mirror of
https://github.com/aljazceru/lspd.git
synced 2026-01-10 01:24:27 +01:00
add a test to verify tag is persisted
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ type LspNode interface {
|
||||
NodeId() []byte
|
||||
LightningNode() lntest.LightningNode
|
||||
SupportsChargingFees() bool
|
||||
PostgresBackend() *PostgresContainer
|
||||
}
|
||||
|
||||
type lspBase struct {
|
||||
|
||||
@@ -101,4 +101,8 @@ var allTestCases = []*testCase{
|
||||
name: "testInvalidCltv",
|
||||
test: testInvalidCltv,
|
||||
},
|
||||
{
|
||||
name: "registerPaymentWithTag",
|
||||
test: registerPaymentWithTag,
|
||||
},
|
||||
}
|
||||
|
||||
55
itest/tag_test.go
Normal file
55
itest/tag_test.go
Normal file
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user