public async Task CanCreateInvoiceUsingConnectionString()
        {
            ILightningClientFactory factory = new LightningClientFactory(Tester.Network);

            var connectionStrings = Docker
                ? new[]
            {
                "type=charge;server=http://api-token:foiewnccewuify@charge:9112",
                "type=lnd-rest;server=https://lnd_dest:8080;allowinsecure=true",
                "type=clightning;server=tcp://lightningd:9835",
                "type=eclair;server=http://eclair:8080;password=bukkake;bitcoin-host=bitcoind:43782;bitcoin-auth=ceiwHEbqWI83:DwubwWsoo3"
            }
                : new[]
            {
                "type=charge;server=http://api-token:[email protected]:37462",
                "type=lnd-rest;server=https://127.0.0.1:42802;allowinsecure=true",
                "type=clightning;server=tcp://127.0.0.1:48532",
                "type=eclair;server=http://127.0.0.1:4570;password=bukkake;bitcoin-host=127.0.0.1:37393;bitcoin-auth=ceiwHEbqWI83:DwubwWsoo3"
            };

            foreach (var connectionString in connectionStrings)
            {
                ILightningClient client = factory.Create(connectionString);
                var createdInvoice      = await client.CreateInvoice(10000, "CanCreateInvoice", TimeSpan.FromMinutes(5));

                var retrievedInvoice = await client.GetInvoice(createdInvoice.Id);

                AssertUnpaid(createdInvoice);
                AssertUnpaid(retrievedInvoice);
            }
        }
Esempio n. 2
0
        public ChargeTester(ServerTester serverTester, string environmentName, string defaultValue, string defaultHost, Network network)
        {
            this._Parent = serverTester;
            var url = serverTester.GetEnvironment(environmentName, defaultValue);

            Client  = (ChargeClient)LightningClientFactory.CreateClient(url, network);
            P2PHost = _Parent.GetEnvironment(environmentName + "_HOST", defaultHost);
        }
Esempio n. 3
0
        public ILightningClient ConstructClient(
            LightningNodeExternalServiceData lightningNodeExternalServiceData = null)
        {
            var data = lightningNodeExternalServiceData ?? GetData();

            var client = _nbXplorerClientProvider.GetClient(data.CryptoCode);

            return(LightningClientFactory.CreateClient(data.ConnectionString, client.Network.NBitcoinNetwork));
        }
Esempio n. 4
0
        public void ActivateLightning(LightningConnectionType internalNode)
        {
            var btc = NetworkProvider.GetNetwork <BTCPayNetwork>("BTC").NBitcoinNetwork;

            CustomerLightningD            = LightningClientFactory.CreateClient(GetEnvironment("TEST_CUSTOMERLIGHTNINGD", "type=clightning;server=tcp://127.0.0.1:30992/"), btc);
            MerchantLightningD            = LightningClientFactory.CreateClient(GetEnvironment("TEST_MERCHANTLIGHTNINGD", "type=clightning;server=tcp://127.0.0.1:30993/"), btc);
            MerchantCharge                = new ChargeTester(this, "TEST_MERCHANTCHARGE", "type=charge;server=http://127.0.0.1:54938/;api-token=foiewnccewuify;allowinsecure=true", "merchant_lightningd", btc);
            MerchantLnd                   = new LndMockTester(this, "TEST_MERCHANTLND", "http://*****:*****@127.0.0.1:35531/", "merchant_lnd", btc);
            PayTester.UseLightning        = true;
            PayTester.IntegratedLightning = GetLightningConnectionString(internalNode, true);
        }
Esempio n. 5
0
        private LndClient CreateLndClient()
        {
            if (!LightningConnectionString.TryParse(
                    $"type=lnd-rest;server={this.configuration.LndRestApiUri};macaroon={this.configuration.MacaroonHex};certthumbprint={this.configuration.CertThumbprintHex}",
                    false, out var connectionString))
            {
                throw new ArgumentException("Unable to contruct the connection string");
            }

            Logger.Debug("LndClient connection string created successfully");

            return((LndClient)LightningClientFactory.CreateClient(
                       connectionString,
                       this.configuration.Network == Network.MainNet ? NBitcoin.Network.Main : NBitcoin.Network.TestNet));
        }
Esempio n. 6
0
        public LightningClientProvider(IOptions <LightningHubOptions> options)
        {
            if (!LightningConnectionString.TryParse(options.Value.LightningConnectionString, out var connectionString))
            {
                throw new Exception("Connection string was invalid");
            }

            var networkSets = NBitcoin.Network.GetNetworks().Select(network => network.NetworkSet).Distinct();

            var networkSet = networkSets.Single(set =>
                                                set.CryptoCode.Equals(options.Value.CryptoCode, StringComparison.InvariantCultureIgnoreCase));

            _network         = networkSet.GetNetwork(options.Value.NetworkType);
            _lightningClient = LightningClientFactory.CreateClient(connectionString, _network);
        }
