Skip to content

Commit

Permalink
fix: list transactions offset
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Aug 20, 2024
1 parent d7a40e8 commit 2dcba00
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
26 changes: 23 additions & 3 deletions transactions/list_transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion transactions/transactions_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2dcba00

Please sign in to comment.