@@ -807,10 +807,7 @@ func testReattemptFailedSendUniCourier(t *harnessTest) {
807807// receiving an asset proof will be reattempted by the receiving tapd node. This
808808// test targets the universe proof courier.
809809func testReattemptFailedReceiveUniCourier (t * harnessTest ) {
810- var (
811- ctxb = context .Background ()
812- wg sync.WaitGroup
813- )
810+ ctxb := context .Background ()
814811
815812 // This tapd node will send the asset to the receiving tapd node.
816813 // It will also transfer proof the related transfer proofs to the
@@ -892,56 +889,47 @@ func testReattemptFailedReceiveUniCourier(t *harnessTest) {
892889
893890 // Test to ensure that we receive the minimum expected number of backoff
894891 // wait event notifications.
895- //
896- // This test is executed in a goroutine to ensure that we can receive
897- // the event notification(s) from the tapd node as soon as the proof
898- // courier service is restarted.
899- wg .Add (1 )
900- go func () {
901- defer wg .Done ()
902-
903- // Define a target event selector to match the backoff wait
904- // event. This function selects for a specific event type.
905- targetEventSelector := func (event * taprpc.ReceiveAssetEvent ) bool {
906- switch eventTyped := event .Event .(type ) {
907- case * taprpc.ReceiveAssetEvent_ProofTransferBackoffWaitEvent :
908- ev := eventTyped .ProofTransferBackoffWaitEvent
909-
910- // We are attempting to identify receive
911- // transfer types. Skip the event if it is not
912- // a receiving transfer type.
913- if ev .TransferType != taprpc .ProofTransferType_PROOF_TRANSFER_TYPE_RECEIVE {
914- return false
915- }
892+ t .Logf ("Waiting for the receiving tapd node to complete backoff " +
893+ "proof retrieval attempts" )
916894
917- t .Logf ("Found event ntfs: %v" , ev )
918- return true
895+ // Define a target event selector to match the backoff wait event. This
896+ // function selects for a specific event type.
897+ targetEventSelector := func (event * taprpc.ReceiveAssetEvent ) bool {
898+ switch eventTyped := event .Event .(type ) {
899+ case * taprpc.ReceiveAssetEvent_ProofTransferBackoffWaitEvent :
900+ ev := eventTyped .ProofTransferBackoffWaitEvent
901+
902+ // We are attempting to identify receive transfer types.
903+ // Skip the event if it is not a receiving transfer
904+ // type.
905+ if ev .TransferType != taprpc .ProofTransferType_PROOF_TRANSFER_TYPE_RECEIVE {
906+ return false
919907 }
920908
921- return false
909+ t .Logf ("Found event ntfs: %v" , ev )
910+ return true
922911 }
923912
924- // Expected minimum number of events to receive.
925- expectedEventCount := 3
926-
927- // Context timeout scales with expected number of events.
928- timeout := time .Duration (expectedEventCount ) *
929- defaultProofTransferReceiverAckTimeout
930- // Add overhead buffer to context timeout.
931- timeout += 5 * time .Second
932- ctx , cancel := context .WithTimeout (ctxb , timeout )
933- defer cancel ()
913+ return false
914+ }
934915
935- assertAssetRecvNtfsEvent (
936- t , ctx , eventNtfns , targetEventSelector ,
937- expectedEventCount ,
938- )
939- }()
916+ // Expected minimum number of events to receive.
917+ expectedEventCount := 3
918+
919+ // Context timeout scales with expected number of events.
920+ timeout := time .Duration (expectedEventCount ) *
921+ defaultProofTransferReceiverAckTimeout
922+ // Add overhead buffer to context timeout.
923+ timeout += 5 * time .Second
924+ ctx , cancel := context .WithTimeout (ctxb , timeout )
925+ defer cancel ()
926+
927+ // Assert that the receiver tapd node has accomplished our minimum
928+ // expected number of backoff procedure receive attempts.
929+ assertAssetRecvNtfsEvent (
930+ t , ctx , eventNtfns , targetEventSelector , expectedEventCount ,
931+ )
940932
941- // Wait for the receiver node's backoff attempts to complete.
942- t .Logf ("Waiting for the receiving tapd node to complete backoff " +
943- "proof retrieval attempts" )
944- wg .Wait ()
945933 t .Logf ("Finished waiting for the receiving tapd node to complete " +
946934 "backoff procedure" )
947935
@@ -956,6 +944,13 @@ func testReattemptFailedReceiveUniCourier(t *harnessTest) {
956944 // proof(s).
957945 t .Logf ("Attempting to confirm asset received by receiver node" )
958946 AssertNonInteractiveRecvComplete (t .t , receiveTapd , 1 )
947+
948+ // Confirm that the sender tapd node eventually receives the asset
949+ // transfer and publishes an asset recv complete event.
950+ t .Logf ("Check for asset recv complete event from receiver tapd node" )
951+ assertAssetRecvCompleteEvent (
952+ t , ctxb , 5 * time .Second , recvAddr .Encoded , eventNtfns ,
953+ )
959954}
960955
961956// testOfflineReceiverEventuallyReceives tests that a receiver node will
@@ -1169,6 +1164,29 @@ func assertAssetRecvNtfsEvent(t *harnessTest, ctx context.Context,
11691164 expectedCount , countFound )
11701165}
11711166
1167+ // assertAssetRecvNtfsEvent asserts that the given asset receive complete event
1168+ // notification was received. This function will block until the event is
1169+ // received or the event stream is closed.
1170+ func assertAssetRecvCompleteEvent (t * harnessTest , ctxb context.Context ,
1171+ timeout time.Duration , encodedAddr string ,
1172+ eventNtfns taprpc.TaprootAssets_SubscribeReceiveAssetEventNtfnsClient ) {
1173+
1174+ ctx , cancel := context .WithTimeout (ctxb , timeout )
1175+ defer cancel ()
1176+
1177+ eventSelector := func (event * taprpc.ReceiveAssetEvent ) bool {
1178+ switch eventTyped := event .Event .(type ) {
1179+ case * taprpc.ReceiveAssetEvent_AssetReceiveCompleteEvent :
1180+ ev := eventTyped .AssetReceiveCompleteEvent
1181+ return encodedAddr == ev .Address .Encoded
1182+ default :
1183+ return false
1184+ }
1185+ }
1186+
1187+ assertAssetRecvNtfsEvent (t , ctx , eventNtfns , eventSelector , 1 )
1188+ }
1189+
11721190// testMultiInputSendNonInteractiveSingleID tests that we can properly
11731191// non-interactively send a single asset from multiple inputs.
11741192//
0 commit comments