Esempio n. 7
0
        public ServerTester(string scope)
        {
            _Directory = scope;
            if (Directory.Exists(_Directory))
            {
                Utils.DeleteDirectory(_Directory);
            }
            if (!Directory.Exists(_Directory))
            {
                Directory.CreateDirectory(_Directory);
            }

            NetworkProvider = new BTCPayNetworkProvider(NetworkType.Regtest);
            ExplorerNode    = new RPCClient(RPCCredentialString.Parse(GetEnvironment("TESTS_BTCRPCCONNECTION", "server=http://127.0.0.1:43782;ceiwHEbqWI83:DwubwWsoo3")), NetworkProvider.GetNetwork <BTCPayNetwork>("BTC").NBitcoinNetwork);
            ExplorerNode.ScanRPCCapabilities();
            LTCExplorerNode = new RPCClient(RPCCredentialString.Parse(GetEnvironment("TESTS_LTCRPCCONNECTION", "server=http://127.0.0.1:43783;ceiwHEbqWI83:DwubwWsoo3")), NetworkProvider.GetNetwork <BTCPayNetwork>("LTC").NBitcoinNetwork);

            ExplorerClient    = new ExplorerClient(NetworkProvider.GetNetwork <BTCPayNetwork>("BTC").NBXplorerNetwork, new Uri(GetEnvironment("TESTS_BTCNBXPLORERURL", "http://127.0.0.1:32838/")));
            LTCExplorerClient = new ExplorerClient(NetworkProvider.GetNetwork <BTCPayNetwork>("LTC").NBXplorerNetwork, new Uri(GetEnvironment("TESTS_LTCNBXPLORERURL", "http://127.0.0.1:32838/")));

            var btc = NetworkProvider.GetNetwork <BTCPayNetwork>("BTC").NBitcoinNetwork;

            CustomerLightningD = LightningClientFactory.CreateClient(GetEnvironment("TEST_CUSTOMERLIGHTNINGD", "type=clightning;server=tcp://127.0.0.1:30992/"), btc);
            MerchantLightningD = LightningClientFactory.CreateClient(GetEnvironment("TEST_MERCHANTLIGHTNINGD", "type=clightning;server=tcp://127.0.0.1:30993/"), btc);

            MerchantCharge = new ChargeTester(this, "TEST_MERCHANTCHARGE", "type=charge;server=http://127.0.0.1:54938/;api-token=foiewnccewuify", "merchant_lightningd", btc);

            MerchantLnd = new LndMockTester(this, "TEST_MERCHANTLND", "https://*****:*****@127.0.0.1:53280/", "merchant_lnd", btc);

            PayTester = new BTCPayServerTester(Path.Combine(_Directory, "pay"))
            {
                NBXplorerUri        = ExplorerClient.Address,
                LTCNBXplorerUri     = LTCExplorerClient.Address,
                TestDatabase        = Enum.Parse <TestDatabases>(GetEnvironment("TESTS_DB", TestDatabases.Postgres.ToString()), true),
                Postgres            = GetEnvironment("TESTS_POSTGRES", "User ID=postgres;Host=127.0.0.1;Port=39372;Database=btcpayserver"),
                MySQL               = GetEnvironment("TESTS_MYSQL", "User ID=root;Host=127.0.0.1;Port=33036;Database=btcpayserver"),
                IntegratedLightning = MerchantCharge.Client.Uri
            };
            PayTester.Port        = int.Parse(GetEnvironment("TESTS_PORT", Utils.FreeTcpPort().ToString(CultureInfo.InvariantCulture)), CultureInfo.InvariantCulture);
            PayTester.HostName    = GetEnvironment("TESTS_HOSTNAME", "127.0.0.1");
            PayTester.InContainer = bool.Parse(GetEnvironment("TESTS_INCONTAINER", "false"));

            PayTester.SSHPassword   = GetEnvironment("TESTS_SSHPASSWORD", "opD3i2282D");
            PayTester.SSHKeyFile    = GetEnvironment("TESTS_SSHKEYFILE", "");
            PayTester.SSHConnection = GetEnvironment("TESTS_SSHCONNECTION", "[email protected]:21622");
        }
Esempio n. 8
0
        public async Task CanCreateInvoiceUsingConnectionString()
        {
            ILightningClientFactory factory = new LightningClientFactory(Tester.Network);

            foreach (var connectionString in new[]
            {
                "type=charge;server=http://api-token:[email protected]:37462",
                "type=lnd-rest;server=https://127.0.0.1:42802;allowinsecure=true",
                "type=clightning;server=tcp://127.0.0.1:48532"
            })
            {
                ILightningClient client = factory.Create(connectionString);
                var createdInvoice      = await client.CreateInvoice(10000, "CanCreateInvoice", TimeSpan.FromMinutes(5));

                var retrievedInvoice = await client.GetInvoice(createdInvoice.Id);

                AssertUnpaid(createdInvoice);
                AssertUnpaid(retrievedInvoice);
            }
        }
