Skip to content

Commit 940b6ee

Browse files
committed
itest: refactor itest testReattemptFailedSendUniCourier
Refactor to perform asset minting and node setup before subscribing to the send notification events from the sending node. This change aims to improve test clarity and readability.
1 parent 0312663 commit 940b6ee

File tree

1 file changed

+33
-27
lines changed

1 file changed

+33
-27
lines changed

itest/send_test.go

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -683,14 +683,40 @@ func testReattemptFailedSendUniCourier(t *harnessTest) {
683683
},
684684
)
685685

686-
// Subscribe to receive asset send events from the sending tapd node.
686+
// Use the primary tapd node as the receiver node.
687+
recvTapd := t.tapd
688+
689+
// Use the sending node to mint an asset for sending.
690+
rpcAssets := MintAssetsConfirmBatch(
691+
t.t, t.lndHarness.Miner.Client, sendTapd,
692+
[]*mintrpc.MintAssetRequest{simpleAssets[0]},
693+
)
694+
695+
genInfo := rpcAssets[0].AssetGenesis
696+
697+
// After minting an asset with the sending node, we need to synchronize
698+
// the Universe state to ensure the receiving node is updated and aware
699+
// of the asset.
700+
t.syncUniverseState(sendTapd, recvTapd, len(rpcAssets))
701+
702+
// Create a new address for the receiver node.
703+
recvAddr, err := recvTapd.NewAddr(ctxb, &taprpc.NewAddrRequest{
704+
AssetId: genInfo.AssetId,
705+
Amt: 10,
706+
})
707+
require.NoError(t.t, err)
708+
AssertAddrCreated(t.t, recvTapd, rpcAssets[0], recvAddr)
709+
710+
// No we will ensure that the expected number of backoff wait event
711+
// notifications are emitted from the sending node.
712+
//
713+
// We identify backoff wait events in a goroutine to ensure that we can
714+
// capture event notifications from the send node while the main
715+
// test continues.
716+
//
717+
// Subscribe to proof transfer send events from the sending tapd node.
687718
events := SubscribeSendEvents(t.t, sendTapd)
688719

689-
// Test to ensure that we receive the expected number of backoff wait
690-
// event notifications.
691-
// This test is executed in a goroutine to ensure that we can receive
692-
// the event notification(s) from the tapd node as the rest of the test
693-
// proceeds.
694720
wg.Add(1)
695721
go func() {
696722
defer wg.Done()
@@ -708,7 +734,7 @@ func testReattemptFailedSendUniCourier(t *harnessTest) {
708734
// Expected number of events is one less than the number of
709735
// tries because the first attempt does not count as a backoff
710736
// event.
711-
nodeBackoffCfg := t.tapd.clientCfg.HashMailCourier.BackoffCfg
737+
nodeBackoffCfg := sendTapd.clientCfg.HashMailCourier.BackoffCfg
712738
expectedEventCount := nodeBackoffCfg.NumTries - 1
713739

714740
// Context timeout scales with expected number of events.
@@ -725,26 +751,6 @@ func testReattemptFailedSendUniCourier(t *harnessTest) {
725751
)
726752
}()
727753

728-
// Mint an asset for sending.
729-
rpcAssets := MintAssetsConfirmBatch(
730-
t.t, t.lndHarness.Miner.Client, sendTapd,
731-
[]*mintrpc.MintAssetRequest{simpleAssets[0]},
732-
)
733-
734-
genInfo := rpcAssets[0].AssetGenesis
735-
736-
// Synchronize the Universe state of the second node, with the main
737-
// node.
738-
t.syncUniverseState(sendTapd, t.tapd, len(rpcAssets))
739-
740-
// Create a new address for the receiver node.
741-
recvAddr, err := t.tapd.NewAddr(ctxb, &taprpc.NewAddrRequest{
742-
AssetId: genInfo.AssetId,
743-
Amt: 10,
744-
})
745-
require.NoError(t.t, err)
746-
AssertAddrCreated(t.t, t.tapd, rpcAssets[0], recvAddr)
747-
748754
// Simulate a failed attempt at sending the asset proof by stopping
749755
// the proof courier service.
750756
require.NoError(t.t, t.proofCourier.Stop())

0 commit comments

Comments
 (0)