From f97173e9e7df17a37cd73f9a41cf55fbc4701689 Mon Sep 17 00:00:00 2001 From: rockstardev Date: Sat, 12 May 2018 00:43:13 -0500 Subject: [PATCH] Testing invoice payment with Lnd --- BTCPayServer.Tests/UnitTests/LndTest.cs | 13 ++++++++++++- BTCPayServer/Payments/Lightning/Lnd/LndClient.cs | 11 ++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/BTCPayServer.Tests/UnitTests/LndTest.cs b/BTCPayServer.Tests/UnitTests/LndTest.cs index 49e6c8255..418b73f48 100644 --- a/BTCPayServer.Tests/UnitTests/LndTest.cs +++ b/BTCPayServer.Tests/UnitTests/LndTest.cs @@ -9,6 +9,7 @@ using NBitcoin.RPC; using Xunit; using Xunit.Abstractions; using System.Linq; +using System.Threading; namespace BTCPayServer.Tests.UnitTests { @@ -59,9 +60,19 @@ namespace BTCPayServer.Tests.UnitTests [Fact] - public async Task SetupWalletForPayment() + public async Task CreateLndInvoiceAndPay() { + var merchantInvoice = await InvoiceClient.CreateInvoice(10000, "Hello world", TimeSpan.FromSeconds(3600)); + await EnsureLightningChannelAsync(); + var payResponse = await CustomerLnd.SendPaymentSyncAsync(new LnrpcSendRequest + { + Payment_request = merchantInvoice.BOLT11 + }); + + var invoice = await InvoiceClient.GetInvoice(merchantInvoice.Id); + + Assert.True(invoice.PaidAt.HasValue); } diff --git a/BTCPayServer/Payments/Lightning/Lnd/LndClient.cs b/BTCPayServer/Payments/Lightning/Lnd/LndClient.cs index bc141a572..a97d4b51c 100644 --- a/BTCPayServer/Payments/Lightning/Lnd/LndClient.cs +++ b/BTCPayServer/Payments/Lightning/Lnd/LndClient.cs @@ -57,10 +57,10 @@ namespace BTCPayServer.Payments.Lightning.Lnd NodeId = resp.Identity_pubkey }; - // Lnd doesn't return this data as Clightning so we add it manually from data we have - var uri = new Uri(_Decorator.BaseUrl); - nodeInfo.Address = uri.Host; - nodeInfo.P2PPort = uri.Port; + // Lnd doesn't return this data as Clightning, find alternative ways to supply + // it always should be merchant_lnd:9735 because of docker + nodeInfo.Address = null; + nodeInfo.P2PPort = 9735; return nodeInfo; } @@ -71,6 +71,7 @@ namespace BTCPayServer.Payments.Lightning.Lnd return ConvertLndInvoice(resp); } + // TODO: These two methods where you wait on invoice are still work in progress public Task Listen(CancellationToken cancellation = default(CancellationToken)) { return Task.FromResult(this); @@ -80,8 +81,8 @@ namespace BTCPayServer.Payments.Lightning.Lnd { var resp = await _Decorator.SubscribeInvoicesAsync(cancellation); return ConvertLndInvoice(resp); - } + // Eof work in progress // utility static methods... maybe move to separate class