From 2dcba00d6cde522f02ca45a732392c1ba26a5b68 Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Tue, 20 Aug 2024 11:25:45 +0700 Subject: [PATCH] fix: list transactions offset --- transactions/list_transactions_test.go | 26 +++++++++++++++++++++++--- transactions/transactions_service.go | 2 +- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/transactions/list_transactions_test.go b/transactions/list_transactions_test.go index 3124d4b6..29bc127d 100644 --- a/transactions/list_transactions_test.go +++ b/transactions/list_transactions_test.go @@ -131,7 +131,7 @@ func TestListTransactions_Offset(t *testing.T) { Preimage: &mockPreimage, AmountMsat: 123000, Description: "first", - CreatedAt: time.Now().Add(1 * time.Minute), + CreatedAt: time.Now().Add(3 * time.Minute), }) svc.DB.Create(&db.Transaction{ State: constants.TRANSACTION_STATE_SETTLED, @@ -141,14 +141,34 @@ func TestListTransactions_Offset(t *testing.T) { Preimage: &mockPreimage, AmountMsat: 123000, Description: "second", + CreatedAt: time.Now().Add(2 * time.Minute), + }) + svc.DB.Create(&db.Transaction{ + State: constants.TRANSACTION_STATE_SETTLED, + Type: constants.TRANSACTION_TYPE_INCOMING, + PaymentRequest: tests.MockLNClientTransaction.Invoice, + PaymentHash: tests.MockLNClientTransaction.PaymentHash, + Preimage: &mockPreimage, + AmountMsat: 123000, + Description: "third", + CreatedAt: time.Now().Add(1 * time.Minute), + }) + svc.DB.Create(&db.Transaction{ + State: constants.TRANSACTION_STATE_SETTLED, + Type: constants.TRANSACTION_TYPE_INCOMING, + PaymentRequest: tests.MockLNClientTransaction.Invoice, + PaymentHash: tests.MockLNClientTransaction.PaymentHash, + Preimage: &mockPreimage, + AmountMsat: 123000, + Description: "fourth", }) transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher) - incomingTransactions, err := transactionsService.ListTransactions(ctx, 0, 0, 1, 1, false, nil, svc.LNClient, nil) + incomingTransactions, err := transactionsService.ListTransactions(ctx, 0, 0, 1, 2, false, nil, svc.LNClient, nil) assert.NoError(t, err) assert.Equal(t, 1, len(incomingTransactions)) - assert.Equal(t, "second", incomingTransactions[0].Description) + assert.Equal(t, "third", incomingTransactions[0].Description) } func TestListTransactions_FromUntil(t *testing.T) { diff --git a/transactions/transactions_service.go b/transactions/transactions_service.go index b16eb2f4..aa52e984 100644 --- a/transactions/transactions_service.go +++ b/transactions/transactions_service.go @@ -467,7 +467,7 @@ func (svc *transactionsService) ListTransactions(ctx context.Context, from, unti tx = tx.Limit(int(limit)) } if offset > 0 { - tx = tx.Offset(int(limit)) + tx = tx.Offset(int(offset)) } if appId != nil {