public DosTests(RegTestFixture regTestFixture) { RegTestFixture = regTestFixture; BackendHttpClient = new ClearnetHttpClient(() => new Uri(RegTestFixture.BackendEndPoint)); SatoshiClient = new SatoshiClient(BackendHttpClient); }
private volatile bool _disposedValue = false; // To detect redundant calls public RegTestFixture() { RuntimeParams.SetDataDir(Path.Combine(Common.DataDir, "RegTests", "Backend")); RuntimeParams.LoadAsync().GetAwaiter().GetResult(); var hostedServices = new HostedServices(); BackendRegTestNode = TestNodeBuilder.CreateAsync(hostedServices, callerFilePath: "RegTests", callerMemberName: "BitcoinCoreData").GetAwaiter().GetResult(); var walletName = "wallet.dat"; BackendRegTestNode.RpcClient.CreateWalletAsync(walletName).GetAwaiter().GetResult(); var testnetBackendDir = EnvironmentHelpers.GetDataDir(Path.Combine("WalletWasabi", "Tests", "RegTests", "Backend")); IoHelpers.TryDeleteDirectoryAsync(testnetBackendDir).GetAwaiter().GetResult(); Thread.Sleep(100); Directory.CreateDirectory(testnetBackendDir); Thread.Sleep(100); var config = new Config( BackendRegTestNode.RpcClient.Network, BackendRegTestNode.RpcClient.CredentialString.ToString(), new IPEndPoint(IPAddress.Loopback, Network.Main.DefaultPort), new IPEndPoint(IPAddress.Loopback, Network.TestNet.DefaultPort), BackendRegTestNode.P2pEndPoint, new IPEndPoint(IPAddress.Loopback, Network.Main.RPCPort), new IPEndPoint(IPAddress.Loopback, Network.TestNet.RPCPort), BackendRegTestNode.RpcEndPoint); var configFilePath = Path.Combine(testnetBackendDir, "Config.json"); config.SetFilePath(configFilePath); config.ToFile(); var roundConfig = CreateRoundConfig(Money.Coins(0.1m), Constants.OneDayConfirmationTarget, 0.7, 0.1m, 100, 120, 60, 60, 60, 1, 24, true, 11); var roundConfigFilePath = Path.Combine(testnetBackendDir, "CcjRoundConfig.json"); roundConfig.SetFilePath(roundConfigFilePath); roundConfig.ToFile(); var conf = new ConfigurationBuilder() .AddInMemoryCollection(new[] { new KeyValuePair <string, string>("datadir", testnetBackendDir) }) .Build(); BackendEndPoint = $"http://localhost:{CryptoHelpers.RandomInt(37130, 37999)}/"; BackendEndPointUri = new Uri(BackendEndPoint); BackendEndPointApiUri = new Uri(BackendEndPointUri, $"/api/v{Constants.BackendMajorVersion}/"); BackendHost = Host.CreateDefaultBuilder() .ConfigureWebHostDefaults(webBuilder => webBuilder .UseStartup <Startup>() .UseConfiguration(conf) .UseWebRoot("../../../../WalletWasabi.Backend/wwwroot") .UseUrls(BackendEndPoint)) .Build(); if (BackendHost.Services.GetService(typeof(Global)) is not Global global) { throw new InvalidOperationException($"Service {nameof(Global)} is not registered."); } Global = global; Global.HostedServices = hostedServices; var hostInitializationTask = BackendHost.RunWithTasksAsync(); Logger.LogInfo($"Started Backend webhost: {BackendEndPoint}"); HttpClient = new HttpClient(); BackendHttpClient = new ClearnetHttpClient(HttpClient, () => BackendEndPointUri); var delayTask = Task.Delay(3000); Task.WaitAny(delayTask, hostInitializationTask); // Wait for server to initialize (Without this OSX CI will fail) }
public BackendTests(RegTestFixture regTestFixture) { RegTestFixture = regTestFixture; BackendHttpClient = regTestFixture.BackendHttpClient; BackendApiHttpClient = new ClearnetHttpClient(regTestFixture.HttpClient, () => RegTestFixture.BackendEndPointApiUri); }