From f8540dc78c1fc0f13dd7f83d69aeffe7a8312859 Mon Sep 17 00:00:00 2001 From: rockstardev Date: Fri, 11 May 2018 16:59:24 -0500 Subject: [PATCH] Providing merchant_lnd and customer_lnd for testing --- BTCPayServer.Tests/UnitTests/LndTest.cs | 24 ++++++++-- BTCPayServer.Tests/docker-compose.yml | 48 +++++++++++++++++-- .../Payments/Lightning/Lnd/LndClient.cs | 14 ++++-- 3 files changed, 72 insertions(+), 14 deletions(-) diff --git a/BTCPayServer.Tests/UnitTests/LndTest.cs b/BTCPayServer.Tests/UnitTests/LndTest.cs index cae4f3216..a6dd231e3 100644 --- a/BTCPayServer.Tests/UnitTests/LndTest.cs +++ b/BTCPayServer.Tests/UnitTests/LndTest.cs @@ -11,6 +11,7 @@ using Xunit.Abstractions; namespace BTCPayServer.Tests.UnitTests { + // this depends for now on `docker-compose up devlnd` public class LndTest { private readonly ITestOutputHelper output; @@ -20,13 +21,17 @@ namespace BTCPayServer.Tests.UnitTests this.output = output; initializeEnvironment(); - LndRpc = LndSwaggerClientCustomHttp.Create(new Uri("http://localhost:53280"), Network.RegTest); - InvoiceClient = new LndClient(LndRpc); + MerchantLnd = LndSwaggerClientCustomHttp.Create(new Uri("http://127.0.0.1:53280"), Network.RegTest); + InvoiceClient = new LndClient(MerchantLnd); + + CustomerLnd = LndSwaggerClientCustomHttp.Create(new Uri("http://127.0.0.1:53281"), Network.RegTest); } - private LndSwaggerClientCustomHttp LndRpc { get; set; } + private LndSwaggerClientCustomHttp MerchantLnd { get; set; } private LndClient InvoiceClient { get; set; } + private LndSwaggerClientCustomHttp CustomerLnd { get; set; } + [Fact] public async Task GetInfo() { @@ -55,14 +60,23 @@ namespace BTCPayServer.Tests.UnitTests [Fact] public async Task SetupWalletForPayment() { - var nodeInfo = GetInfo(); - var addressResponse = await LndRpc.NewWitnessAddressAsync(); + var merchantNodeInfo = await InvoiceClient.GetInfo(); + var addressResponse = await CustomerLnd.NewWitnessAddressAsync(); var address = BitcoinAddress.Create(addressResponse.Address, Network.RegTest); await ExplorerNode.SendToAddressAsync(address, Money.Coins(0.2m)); ExplorerNode.Generate(1); await WaitLNSynched(); await Task.Delay(1000); + var connectResp = await CustomerLnd.ConnectPeerAsync(new LnrpcConnectPeerRequest + { + Addr = new LnrpcLightningAddress + { + Pubkey = merchantNodeInfo.NodeId, + Host = "merchant_lnd:8080" + } + }); + // We need two instances of lnd... one for merchant, one for buyer // prepare that in next commit //var channelReq = new LnrpcOpenChannelRequest diff --git a/BTCPayServer.Tests/docker-compose.yml b/BTCPayServer.Tests/docker-compose.yml index ecdce19fe..3971748b4 100644 --- a/BTCPayServer.Tests/docker-compose.yml +++ b/BTCPayServer.Tests/docker-compose.yml @@ -44,7 +44,22 @@ services: - customer_lightningd - merchant_lightningd - lightning-charged - - lnd + - customer_lnd + - merchant_lnd + + devlnd: + image: nicolasdorier/docker-bitcoin:0.16.0 + environment: + BITCOIN_EXTRA_ARGS: | + regtest=1 + connect=bitcoind:39388 + links: + - nbxplorer + - postgres + - customer_lnd + - merchant_lnd + + nbxplorer: image: nicolasdorier/nbxplorer:1.0.2.2 @@ -180,7 +195,7 @@ services: expose: - "5432" - lnd: + merchant_lnd: image: btcpayserver/lnd:0.4.1.0 environment: RPCHOST: bitcoind:43782 @@ -193,8 +208,32 @@ services: DEBUG: debug ports: - "53280:8080" + expose: + - "8080" + - "10009" volumes: - - "lnd_datadir:/root/.lnd" + - "merchant_lnd_datadir:/root/.lnd" + links: + - bitcoind + + customer_lnd: + image: btcpayserver/lnd:0.4.1.0 + environment: + RPCHOST: bitcoind:43782 + RPCUSER: ceiwHEbqWI83 + RPCPASS: DwubwWsoo3 + ZMQPATH: tcp://bitcoind:28332 + NETWORK: regtest + CHAIN: bitcoin + BACKEND: bitcoind + DEBUG: debug + ports: + - "53281:8080" + expose: + - "8080" + - "10009" + volumes: + - "customer_lnd_datadir:/root/.lnd" links: - bitcoind @@ -203,4 +242,5 @@ volumes: customer_lightningd_datadir: merchant_lightningd_datadir: lightning_charge_datadir: - lnd_datadir: + customer_lnd_datadir: + merchant_lnd_datadir: diff --git a/BTCPayServer/Payments/Lightning/Lnd/LndClient.cs b/BTCPayServer/Payments/Lightning/Lnd/LndClient.cs index 0b9e6207d..bc141a572 100644 --- a/BTCPayServer/Payments/Lightning/Lnd/LndClient.cs +++ b/BTCPayServer/Payments/Lightning/Lnd/LndClient.cs @@ -51,14 +51,18 @@ namespace BTCPayServer.Payments.Lightning.Lnd { var resp = await _Decorator.GetInfoAsync(cancellation); - var invoice = new LightningNodeInformation + var nodeInfo = new LightningNodeInformation { - Address = resp.Uris?.FirstOrDefault(), BlockHeight = (int?)resp.Block_height ?? 0, - NodeId = resp.Alias, - P2PPort = 0 + NodeId = resp.Identity_pubkey }; - return invoice; + + // 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; + + return nodeInfo; } public async Task GetInvoice(string invoiceId, CancellationToken cancellation = default(CancellationToken))