diff --git a/go.mod b/go.mod index 33a2416..bb38b44 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/itest/lspd_test.go b/itest/lspd_test.go index b7c2ca3..6360539 100644 --- a/itest/lspd_test.go +++ b/itest/lspd_test.go @@ -89,4 +89,8 @@ var allTestCases = []*testCase{ name: "testNoBalance", test: testNoBalance, }, + { + name: "testRegularForward", + test: testRegularForward, + }, } diff --git a/itest/regular_forward_test.go b/itest/regular_forward_test.go new file mode 100644 index 0000000..61c22a7 --- /dev/null +++ b/itest/regular_forward_test.go @@ -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) +}