@@ -701,6 +701,164 @@ func runMultiSendTest(ctxt context.Context, t *harnessTest, alice,
701701 }
702702}
703703
704+ // testAddrReceives tests the fetching of address events.
705+ func testAddrReceives (t * harnessTest ) {
706+ // First, mint a few assets, so we have some to create addresses for.
707+ rpcAssets := MintAssetsConfirmBatch (
708+ t .t , t .lndHarness .Miner ().Client , t .tapd ,
709+ []* mintrpc.MintAssetRequest {
710+ simpleAssets [0 ], issuableAssets [0 ],
711+ },
712+ )
713+
714+ ctxb := context .Background ()
715+ ctxt , cancel := context .WithTimeout (ctxb , defaultWaitTimeout )
716+ defer cancel ()
717+
718+ // We'll make a second node now that'll be the receiver of all the
719+ // assets made above.
720+ bobLnd := t .lndHarness .NewNodeWithCoins ("Bob" , nil )
721+ secondTapd := setupTapdHarness (t .t , t , bobLnd , t .universeServer )
722+ defer func () {
723+ require .NoError (t .t , secondTapd .stop (! * noDelete ))
724+ }()
725+
726+ const numAddresses = 6
727+ for i := range numAddresses {
728+ // Use different assets for variety
729+ assetIdx := i % len (rpcAssets )
730+ asset := rpcAssets [assetIdx ]
731+
732+ addr , events := NewAddrWithEventStream (
733+ t .t , secondTapd , & taprpc.NewAddrRequest {
734+ AssetId : asset .AssetGenesis .AssetId ,
735+ Amt : uint64 (10 ),
736+ AssetVersion : asset .Version ,
737+ },
738+ )
739+
740+ AssertAddrCreated (t .t , secondTapd , asset , addr )
741+
742+ // Send assets to the address
743+ _ , sendEvents := sendAssetsToAddr (t , t .tapd , addr )
744+
745+ AssertAddrEvent (t .t , secondTapd , addr , 1 , statusDetected )
746+
747+ // Mine a block to make sure the events are marked as confirmed.
748+ MineBlocks (t .t , t .lndHarness .Miner ().Client , 1 , 1 )
749+
750+ // Eventually the event should be marked as confirmed.
751+ AssertAddrEvent (t .t , secondTapd , addr , 1 , statusConfirmed )
752+
753+ // Make sure we have imported and finalized all proofs.
754+ AssertNonInteractiveRecvComplete (t .t , secondTapd , i + 1 )
755+ AssertSendEventsComplete (t .t , addr .ScriptKey , sendEvents )
756+
757+ // Make sure the receiver has received all events in order for
758+ // the address.
759+ AssertReceiveEvents (t .t , addr , events )
760+ }
761+
762+ // Test 1: limit
763+ resp , err := secondTapd .AddrReceives (ctxt , & taprpc.AddrReceivesRequest {
764+ Limit : 3 ,
765+ })
766+ require .NoError (t .t , err )
767+ require .Len (t .t , resp .Events , 3 )
768+
769+ // Test 2: offset
770+ resp , err = secondTapd .AddrReceives (ctxt , & taprpc.AddrReceivesRequest {
771+ Offset : 2 ,
772+ Limit : 3 ,
773+ })
774+ require .NoError (t .t , err )
775+ require .Len (t .t , resp .Events , 3 )
776+
777+ // Test 3: Ascending direction (default)
778+ resp , err = secondTapd .AddrReceives (ctxt , & taprpc.AddrReceivesRequest {
779+ Limit : 5 ,
780+ Direction : 0 , // ascending
781+ })
782+ require .NoError (t .t , err )
783+ require .Len (t .t , resp .Events , 5 )
784+
785+ // Verify ascending order by checking creation times
786+ for i := 1 ; i < len (resp .Events ); i ++ {
787+ require .LessOrEqual (t .t ,
788+ resp .Events [i - 1 ].CreationTimeUnixSeconds ,
789+ resp .Events [i ].CreationTimeUnixSeconds ,
790+ )
791+ }
792+
793+ // Test 4: Descending direction
794+ resp , err = secondTapd .AddrReceives (ctxt , & taprpc.AddrReceivesRequest {
795+ Limit : 5 ,
796+ Direction : 1 , // descending
797+ })
798+ require .NoError (t .t , err )
799+ require .Len (t .t , resp .Events , 5 )
800+
801+ // Verify descending order by checking creation times
802+ for i := 1 ; i < len (resp .Events ); i ++ {
803+ require .GreaterOrEqual (t .t ,
804+ resp .Events [i - 1 ].CreationTimeUnixSeconds ,
805+ resp .Events [i ].CreationTimeUnixSeconds ,
806+ )
807+ }
808+
809+ // Test 5: Offset out of bounds
810+ resp , err = secondTapd .AddrReceives (ctxt ,
811+ & taprpc.AddrReceivesRequest {
812+ Offset : 100 ,
813+ Limit : 10 ,
814+ },
815+ )
816+ require .NoError (t .t , err )
817+ require .Len (t .t , resp .Events , 0 )
818+
819+ // Test 6: Test pagination through all results
820+ var allPaginatedEvents []* taprpc.AddrEvent
821+ offset := int32 (0 )
822+ limit := int32 (3 )
823+
824+ for {
825+ resp , err := secondTapd .AddrReceives (ctxt ,
826+ & taprpc.AddrReceivesRequest {
827+ Offset : offset ,
828+ Limit : limit ,
829+ },
830+ )
831+ require .NoError (t .t , err )
832+
833+ if len (resp .Events ) == 0 {
834+ break
835+ }
836+
837+ allPaginatedEvents = append (allPaginatedEvents , resp .Events ... )
838+ offset += limit
839+ }
840+
841+ // Should have collected all events
842+ require .Len (t .t , allPaginatedEvents , numAddresses )
843+
844+ // Test 7: Test negative offset and limit error
845+ _ , err = secondTapd .AddrReceives (ctxt ,
846+ & taprpc.AddrReceivesRequest {
847+ Offset : - 5 ,
848+ },
849+ )
850+ require .Error (t .t , err )
851+ require .Contains (t .t , err .Error (), "offset must be non-negative" )
852+
853+ _ , err = secondTapd .AddrReceives (ctxt ,
854+ & taprpc.AddrReceivesRequest {
855+ Limit : - 5 ,
856+ },
857+ )
858+ require .Error (t .t , err )
859+ require .Contains (t .t , err .Error (), "limit must be non-negative" )
860+ }
861+
704862// testUnknownTlvType tests that we can create an address with an unknown TLV
705863// type and that assets can be sent to it. We then modify a proof similarly and
706864// make sure it can be imported by a node correctly.
0 commit comments