package itest import ( "log" "github.com/breez/lntest" lspd "github.com/breez/lspd/rpc" "github.com/stretchr/testify/assert" ) func testZeroReserve(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) alice.PayViaRoute(outerAmountMsat, outerInvoice.paymentHash, outerInvoice.paymentSecret, route) // Make sure balance is correct chans := p.BreezClient().lightningNode.GetChannels() assert.Len(p.t, chans, 1) c := chans[0] assert.Equal(p.t, c.RemoteReserveMsat, c.CapacityMsat/100) assert.Zero(p.t, c.LocalReserveMsat) }