add a test to verify tag is persisted

This commit is contained in:
Jesse de Wit
2023-02-13 10:38:51 +01:00
parent 8e2c9bd9ce
commit 14f93d934e
5 changed files with 67 additions and 0 deletions

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -43,6 +43,7 @@ type LspNode interface {
NodeId() []byte
LightningNode() lntest.LightningNode
SupportsChargingFees() bool
PostgresBackend() *PostgresContainer
}
type lspBase struct {

View File

@@ -101,4 +101,8 @@ var allTestCases = []*testCase{
name: "testInvalidCltv",
test: testInvalidCltv,
},
{
name: "registerPaymentWithTag",
test: registerPaymentWithTag,
},
}

55
itest/tag_test.go Normal file
View 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)
}