diff --git a/itest/cln_lspd_node.go b/itest/cln_lspd_node.go index 0221e84..52bec20 100644 --- a/itest/cln_lspd_node.go +++ b/itest/cln_lspd_node.go @@ -217,3 +217,6 @@ func (l *ClnLspNode) LightningNode() lntest.LightningNode { func (l *ClnLspNode) SupportsChargingFees() bool { return false } +func (l *ClnLspNode) PostgresBackend() *PostgresContainer { + return l.lspBase.postgresBackend +} diff --git a/itest/lnd_lspd_node.go b/itest/lnd_lspd_node.go index e9c0d10..0b98931 100644 --- a/itest/lnd_lspd_node.go +++ b/itest/lnd_lspd_node.go @@ -240,3 +240,7 @@ func (l *LndLspNode) NodeId() []byte { func (l *LndLspNode) LightningNode() lntest.LightningNode { return l.lightningNode } + +func (l *LndLspNode) PostgresBackend() *PostgresContainer { + return l.lspBase.postgresBackend +} diff --git a/itest/lspd_node.go b/itest/lspd_node.go index abfab8b..2d22fd0 100644 --- a/itest/lspd_node.go +++ b/itest/lspd_node.go @@ -43,6 +43,7 @@ type LspNode interface { NodeId() []byte LightningNode() lntest.LightningNode SupportsChargingFees() bool + PostgresBackend() *PostgresContainer } type lspBase struct { diff --git a/itest/lspd_test.go b/itest/lspd_test.go index b3220f9..f888f82 100644 --- a/itest/lspd_test.go +++ b/itest/lspd_test.go @@ -101,4 +101,8 @@ var allTestCases = []*testCase{ name: "testInvalidCltv", test: testInvalidCltv, }, + { + name: "registerPaymentWithTag", + test: registerPaymentWithTag, + }, } diff --git a/itest/tag_test.go b/itest/tag_test.go new file mode 100644 index 0000000..c671dc4 --- /dev/null +++ b/itest/tag_test.go @@ -0,0 +1,55 @@ +package itest + +import ( + "log" + + "github.com/breez/lntest" + lspd "github.com/breez/lspd/rpc" + "github.com/jackc/pgx/v4/pgxpool" + "github.com/stretchr/testify/assert" +) + +func registerPaymentWithTag(p *testParams) { + expected := "{\"apiKey\": \"11111111111111\"}" + i := p.BreezClient().Node().CreateBolt11Invoice(&lntest.CreateInvoiceOptions{ + AmountMsat: 25000000, + }) + + log.Printf("Registering payment with lsp") + RegisterPayment(p.lsp, &lspd.PaymentInformation{ + PaymentHash: i.PaymentHash, + PaymentSecret: i.PaymentSecret, + Destination: p.BreezClient().Node().NodeId(), + IncomingAmountMsat: int64(25000000), + OutgoingAmountMsat: int64(21000000), + Tag: expected, + }) + + pgxPool, err := pgxpool.Connect(p.h.Ctx, p.lsp.PostgresBackend().ConnectionString()) + if err != nil { + p.h.T.Fatalf("Failed to connect to postgres backend: %v", err) + } + defer pgxPool.Close() + + rows, err := pgxPool.Query( + p.h.Ctx, + "SELECT tag FROM public.payments WHERE payment_hash=$1", + i.PaymentHash, + ) + if err != nil { + p.h.T.Fatalf("Failed to query tag: %v", err) + } + + defer rows.Close() + if !rows.Next() { + p.h.T.Fatal("No rows found") + } + + var actual string + err = rows.Scan(&actual) + if err != nil { + p.h.T.Fatalf("Failed to get tag from row: %v", err) + } + + assert.Equal(p.h.T, expected, actual) +}