Esempio n. 9
0
        public async Task CanCreateInvoiceUsingConnectionString()
        {
            ILightningClientFactory factory = new LightningClientFactory(Tester.Network);

            var connectionStrings = Docker
                ? new[]
            {
                "type=charge;server=http://api-token:foiewnccewuify@charge:9112;allowinsecure=true",
                "type=lnd-rest;server=http://lnd_dest:8080;allowinsecure=true",
                "type=clightning;server=tcp://lightningd:9835",
                "type=eclair;server=http://eclair:8080;password=bukkake"
            }
                : new[]
            {
                "type=charge;server=http://api-token:[email protected]:37462;allowinsecure=true",
                "type=lnd-rest;server=http://127.0.0.1:42802;allowinsecure=true",
                "type=clightning;server=tcp://127.0.0.1:48532",
                "type=eclair;server=http://127.0.0.1:4570;password=bukkake"
            };

            var clientTypes = Tester.GetLightningClients().Select(l => l.Client.GetType()).ToArray();

            foreach (var connectionString in connectionStrings)
            {
                var client = factory.Create(connectionString);
                if (!clientTypes.Contains(client.GetType()))
                {
                    continue;
                }
                var createdInvoice = await client.CreateInvoice(10000, "CanCreateInvoice", TimeSpan.FromMinutes(5));

                var retrievedInvoice = await client.GetInvoice(createdInvoice.Id);

                AssertUnpaid(createdInvoice);
                AssertUnpaid(retrievedInvoice);
            }
        }
Esempio n. 10
0
        public static async Task <Clients> StartLNTestFixtureAsync(this DockerFixture dockerFixture, string caller, bool useCachedData = false)
        {
            var ports = new int[5];

            Support.Utils.FindEmptyPort(ports);
            var dataPath = Path.GetFullPath(caller);

            if (Directory.Exists(dataPath) && !useCachedData)
            {
                Directory.Delete(dataPath, true);
            }
            Directory.CreateDirectory(dataPath);

            var env = new Dictionary <string, object>()
            {
                {
                    "BITCOIND_RPC_AUTH",
                    Constants.BitcoindRPCAuth
                },
                { "BITCOIND_RPC_USER", Constants.BitcoindRPCUser },
                { "BITCOIND_RPC_PASS", Constants.BitcoindRPCPass },
                { "BITCOIND_RPC_PORT", ports[0] },
                { "LND_REST_PORT", ports[1] },
                { "LIGHTNINGD_RPC_PORT", ports[2] },
                { "HTTP_PORT", ports[3] },
                { "NBXPLORER_PORT", ports[4] },
                { "DATA_PATH", dataPath }
            };
            var envFile = Path.Join(dataPath, "env.sh");

            using (TextWriter w = File.AppendText(envFile))
            {
                foreach (var kv in env)
                {
                    w.WriteLine($"export {kv.Key}='{kv.Value}'");
                }
            }
            await dockerFixture.InitAsync(() => new DockerFixtureOptions
            {
                DockerComposeFiles    = new[] { "docker-compose.yml" },
                EnvironmentVariables  = env,
                DockerComposeDownArgs = "--remove-orphans --volumes",
                // we need this because c-lightning is not working well with bind mount.
                // If we use volume mount instead, this is the only way to recreate the volume at runtime.
                DockerComposeUpArgs = "--renew-anon-volumes",
                StartupTimeoutSecs  = 400,
                LogFilePath         = Path.Join(dataPath, "docker-compose.log"),
                CustomUpTest        = o =>
                {
                    return
                    (o.Any(x => x.Contains("Now listening on: http://0.0.0.0:9735")) && // nrustlightning is up
                     o.Any(x => x.Contains("PeerManagerProvider started")) &&    // ditto
                     o.Any(x => x.Contains("Server started with public key")) &&    // lightningd is up
                     o.Any(x => x.Contains("BTC: Node state changed: NBXplorerSynching => Ready")) &&    // nbx is up
                     o.Any(x => x.Contains("BTCN: Server listening on")));      // lnd is up
                }
            });

            var networkProvider      = new NRustLightningNetworkProvider(NetworkType.Regtest);
            var btcNetwork           = networkProvider.GetByCryptoCode("BTC");
            var lndMacaroonPath      = Path.Join(dataPath, ".lnd", "chain", "bitcoin", "regtest", "admin.macaroon");
            var lndTlsCertThumbPrint = GetCertificateFingerPrintHex(Path.Join(dataPath, ".lnd", "tls.cert"));
            var clients = new Clients(
                new RPCClient($"{Constants.BitcoindRPCUser}:{Constants.BitcoindRPCPass}", new Uri($"http://localhost:{ports[0]}"), NBitcoin.Network.RegTest),
                (LndClient)LightningClientFactory.CreateClient($"type=lnd-rest;macaroonfilepath={lndMacaroonPath};certthumbprint={lndTlsCertThumbPrint};server=https://localhost:{ports[1]}", NBitcoin.Network.RegTest),
                (CLightningClient)LightningClientFactory.CreateClient($"type=clightning;server=tcp://127.0.0.1:{ports[2]}", NBitcoin.Network.RegTest),
                new NRustLightningClient($"http://localhost:{ports[3]}", btcNetwork),
                new ExplorerClient(btcNetwork.NbXplorerNetwork, new Uri($"http://localhost:{ports[4]}"))
                );

            return(clients);
        }