private void StartNBXplorer() { var port = CustomServer.FreeTcpPort(); List <(string key, string value)> keyValues = new List <(string key, string value)>(); keyValues.Add(("conf", Path.Combine(datadir, "settings.config"))); keyValues.Add(("datadir", datadir)); keyValues.Add(("port", port.ToString())); keyValues.Add(("network", "regtest")); keyValues.Add(("chains", CryptoCode.ToLowerInvariant())); keyValues.Add(("verbose", "1")); keyValues.Add(($"{CryptoCode.ToLowerInvariant()}rpcauth", Explorer.GetRPCAuth())); keyValues.Add(($"{CryptoCode.ToLowerInvariant()}rpcurl", Explorer.CreateRPCClient().Address.AbsoluteUri)); keyValues.Add(("cachechain", "0")); keyValues.Add(("rpcnotest", "1")); keyValues.Add(("mingapsize", "3")); keyValues.Add(("maxgapsize", "8")); keyValues.Add(($"{CryptoCode.ToLowerInvariant()}startheight", Explorer.CreateRPCClient().GetBlockCount().ToString())); keyValues.Add(($"{CryptoCode.ToLowerInvariant()}nodeendpoint", $"{Explorer.Endpoint.Address}:{Explorer.Endpoint.Port}")); keyValues.Add(("asbcnstr", AzureServiceBusTestConfig.ConnectionString)); keyValues.Add(("asbblockq", AzureServiceBusTestConfig.NewBlockQueue)); keyValues.Add(("asbtranq", AzureServiceBusTestConfig.NewTransactionQueue)); keyValues.Add(("asbblockt", AzureServiceBusTestConfig.NewBlockTopic)); keyValues.Add(("asbtrant", AzureServiceBusTestConfig.NewTransactionTopic)); var args = keyValues.SelectMany(kv => new[] { $"--{kv.key}", kv.value } .Concat(new[] { $"--{CryptoCode.ToLowerInvariant()}hastxindex" })).ToArray(); Host = new WebHostBuilder() .UseConfiguration(new DefaultConfiguration().CreateConfiguration(args)) .UseKestrel() .ConfigureLogging(l => { l.SetMinimumLevel(LogLevel.Information) .AddFilter("System.Net.Http.HttpClient", LogLevel.Error) .AddFilter("Microsoft", LogLevel.Error) .AddFilter("Hangfire", LogLevel.Error) .AddFilter("NBXplorer.Authentication.BasicAuthenticationHandler", LogLevel.Critical) .AddProvider(Logs.LogProvider); }) .UseStartup <Startup>() .Build(); RPC = ((RPCClientProvider)Host.Services.GetService(typeof(RPCClientProvider))).GetRPCClient(CryptoCode); var nbxnetwork = ((NBXplorerNetworkProvider)Host.Services.GetService(typeof(NBXplorerNetworkProvider))).GetFromCryptoCode(CryptoCode); Network = nbxnetwork.NBitcoinNetwork; var conf = (ExplorerConfiguration)Host.Services.GetService(typeof(ExplorerConfiguration)); Host.Start(); Configuration = conf; _Client = new ExplorerClient(nbxnetwork, Address); _Client.SetCookieAuth(Path.Combine(conf.DataDir, ".cookie")); Notifications = _Client.CreateLongPollingNotificationSession(); }
public ServerTester(string directory) { SetEnvironment(); try { var rootTestData = "TestData"; directory = Path.Combine(rootTestData, directory); _Directory = directory; if (!Directory.Exists(rootTestData)) { Directory.CreateDirectory(rootTestData); } var cryptoSettings = new NBXplorerNetworkProvider(NetworkType.Regtest).GetFromCryptoCode(CryptoCode); NodeBuilder = NodeBuilder.Create(nodeDownloadData, Network, directory); User1 = NodeBuilder.CreateNode(); User2 = NodeBuilder.CreateNode(); Explorer = NodeBuilder.CreateNode(); foreach (var node in NodeBuilder.Nodes) { node.WhiteBind = true; node.CookieAuth = cryptoSettings.SupportCookieAuthentication; } NodeBuilder.StartAll(); User1.CreateRPCClient().Generate(1); User1.Sync(Explorer, true); Explorer.CreateRPCClient().Generate(1); Explorer.Sync(User2, true); User2.CreateRPCClient().EnsureGenerate(Network.Consensus.CoinbaseMaturity + 1); User1.Sync(User2, true); var port = CustomServer.FreeTcpPort(); var datadir = Path.Combine(directory, "explorer"); DeleteRecursivelyWithMagicDust(datadir); List <(string key, string value)> keyValues = new List <(string key, string value)>(); keyValues.Add(("conf", Path.Combine(directory, "explorer", "settings.config"))); keyValues.Add(("datadir", datadir)); keyValues.Add(("port", port.ToString())); keyValues.Add(("network", "regtest")); keyValues.Add(("chains", CryptoCode.ToLowerInvariant())); keyValues.Add(("verbose", "1")); keyValues.Add(($"{CryptoCode.ToLowerInvariant()}rpcauth", Explorer.GetRPCAuth())); keyValues.Add(($"{CryptoCode.ToLowerInvariant()}rpcurl", Explorer.CreateRPCClient().Address.AbsoluteUri)); keyValues.Add(("cachechain", "0")); keyValues.Add(("rpcnotest", "1")); keyValues.Add(("mingapsize", "2")); keyValues.Add(("maxgapsize", "4")); keyValues.Add(($"{CryptoCode.ToLowerInvariant()}startheight", Explorer.CreateRPCClient().GetBlockCount().ToString())); keyValues.Add(($"{CryptoCode.ToLowerInvariant()}nodeendpoint", $"{Explorer.Endpoint.Address}:{Explorer.Endpoint.Port}")); keyValues.Add(("asbcnstr", AzureServiceBusTestConfig.ConnectionString)); keyValues.Add(("asbblockq", AzureServiceBusTestConfig.NewBlockQueue)); keyValues.Add(("asbtranq", AzureServiceBusTestConfig.NewTransactionQueue)); keyValues.Add(("asbblockt", AzureServiceBusTestConfig.NewBlockTopic)); keyValues.Add(("asbtrant", AzureServiceBusTestConfig.NewTransactionTopic)); var args = keyValues.SelectMany(kv => new[] { $"--{kv.key}", kv.value }).ToArray(); Host = new WebHostBuilder() .UseConfiguration(new DefaultConfiguration().CreateConfiguration(args)) .UseKestrel() .ConfigureLogging(l => { l.SetMinimumLevel(LogLevel.Information) .AddFilter("Microsoft", LogLevel.Error) .AddFilter("Hangfire", LogLevel.Error) .AddFilter("NBXplorer.Authentication.BasicAuthenticationHandler", LogLevel.Critical) .AddProvider(Logs.LogProvider); }) .UseStartup <Startup>() .Build(); RPC = ((RPCClientProvider)Host.Services.GetService(typeof(RPCClientProvider))).GetRPCClient(CryptoCode); var nbxnetwork = ((NBXplorerNetworkProvider)Host.Services.GetService(typeof(NBXplorerNetworkProvider))).GetFromCryptoCode(CryptoCode); Network = nbxnetwork.NBitcoinNetwork; var conf = (ExplorerConfiguration)Host.Services.GetService(typeof(ExplorerConfiguration)); Host.Start(); _Client = new ExplorerClient(nbxnetwork, Address); _Client.SetCookieAuth(Path.Combine(conf.DataDir, ".cookie")); } catch { Dispose(); throw; } }