/// <summary> /// Start bitcoind and nbxplorer in the backgroud. /// </summary> /// <param name="dockerFixture"></param> /// <param name="output"></param> /// <param name="caller"></param> /// <returns></returns> public static async Task <ExplorerClient> StartExplorerFixtureAsync(this DockerFixture dockerFixture, string caller) { var ports = new int[2]; Support.Utils.FindEmptyPort(ports); var dataPath = Path.GetFullPath(caller); if (!Directory.Exists(dataPath)) { Directory.CreateDirectory(dataPath); } else { 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] }, { "NBXPLORER_PORT", ports[1] }, { "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.base.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("BTC: Node state changed: NBXplorerSynching => Ready"))); // nbx is up } }); var networkProvider = new NRustLightningNetworkProvider(NetworkType.Regtest); var btcNetwork = networkProvider.GetByCryptoCode("BTC"); return(new ExplorerClient(btcNetwork.NbXplorerNetwork, new Uri($"http://localhost:{ports[1]}"))); }
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); }