package itest import ( "log" "github.com/breez/lntest" lspd "github.com/breez/lspd/rpc" "github.com/stretchr/testify/assert" ) func testOpenZeroConfChannelOnReceive(p *testParams) { alice := lntest.NewCoreLightningNode(p.h, p.m, "Alice") alice.Fund(10000000) p.lsp.LightningNode().Fund(10000000) log.Print("Opening channel between Alice and the lsp") channel := alice.OpenChannel(p.lsp.LightningNode(), &lntest.OpenChannelOptions{ AmountSat: 1000000, }) alice.WaitForChannelReady(channel) log.Printf("Adding bob's invoices") outerAmountMsat := uint64(2100000) innerAmountMsat := uint64(2100000) description := "Please pay me" innerInvoice, outerInvoice := p.BreezClient().GenerateInvoices(generateInvoicesRequest{ innerAmountMsat: innerAmountMsat, outerAmountMsat: outerAmountMsat, description: description, lsp: p.lsp, }) log.Print("Connecting bob to lspd") p.BreezClient().lightningNode.ConnectPeer(p.lsp.LightningNode()) // NOTE: We pretend to be paying fees to the lsp, but actually we won't. log.Printf("Registering payment with lsp") pretendAmount := outerAmountMsat - 2000000 RegisterPayment(p.lsp, &lspd.PaymentInformation{ PaymentHash: innerInvoice.paymentHash, PaymentSecret: innerInvoice.paymentSecret, Destination: p.BreezClient().lightningNode.NodeId(), IncomingAmountMsat: int64(outerAmountMsat), OutgoingAmountMsat: int64(pretendAmount), }) log.Printf("Alice paying") payResp := alice.Pay(outerInvoice.bolt11) bobInvoice := p.BreezClient().lightningNode.GetInvoice(payResp.PaymentHash) assert.Equal(p.t, payResp.PaymentPreimage, bobInvoice.PaymentPreimage) assert.Equal(p.t, outerAmountMsat, bobInvoice.AmountReceivedMsat) // Make sure capacity is correct chans := p.BreezClient().lightningNode.GetChannels() assert.Len(p.t, chans, 1) c := chans[0] AssertChannelCapacity(p.t, outerAmountMsat, c.CapacityMsat) } func testOpenZeroConfSingleHtlc(p *testParams) { alice := lntest.NewCoreLightningNode(p.h, p.m, "Alice") alice.Fund(10000000) p.lsp.LightningNode().Fund(10000000) log.Print("Opening channel between Alice and the lsp") channel := alice.OpenChannel(p.lsp.LightningNode(), &lntest.OpenChannelOptions{ AmountSat: 1000000, }) channelId := alice.WaitForChannelReady(channel) log.Printf("Adding bob's invoices") outerAmountMsat := uint64(2100000) innerAmountMsat := uint64(2100000) description := "Please pay me" innerInvoice, outerInvoice := p.BreezClient().GenerateInvoices(generateInvoicesRequest{ innerAmountMsat: innerAmountMsat, outerAmountMsat: outerAmountMsat, description: description, lsp: p.lsp, }) log.Print("Connecting bob to lspd") p.BreezClient().lightningNode.ConnectPeer(p.lsp.LightningNode()) // NOTE: We pretend to be paying fees to the lsp, but actually we won't. log.Printf("Registering payment with lsp") pretendAmount := outerAmountMsat - 2000000 RegisterPayment(p.lsp, &lspd.PaymentInformation{ PaymentHash: innerInvoice.paymentHash, PaymentSecret: innerInvoice.paymentSecret, Destination: p.BreezClient().lightningNode.NodeId(), IncomingAmountMsat: int64(outerAmountMsat), OutgoingAmountMsat: int64(pretendAmount), }) log.Printf("Alice paying") route := constructRoute(p.lsp.LightningNode(), p.BreezClient().lightningNode, channelId, lntest.NewShortChanIDFromString("1x0x0"), outerAmountMsat) payResp := alice.PayViaRoute(outerAmountMsat, outerInvoice.paymentHash, outerInvoice.paymentSecret, route) bobInvoice := p.BreezClient().lightningNode.GetInvoice(payResp.PaymentHash) assert.Equal(p.t, payResp.PaymentPreimage, bobInvoice.PaymentPreimage) assert.Equal(p.t, outerAmountMsat, bobInvoice.AmountReceivedMsat) // Make sure capacity is correct chans := p.BreezClient().lightningNode.GetChannels() assert.Len(p.t, chans, 1) c := chans[0] AssertChannelCapacity(p.t, outerAmountMsat, c.CapacityMsat) } func constructRoute( lsp lntest.LightningNode, bob lntest.LightningNode, aliceLspChannel lntest.ShortChannelID, lspBobChannel lntest.ShortChannelID, amountMsat uint64, ) *lntest.Route { return &lntest.Route{ Hops: []*lntest.Hop{ { Id: lsp.NodeId(), Channel: aliceLspChannel, AmountMsat: amountMsat + uint64(lspBaseFeeMsat) + (amountMsat * uint64(lspFeeRatePpm) / 1000000), Delay: 144 + lspCltvDelta, }, { Id: bob.NodeId(), Channel: lspBobChannel, AmountMsat: amountMsat, Delay: 144, }, }, } }