paymentsdb: make QueryPayments test db agnostic
We make the QueryPayments test db agnostic and also keep a small test for querying the duplicate payments case in the kv world.
This commit is contained in:
2 files changed
+502
-188
No files matched your search
+27
-188
@@ -690,17 +690,19 @@ func putDuplicatePayment(t *testing.T, duplicateBucket kvdb.RwBucket,
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
// TestQueryPayments tests retrieval of payments with forwards and reversed
|
||||
// queries.
|
||||
//
|
||||
// TODO(ziggie): Make this test db agnostic.
|
||||
func TestQueryPayments(t *testing.T) {
|
||||
// Define table driven test for QueryPayments.
|
||||
// TestKVStoreQueryPaymentsDuplicates tests the KV store's legacy duplicate
|
||||
// payment handling. This tests the specific case where duplicate payments
|
||||
// are stored in a nested bucket within the parent payment bucket.
|
||||
func TestKVStoreQueryPaymentsDuplicates(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Test payments have sequence indices [1, 3, 4, 5, 6, 7].
|
||||
// Note that the payment with index 7 has the same payment hash as 6,
|
||||
// and is stored in a nested bucket within payment 6 rather than being
|
||||
// its own entry in the payments bucket. We do this to test retrieval
|
||||
// of legacy payments.
|
||||
// its own entry in the payments bucket. This tests retrieval of legacy
|
||||
// duplicate payments which is KV-store specific.
|
||||
// These test cases focus on validating that duplicate payments (seq 7,
|
||||
// nested under payment 6) are correctly returned in queries.
|
||||
tests := []struct {
|
||||
name string
|
||||
query Query
|
||||
@@ -712,31 +714,20 @@ func TestQueryPayments(t *testing.T) {
|
||||
expectedSeqNrs []uint64
|
||||
}{
|
||||
{
|
||||
name: "IndexOffset at the end of the payments range",
|
||||
name: "query includes duplicate payment in forward " +
|
||||
"order",
|
||||
query: Query{
|
||||
IndexOffset: 7,
|
||||
MaxPayments: 7,
|
||||
IndexOffset: 5,
|
||||
MaxPayments: 3,
|
||||
Reversed: false,
|
||||
IncludeIncomplete: true,
|
||||
},
|
||||
firstIndex: 0,
|
||||
lastIndex: 0,
|
||||
expectedSeqNrs: nil,
|
||||
firstIndex: 6,
|
||||
lastIndex: 7,
|
||||
expectedSeqNrs: []uint64{6, 7},
|
||||
},
|
||||
{
|
||||
name: "query in forwards order, start at beginning",
|
||||
query: Query{
|
||||
IndexOffset: 0,
|
||||
MaxPayments: 2,
|
||||
Reversed: false,
|
||||
IncludeIncomplete: true,
|
||||
},
|
||||
firstIndex: 1,
|
||||
lastIndex: 3,
|
||||
expectedSeqNrs: []uint64{1, 3},
|
||||
},
|
||||
{
|
||||
name: "query in forwards order, start at end, overflow",
|
||||
name: "query duplicate payment at end",
|
||||
query: Query{
|
||||
IndexOffset: 6,
|
||||
MaxPayments: 2,
|
||||
@@ -748,93 +739,31 @@ func TestQueryPayments(t *testing.T) {
|
||||
expectedSeqNrs: []uint64{7},
|
||||
},
|
||||
{
|
||||
name: "start at offset index outside of payments",
|
||||
name: "query includes duplicate in reverse order",
|
||||
query: Query{
|
||||
IndexOffset: 20,
|
||||
IndexOffset: 0,
|
||||
MaxPayments: 2,
|
||||
Reversed: false,
|
||||
Reversed: true,
|
||||
IncludeIncomplete: true,
|
||||
},
|
||||
firstIndex: 0,
|
||||
lastIndex: 0,
|
||||
expectedSeqNrs: nil,
|
||||
firstIndex: 6,
|
||||
lastIndex: 7,
|
||||
expectedSeqNrs: []uint64{6, 7},
|
||||
},
|
||||
{
|
||||
name: "overflow in forwards order",
|
||||
name: "query all payments includes duplicate",
|
||||
query: Query{
|
||||
IndexOffset: 4,
|
||||
IndexOffset: 0,
|
||||
MaxPayments: math.MaxUint64,
|
||||
Reversed: false,
|
||||
IncludeIncomplete: true,
|
||||
},
|
||||
firstIndex: 5,
|
||||
lastIndex: 7,
|
||||
expectedSeqNrs: []uint64{5, 6, 7},
|
||||
},
|
||||
{
|
||||
name: "start at offset index outside of payments, " +
|
||||
"reversed order",
|
||||
query: Query{
|
||||
IndexOffset: 9,
|
||||
MaxPayments: 2,
|
||||
Reversed: true,
|
||||
IncludeIncomplete: true,
|
||||
},
|
||||
firstIndex: 6,
|
||||
lastIndex: 7,
|
||||
expectedSeqNrs: []uint64{6, 7},
|
||||
},
|
||||
{
|
||||
name: "query in reverse order, start at end",
|
||||
query: Query{
|
||||
IndexOffset: 0,
|
||||
MaxPayments: 2,
|
||||
Reversed: true,
|
||||
IncludeIncomplete: true,
|
||||
},
|
||||
firstIndex: 6,
|
||||
lastIndex: 7,
|
||||
expectedSeqNrs: []uint64{6, 7},
|
||||
},
|
||||
{
|
||||
name: "query in reverse order, starting in middle",
|
||||
query: Query{
|
||||
IndexOffset: 4,
|
||||
MaxPayments: 2,
|
||||
Reversed: true,
|
||||
IncludeIncomplete: true,
|
||||
},
|
||||
firstIndex: 1,
|
||||
lastIndex: 3,
|
||||
expectedSeqNrs: []uint64{1, 3},
|
||||
},
|
||||
{
|
||||
name: "query in reverse order, starting in middle, " +
|
||||
"with underflow",
|
||||
query: Query{
|
||||
IndexOffset: 4,
|
||||
MaxPayments: 5,
|
||||
Reversed: true,
|
||||
IncludeIncomplete: true,
|
||||
},
|
||||
firstIndex: 1,
|
||||
lastIndex: 3,
|
||||
expectedSeqNrs: []uint64{1, 3},
|
||||
},
|
||||
{
|
||||
name: "all payments in reverse, order maintained",
|
||||
query: Query{
|
||||
IndexOffset: 0,
|
||||
MaxPayments: 7,
|
||||
Reversed: true,
|
||||
IncludeIncomplete: true,
|
||||
},
|
||||
firstIndex: 1,
|
||||
lastIndex: 7,
|
||||
expectedSeqNrs: []uint64{1, 3, 4, 5, 6, 7},
|
||||
},
|
||||
{
|
||||
name: "exclude incomplete payments",
|
||||
name: "exclude incomplete includes duplicate",
|
||||
query: Query{
|
||||
IndexOffset: 0,
|
||||
MaxPayments: 7,
|
||||
@@ -845,96 +774,6 @@ func TestQueryPayments(t *testing.T) {
|
||||
lastIndex: 7,
|
||||
expectedSeqNrs: []uint64{7},
|
||||
},
|
||||
{
|
||||
name: "query payments at index gap",
|
||||
query: Query{
|
||||
IndexOffset: 1,
|
||||
MaxPayments: 7,
|
||||
Reversed: false,
|
||||
IncludeIncomplete: true,
|
||||
},
|
||||
firstIndex: 3,
|
||||
lastIndex: 7,
|
||||
expectedSeqNrs: []uint64{3, 4, 5, 6, 7},
|
||||
},
|
||||
{
|
||||
name: "query payments reverse before index gap",
|
||||
query: Query{
|
||||
IndexOffset: 3,
|
||||
MaxPayments: 7,
|
||||
Reversed: true,
|
||||
IncludeIncomplete: true,
|
||||
},
|
||||
firstIndex: 1,
|
||||
lastIndex: 1,
|
||||
expectedSeqNrs: []uint64{1},
|
||||
},
|
||||
{
|
||||
name: "query payments reverse on index gap",
|
||||
query: Query{
|
||||
IndexOffset: 2,
|
||||
MaxPayments: 7,
|
||||
Reversed: true,
|
||||
IncludeIncomplete: true,
|
||||
},
|
||||
firstIndex: 1,
|
||||
lastIndex: 1,
|
||||
expectedSeqNrs: []uint64{1},
|
||||
},
|
||||
{
|
||||
name: "query payments forward on index gap",
|
||||
query: Query{
|
||||
IndexOffset: 2,
|
||||
MaxPayments: 2,
|
||||
Reversed: false,
|
||||
IncludeIncomplete: true,
|
||||
},
|
||||
firstIndex: 3,
|
||||
lastIndex: 4,
|
||||
expectedSeqNrs: []uint64{3, 4},
|
||||
},
|
||||
{
|
||||
name: "query in forwards order, with start creation " +
|
||||
"time",
|
||||
query: Query{
|
||||
IndexOffset: 0,
|
||||
MaxPayments: 2,
|
||||
Reversed: false,
|
||||
IncludeIncomplete: true,
|
||||
CreationDateStart: 5,
|
||||
},
|
||||
firstIndex: 5,
|
||||
lastIndex: 6,
|
||||
expectedSeqNrs: []uint64{5, 6},
|
||||
},
|
||||
{
|
||||
name: "query in forwards order, with start creation " +
|
||||
"time at end, overflow",
|
||||
query: Query{
|
||||
IndexOffset: 0,
|
||||
MaxPayments: 2,
|
||||
Reversed: false,
|
||||
IncludeIncomplete: true,
|
||||
CreationDateStart: 7,
|
||||
},
|
||||
firstIndex: 7,
|
||||
lastIndex: 7,
|
||||
expectedSeqNrs: []uint64{7},
|
||||
},
|
||||
{
|
||||
name: "query with start and end creation time",
|
||||
query: Query{
|
||||
IndexOffset: 9,
|
||||
MaxPayments: math.MaxUint64,
|
||||
Reversed: true,
|
||||
IncludeIncomplete: true,
|
||||
CreationDateStart: 3,
|
||||
CreationDateEnd: 5,
|
||||
},
|
||||
firstIndex: 3,
|
||||
lastIndex: 5,
|
||||
expectedSeqNrs: []uint64{3, 4, 5},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
Reference in new issue
Block a user