add a test for regular forwards

This commit is contained in:
Jesse de Wit
2022-12-19 15:43:50 +01:00
parent 615bdb8bb5
commit fecb4d7fbc
3 changed files with 58 additions and 1 deletions

2
go.mod
View File

@@ -4,7 +4,7 @@ go 1.19
require (
github.com/aws/aws-sdk-go v1.30.20
github.com/breez/lntest v0.0.13
github.com/breez/lntest v0.0.15
github.com/btcsuite/btcd v0.23.3
github.com/btcsuite/btcd/btcec/v2 v2.2.1
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1

View File

@@ -89,4 +89,8 @@ var allTestCases = []*testCase{
name: "testNoBalance",
test: testNoBalance,
},
{
name: "testRegularForward",
test: testRegularForward,
},
}

View File

@@ -0,0 +1,53 @@
package itest
import (
"log"
"time"
"github.com/breez/lntest"
"github.com/stretchr/testify/assert"
)
func testRegularForward(p *testParams) {
alice := lntest.NewClnNode(p.h, p.m, "Alice")
alice.Start()
alice.Fund(10000000)
p.lsp.LightningNode().Fund(10000000)
p.BreezClient().Node().Fund(100000)
log.Print("Opening channel between Alice and the lsp")
channelAL := alice.OpenChannel(p.lsp.LightningNode(), &lntest.OpenChannelOptions{
AmountSat: publicChanAmount,
IsPublic: true,
})
log.Print("Opening channel between lsp and Breez client")
channelLB := p.lsp.LightningNode().OpenChannel(p.BreezClient().Node(), &lntest.OpenChannelOptions{
AmountSat: 200000,
IsPublic: false,
})
log.Print("Waiting for channel between Alice and the lsp to be ready.")
alice.WaitForChannelReady(channelAL)
log.Print("Waiting for channel between LSP and Bob to be ready.")
p.lsp.LightningNode().WaitForChannelReady(channelLB)
p.BreezClient().Node().WaitForChannelReady(channelLB)
// TODO: Fix race waiting for htlc interceptor.
log.Printf("Waiting %v to allow htlc interceptor to activate.", htlcInterceptorDelay)
<-time.After(htlcInterceptorDelay)
log.Printf("Adding bob's invoice")
amountMsat := uint64(2100000)
bobInvoice := p.BreezClient().Node().CreateBolt11Invoice(&lntest.CreateInvoiceOptions{
AmountMsat: amountMsat,
})
log.Printf(bobInvoice.Bolt11)
log.Printf("Alice paying")
payResp := alice.Pay(bobInvoice.Bolt11)
invoiceResult := p.BreezClient().Node().GetInvoice(bobInvoice.PaymentHash)
assert.Equal(p.t, payResp.PaymentPreimage, invoiceResult.PaymentPreimage)
assert.Equal(p.t, amountMsat, invoiceResult.AmountReceivedMsat)
}