Skip to content

Commit

Permalink
chore: transactions service tests (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Jul 18, 2024
1 parent 03e23a0 commit 40df3b6
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions transactions/transactions_service_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,50 @@
package transactions

import (
"context"
"testing"

"github.com/getAlby/hub/constants"
"github.com/getAlby/hub/tests"
"github.com/stretchr/testify/assert"
)

// TODO: implement tests for transaction service
func TestOne(t *testing.T) {
assert.True(t, false)
func TestMakeInvoice_NoApp(t *testing.T) {
ctx := context.TODO()

defer tests.RemoveTestService()
svc, err := tests.CreateTestService()
assert.NoError(t, err)

transactionsService := NewTransactionsService(svc.DB)
transaction, err := transactionsService.MakeInvoice(ctx, 1234, "Hello world", "", 0, svc.LNClient, nil, nil)

assert.NoError(t, err)
assert.Equal(t, uint64(tests.MockLNClientTransaction.Amount), transaction.AmountMsat)
assert.Equal(t, constants.TRANSACTION_STATE_PENDING, transaction.State)
assert.Equal(t, tests.MockLNClientTransaction.Preimage, *transaction.Preimage)
}

func TestSendPaymentSync_NoApp(t *testing.T) {
ctx := context.TODO()

defer tests.RemoveTestService()
svc, err := tests.CreateTestService()
assert.NoError(t, err)

transactionsService := NewTransactionsService(svc.DB)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockLNClientTransaction.Invoice, svc.LNClient, nil, nil)

assert.NoError(t, err)
assert.Equal(t, uint64(123000), transaction.AmountMsat)
assert.Equal(t, constants.TRANSACTION_STATE_SETTLED, transaction.State)
assert.Equal(t, "123preimage", *transaction.Preimage)
}

// TODO: apps & events
// TODO: isolated apps & events
// TODO: self payments

// TODO: keysend
// TODO: lookup invoice
// TODO: list transactions

0 comments on commit 40df3b6

Please sign in to comment.