Skip to content

Commit 2043665

Browse files
committed
itest: add tests for timestamp filtering
1 parent fe22080 commit 2043665

File tree

2 files changed

+155
-0
lines changed

2 files changed

+155
-0
lines changed

itest/addrs_test.go

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,157 @@ func testUnknownTlvType(t *harnessTest) {
873873
require.False(t.t, verifyResp.Valid)
874874
}
875875

876+
// testAddrReceives tests the fetching of address events.
877+
func testAddrReceives(t *harnessTest) {
878+
// First, mint an asset so we have something to create addresses for.
879+
rpcAssets := MintAssetsConfirmBatch(
880+
t.t, t.lndHarness.Miner().Client, t.tapd,
881+
[]*mintrpc.MintAssetRequest{
882+
simpleAssets[0],
883+
},
884+
)
885+
asset := rpcAssets[0]
886+
887+
ctxb := context.Background()
888+
ctxt, cancel := context.WithTimeout(ctxb, defaultWaitTimeout)
889+
defer cancel()
890+
891+
// Create a second node that'll be the receiver.
892+
bobLnd := t.lndHarness.NewNodeWithCoins("Bob", nil)
893+
bob := setupTapdHarness(t.t, t, bobLnd, t.universeServer)
894+
defer func() {
895+
require.NoError(t.t, bob.stop(!*noDelete))
896+
}()
897+
898+
// Create an address and send assets to it.
899+
addr, events := NewAddrWithEventStream(
900+
t.t, bob, &taprpc.NewAddrRequest{
901+
AssetId: asset.AssetGenesis.AssetId,
902+
Amt: asset.Amount - 1,
903+
AssetVersion: asset.Version,
904+
},
905+
)
906+
907+
AssertAddrCreated(t.t, bob, asset, addr)
908+
909+
// Record the time before sending.
910+
timeBeforeSend := time.Now()
911+
912+
// Send assets to the address.
913+
sendResp, sendEvents := sendAssetsToAddr(t, t.tapd, addr)
914+
require.NotNil(t.t, sendResp)
915+
916+
// Wait for the event to be detected.
917+
AssertAddrEvent(t.t, bob, addr, 1, statusDetected)
918+
919+
// Mine a block to confirm the transaction.
920+
MineBlocks(t.t, t.lndHarness.Miner().Client, 1, 1)
921+
922+
// Wait for the event to be confirmed.
923+
AssertAddrEvent(t.t, bob, addr, 1, statusConfirmed)
924+
925+
// Record the time after sending.
926+
timeAfterSend := time.Now()
927+
928+
// Wait for the receive to complete.
929+
AssertNonInteractiveRecvComplete(t.t, bob, 1)
930+
AssertSendEventsComplete(t.t, addr.ScriptKey, sendEvents)
931+
AssertReceiveEvents(t.t, addr, events)
932+
933+
// Test 1: Get all events without timestamp filtering.
934+
resp, err := bob.AddrReceives(
935+
ctxt, &taprpc.AddrReceivesRequest{},
936+
)
937+
require.NoError(t.t, err)
938+
require.Len(t.t, resp.Events, 1)
939+
940+
// Test 2: Filter by start timestamp before the send
941+
// (should return events).
942+
resp, err = bob.AddrReceives(
943+
ctxt, &taprpc.AddrReceivesRequest{
944+
StartTimestamp: uint64(timeBeforeSend.Unix()),
945+
},
946+
)
947+
require.NoError(t.t, err)
948+
require.Len(t.t, resp.Events, 1)
949+
950+
// Test 3: Filter by start timestamp exactly at the send time
951+
// (should return the event).
952+
resp, err = bob.AddrReceives(
953+
ctxt, &taprpc.AddrReceivesRequest{
954+
StartTimestamp: uint64(timeBeforeSend.Unix()),
955+
},
956+
)
957+
require.NoError(t.t, err)
958+
require.Len(t.t, resp.Events, 1)
959+
960+
// Test 4: Filter by address and start timestamp.
961+
resp, err = bob.AddrReceives(
962+
ctxt, &taprpc.AddrReceivesRequest{
963+
FilterAddr: addr.Encoded,
964+
StartTimestamp: uint64(timeBeforeSend.Unix()),
965+
},
966+
)
967+
require.NoError(t.t, err)
968+
require.Len(t.t, resp.Events, 1)
969+
require.Equal(
970+
t.t, addr.Encoded, resp.Events[0].Addr.Encoded,
971+
)
972+
973+
// Test 5: Filter by address and start timestamp after send
974+
// (should return no events).
975+
resp, err = bob.AddrReceives(
976+
ctxt, &taprpc.AddrReceivesRequest{
977+
FilterAddr: addr.Encoded,
978+
StartTimestamp: uint64(timeAfterSend.Unix() + 1),
979+
},
980+
)
981+
require.NoError(t.t, err)
982+
require.Len(t.t, resp.Events, 0)
983+
984+
// Test 6: Filter by end timestamp before the send
985+
// (should return no events).
986+
resp, err = bob.AddrReceives(
987+
ctxt, &taprpc.AddrReceivesRequest{
988+
EndTimestamp: uint64(timeBeforeSend.Unix()),
989+
},
990+
)
991+
require.NoError(t.t, err)
992+
require.Len(t.t, resp.Events, 0)
993+
994+
// Test 7: Filter by end timestamp after the send
995+
// (should return the event).
996+
resp, err = bob.AddrReceives(
997+
ctxt, &taprpc.AddrReceivesRequest{
998+
EndTimestamp: uint64(timeAfterSend.Unix() + 1),
999+
},
1000+
)
1001+
require.NoError(t.t, err)
1002+
require.Len(t.t, resp.Events, 1)
1003+
1004+
// Test 8: Filter by both start and end timestamp
1005+
// (should return the event).
1006+
resp, err = bob.AddrReceives(
1007+
ctxt, &taprpc.AddrReceivesRequest{
1008+
StartTimestamp: uint64(timeBeforeSend.Unix()),
1009+
EndTimestamp: uint64(timeAfterSend.Unix() + 1),
1010+
},
1011+
)
1012+
require.NoError(t.t, err)
1013+
require.Len(t.t, resp.Events, 1)
1014+
1015+
// Test 10: Filter by both start and end timestamp with narrow range
1016+
// (should return no events)
1017+
resp, err = bob.AddrReceives(
1018+
ctxt, &taprpc.AddrReceivesRequest{
1019+
StartTimestamp: uint64(timeAfterSend.Unix()),
1020+
EndTimestamp: uint64(timeAfterSend.Unix()),
1021+
},
1022+
)
1023+
require.NoError(t.t, err)
1024+
require.Len(t.t, resp.Events, 0)
1025+
}
1026+
8761027
// sendProof manually exports a proof from the given source node and imports it
8771028
// using the development only ImportProof RPC on the destination node.
8781029
func sendProof(t *harnessTest, src, dst *tapdHarness,

itest/test_list_on_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ var allTestCases = []*testCase{
5353
name: "addresses",
5454
test: testAddresses,
5555
},
56+
{
57+
name: "address receives",
58+
test: testAddrReceives,
59+
},
5660
{
5761
name: "multi address",
5862
test: testMultiAddress,

0 commit comments

Comments
 (0)