From bd9cebda5b49911206ac65fbb5566fc06df278b2 Mon Sep 17 00:00:00 2001 From: Yaroslav Vorobiov Date: Tue, 11 Feb 2020 15:11:14 +0200 Subject: [PATCH] satellite/payments: fix transaction list pagination Change-Id: I533f637e5cb12b47d7f7248f8bf7de93bd8be000 --- .../stripecoinpayments/transactions_test.go | 31 ++++++++++++++++--- satellite/satellitedb/coinpaymentstxs.go | 4 +-- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/satellite/payments/stripecoinpayments/transactions_test.go b/satellite/payments/stripecoinpayments/transactions_test.go index 097925e01..bb8a62d9a 100644 --- a/satellite/payments/stripecoinpayments/transactions_test.go +++ b/satellite/payments/stripecoinpayments/transactions_test.go @@ -114,7 +114,8 @@ func TestTransactionsDBList(t *testing.T) { defer ctx.Cleanup() const ( - transactionCount = 10 + limit = 5 + transactionCount = limit * 4 ) // create transactions @@ -154,10 +155,20 @@ func TestTransactionsDBList(t *testing.T) { require.NoError(t, err) } - page, err := db.StripeCoinPayments().Transactions().ListPending(ctx, 0, transactionCount, time.Now()) + page, err := db.StripeCoinPayments().Transactions().ListPending(ctx, 0, limit, time.Now()) require.NoError(t, err) + + pendingTXs := page.Transactions + + for page.Next { + page, err = db.StripeCoinPayments().Transactions().ListPending(ctx, page.NextOffset, limit, time.Now()) + require.NoError(t, err) + + pendingTXs = append(pendingTXs, page.Transactions...) + } + require.False(t, page.Next) - require.Equal(t, transactionCount, len(page.Transactions)) + require.Equal(t, transactionCount, len(pendingTXs)) for _, act := range page.Transactions { for _, exp := range txs { @@ -196,10 +207,20 @@ func TestTransactionsDBList(t *testing.T) { err := db.StripeCoinPayments().Transactions().Update(ctx, updates, applies) require.NoError(t, err) - page, err := db.StripeCoinPayments().Transactions().ListUnapplied(ctx, 0, transactionCount, time.Now()) + page, err := db.StripeCoinPayments().Transactions().ListUnapplied(ctx, 0, limit, time.Now()) require.NoError(t, err) + + unappliedTXs := page.Transactions + + for page.Next { + page, err = db.StripeCoinPayments().Transactions().ListUnapplied(ctx, page.NextOffset, limit, time.Now()) + require.NoError(t, err) + + unappliedTXs = append(unappliedTXs, page.Transactions...) + } + require.False(t, page.Next) - require.Equal(t, transactionCount, len(page.Transactions)) + require.Equal(t, transactionCount, len(unappliedTXs)) for _, act := range page.Transactions { for _, exp := range updatedTxs { diff --git a/satellite/satellitedb/coinpaymentstxs.go b/satellite/satellitedb/coinpaymentstxs.go index 56457996f..aae264368 100644 --- a/satellite/satellitedb/coinpaymentstxs.go +++ b/satellite/satellitedb/coinpaymentstxs.go @@ -260,7 +260,7 @@ func (db *coinPaymentsTransactions) ListPending(ctx context.Context, offset int6 if len(page.Transactions) == limit+1 { page.Next = true - page.NextOffset = offset + int64(limit) + 1 + page.NextOffset = offset + int64(limit) page.Transactions = page.Transactions[:len(page.Transactions)-1] } @@ -343,7 +343,7 @@ func (db *coinPaymentsTransactions) ListUnapplied(ctx context.Context, offset in if len(page.Transactions) == limit+1 { page.Next = true - page.NextOffset = offset + int64(limit) + 1 + page.NextOffset = offset + int64(limit) page.Transactions = page.Transactions[:len(page.Transactions)-1] }