Refactor default constructors
MODIFY
WalletWasabi.Tests/RegTests.cs
WalletWasabi.Tests/RegTests.cs
@@ -84,7 +84,7 @@ namespace WalletWasabi.Tests
[Trait("Category", "TorNotNeeded")]
public async Task GetExchangeRatesAsync()
{
- using (var client = new TorHttpClient(new Uri(RegTestFixture.BackendEndPoint)))
+ using (var client = new TorHttpClient(new Uri(RegTestFixture.BackendEndPoint), SharedFixture.TorSocks5Endpoint))
using (var response = await client.SendAsync(HttpMethod.Get, $"/api/v{Helpers.Constants.BackendMajorVersion}/btc/offchain/exchange-rates"))
{
Assert.True(response.StatusCode == HttpStatusCode.OK);
@@ -127,7 +127,7 @@ namespace WalletWasabi.Tests
var content = new StringContent($"'{signedTx.ToHex()}'", Encoding.UTF8, "application/json");
Logger.TurnOff();
- using (var client = new TorHttpClient(new Uri(RegTestFixture.BackendEndPoint)))
+ using (var client = new TorHttpClient(new Uri(RegTestFixture.BackendEndPoint), SharedFixture.TorSocks5Endpoint))
using (var response = await client.SendAsync(HttpMethod.Post, $"/api/v{Helpers.Constants.BackendMajorVersion}/btc/blockchain/broadcast", content))
{
Assert.NotEqual(HttpStatusCode.OK, response.StatusCode);
@@ -148,7 +148,7 @@ namespace WalletWasabi.Tests
var content = new StringContent($"'{tx.ToHex()}'", Encoding.UTF8, "application/json");
Logger.TurnOff();
- using (var client = new TorHttpClient(new Uri(RegTestFixture.BackendEndPoint)))
+ using (var client = new TorHttpClient(new Uri(RegTestFixture.BackendEndPoint), SharedFixture.TorSocks5Endpoint))
using (var response = await client.SendAsync(HttpMethod.Post, $"/api/v{Helpers.Constants.BackendMajorVersion}/btc/blockchain/broadcast", content))
{
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
@@ -166,7 +166,7 @@ namespace WalletWasabi.Tests
var content = new StringContent($"''", Encoding.UTF8, "application/json");
Logger.TurnOff();
- using (var client = new TorHttpClient(new Uri(RegTestFixture.BackendEndPoint)))
+ using (var client = new TorHttpClient(new Uri(RegTestFixture.BackendEndPoint), SharedFixture.TorSocks5Endpoint))
using (var response = await client.SendAsync(HttpMethod.Post, $"/api/v{Helpers.Constants.BackendMajorVersion}/btc/blockchain/broadcast", content))
{
Assert.NotEqual(HttpStatusCode.OK, response.StatusCode);
@@ -1659,7 +1659,7 @@ namespace WalletWasabi.Tests
coordinator.AbortAllRoundsInInputRegistration(nameof(RegTests), "");
Uri baseUri = new Uri(RegTestFixture.BackendEndPoint);
- using (var torClient = new TorHttpClient(baseUri))
+ using (var torClient = new TorHttpClient(baseUri, SharedFixture.TorSocks5Endpoint))
using (var satoshiClient = new SatoshiClient(baseUri))
{
#region PostInputsGetStates

MODIFY
WalletWasabi.Tests/TorTests.cs
WalletWasabi.Tests/TorTests.cs
@@ -23,7 +23,7 @@ namespace WalletWasabi.Tests
[Fact]
public async Task CanDoRequestManyDifferentAsync()
{
- using (var client = new TorHttpClient(new Uri("http://api.qbit.ninja")))
+ using (var client = new TorHttpClient(new Uri("http://api.qbit.ninja"), SharedFixture.TorSocks5Endpoint))
{
await QBitTestAsync(client, 10, alterRequests: true);
}
@@ -32,7 +32,7 @@ namespace WalletWasabi.Tests
[Fact]
public async Task CanRequestChunkEncodedAsync()
{
- using (var client = new TorHttpClient(new Uri("https://jigsaw.w3.org/")))
+ using (var client = new TorHttpClient(new Uri("https://jigsaw.w3.org/"), SharedFixture.TorSocks5Endpoint))
{
var response = await client.SendAsync(HttpMethod.Get, "/HTTP/ChunkedScript");
var content = await response.Content.ReadAsStringAsync();
@@ -43,7 +43,7 @@ namespace WalletWasabi.Tests
[Fact]
public async Task CanDoBasicPostHttpsRequestAsync()
{
- using (var client = new TorHttpClient(new Uri("https://api.smartbit.com.au")))
+ using (var client = new TorHttpClient(new Uri("https://api.smartbit.com.au"), SharedFixture.TorSocks5Endpoint))
{
HttpContent content = new StringContent("{\"hex\": \"01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff2d03a58605204d696e656420627920416e74506f6f6c20757361311f10b53620558903d80272a70c0000724c0600ffffffff010f9e5096000000001976a9142ef12bd2ac1416406d0e132e5bc8d0b02df3861b88ac00000000\"}");
@@ -70,7 +70,7 @@ namespace WalletWasabi.Tests
}
// 2. Get Tor IP
- using (var client = new TorHttpClient(new Uri(requestUri)))
+ using (var client = new TorHttpClient(new Uri(requestUri), SharedFixture.TorSocks5Endpoint))
{
var content = await (await client.SendAsync(HttpMethod.Get, "")).Content.ReadAsStringAsync();
var gotIp = IPAddress.TryParse(content.Replace("\n", ""), out torIp);
@@ -83,7 +83,7 @@ namespace WalletWasabi.Tests
[Fact]
public async Task CanDoHttpsAsync()
{
- using (var client = new TorHttpClient(new Uri("https://slack.com")))
+ using (var client = new TorHttpClient(new Uri("https://slack.com"), SharedFixture.TorSocks5Endpoint))
{
var content =
await (await client.SendAsync(HttpMethod.Get, "api/api.test")).Content.ReadAsStringAsync();
@@ -95,7 +95,7 @@ namespace WalletWasabi.Tests
[Fact]
public async Task CanDoIpAddressAsync()
{
- using (var client = new TorHttpClient(new Uri("http://172.217.6.142")))
+ using (var client = new TorHttpClient(new Uri("http://172.217.6.142"), SharedFixture.TorSocks5Endpoint))
{
var content = await (await client.SendAsync(HttpMethod.Get, "")).Content.ReadAsStringAsync();
@@ -106,7 +106,7 @@ namespace WalletWasabi.Tests
[Fact]
public async Task CanRequestInRowAsync()
{
- using (var client = new TorHttpClient(new Uri("http://api.qbit.ninja")))
+ using (var client = new TorHttpClient(new Uri("http://api.qbit.ninja"), SharedFixture.TorSocks5Endpoint))
{
await (await client.SendAsync(HttpMethod.Get, "/transactions/38d4cfeb57d6685753b7a3b3534c3cb576c34ca7344cd4582f9613ebf0c2b02a?format=json&headeronly=true")).Content.ReadAsStringAsync();
await (await client.SendAsync(HttpMethod.Get, "/balances/15sYbVpRh6dyWycZMwPdxJWD4xbfxReeHe?unspentonly=true")).Content.ReadAsStringAsync();
@@ -117,7 +117,7 @@ namespace WalletWasabi.Tests
[Fact]
public async Task CanRequestOnionV2Async()
{
- using (var client = new TorHttpClient(new Uri("http://expyuzz4wqqyqhjn.onion/")))
+ using (var client = new TorHttpClient(new Uri("http://expyuzz4wqqyqhjn.onion/"), SharedFixture.TorSocks5Endpoint))
{
HttpResponseMessage response = await client.SendAsync(HttpMethod.Get, "");
var content = await response.Content.ReadAsStringAsync();
@@ -131,7 +131,7 @@ namespace WalletWasabi.Tests
[Fact]
public async Task CanRequestOnionV3Async()
{
- using (var client = new TorHttpClient(new Uri("http://dds6qkxpwdeubwucdiaord2xgbbeyds25rbsgr73tbfpqpt4a6vjwsyd.onion")))
+ using (var client = new TorHttpClient(new Uri("http://dds6qkxpwdeubwucdiaord2xgbbeyds25rbsgr73tbfpqpt4a6vjwsyd.onion"), SharedFixture.TorSocks5Endpoint))
{
HttpResponseMessage response = await client.SendAsync(HttpMethod.Get, "");
var content = await response.Content.ReadAsStringAsync();
@@ -145,9 +145,9 @@ namespace WalletWasabi.Tests
[Fact]
public async Task DoesntIsolateStreamsAsync()
{
- using (var c1 = new TorHttpClient(new Uri("http://api.ipify.org")))
- using (var c2 = new TorHttpClient(new Uri("http://api.ipify.org")))
- using (var c3 = new TorHttpClient(new Uri("http://api.ipify.org")))
+ using (var c1 = new TorHttpClient(new Uri("http://api.ipify.org"), SharedFixture.TorSocks5Endpoint))
+ using (var c2 = new TorHttpClient(new Uri("http://api.ipify.org"), SharedFixture.TorSocks5Endpoint))
+ using (var c3 = new TorHttpClient(new Uri("http://api.ipify.org"), SharedFixture.TorSocks5Endpoint))
{
var t1 = c1.SendAsync(HttpMethod.Get, "");
var t2 = c2.SendAsync(HttpMethod.Get, "");
@@ -167,9 +167,9 @@ namespace WalletWasabi.Tests
[Fact]
public async Task IsolatesStreamsAsync()
{
- using (var c1 = new TorHttpClient(new Uri("http://api.ipify.org"), isolateStream: true))
- using (var c2 = new TorHttpClient(new Uri("http://api.ipify.org"), isolateStream: true))
- using (var c3 = new TorHttpClient(new Uri("http://api.ipify.org"), isolateStream: true))
+ using (var c1 = new TorHttpClient(new Uri("http://api.ipify.org"), SharedFixture.TorSocks5Endpoint, isolateStream: true))
+ using (var c2 = new TorHttpClient(new Uri("http://api.ipify.org"), SharedFixture.TorSocks5Endpoint, isolateStream: true))
+ using (var c3 = new TorHttpClient(new Uri("http://api.ipify.org"), SharedFixture.TorSocks5Endpoint, isolateStream: true))
{
var t1 = c1.SendAsync(HttpMethod.Get, "");
var t2 = c2.SendAsync(HttpMethod.Get, "");
@@ -189,7 +189,8 @@ namespace WalletWasabi.Tests
[Fact]
public async Task TorRunningAsync()
{
- Assert.True(await TorProcessManager.IsTorRunningAsync());
+ Assert.True(await TorProcessManager.IsTorRunningAsync(null));
+ Assert.True(await TorProcessManager.IsTorRunningAsync(new IPEndPoint(IPAddress.Loopback, 9050)));
Assert.False(await TorProcessManager.IsTorRunningAsync(new IPEndPoint(IPAddress.Loopback, 9054)));
}
@@ -203,7 +204,7 @@ namespace WalletWasabi.Tests
var task = client.SendAsync(HttpMethod.Get, relativetUri);
if (alterRequests)
{
- using (var ipClient = new TorHttpClient(new Uri("https://api.ipify.org/")))
+ using (var ipClient = new TorHttpClient(new Uri("https://api.ipify.org/"), SharedFixture.TorSocks5Endpoint))
{
var task2 = ipClient.SendAsync(HttpMethod.Get, "/");
tasks.Add(task2);

MODIFY
WalletWasabi/TorSocks5/TorHttpClient.cs
WalletWasabi/TorSocks5/TorHttpClient.cs
@@ -29,8 +29,7 @@ namespace WalletWasabi.TorSocks5
private static AsyncLock AsyncLock { get; } = new AsyncLock(); // We make everything synchronous, so slow, but at least stable
- /// <param name="torSocks5EndPoint">if null, then localhost:9050</param>
- public TorHttpClient(Uri baseUri, IPEndPoint torSocks5EndPoint = null, bool isolateStream = false)
+ public TorHttpClient(Uri baseUri, IPEndPoint torSocks5EndPoint, bool isolateStream = false)
{
DestinationUri = Guard.NotNull(nameof(baseUri), baseUri);
if (DestinationUri.IsLoopback)

MODIFY
WalletWasabi/TorSocks5/TorProcessManager.cs
WalletWasabi/TorSocks5/TorProcessManager.cs
@@ -11,8 +11,8 @@ namespace WalletWasabi.TorSocks5
{
public IPEndPoint TorSocks5EndPoint { get; }
- /// <param name="torSocks5EndPoint">if null, then localhost:9050</param>
- public TorProcessManager(IPEndPoint torSocks5EndPoint = null)
+ /// <param name="torSocks5EndPoint">Opt out Tor with null.</param>
+ public TorProcessManager(IPEndPoint torSocks5EndPoint)
{
TorSocks5EndPoint = torSocks5EndPoint ?? new IPEndPoint(IPAddress.Loopback, 9050);
}
@@ -23,7 +23,7 @@ namespace WalletWasabi.TorSocks5
// 2. Can I simply run it from output directory?
// 3. Can I copy and unzip it from assets?
// 4. Throw exception.
- if (await IsTorRunningAsync())
+ if (await IsTorRunningAsync(TorSocks5EndPoint))
{
return;
}
@@ -31,8 +31,8 @@ namespace WalletWasabi.TorSocks5
throw new NotImplementedException();
}
- /// <param name="torSocks5EndPoint">if null, then localhost:9050</param>
- public static async Task<bool> IsTorRunningAsync(IPEndPoint torSocks5EndPoint = null)
+ /// <param name="torSocks5EndPoint">Opt out Tor with null.</param>
+ public static async Task<bool> IsTorRunningAsync(IPEndPoint torSocks5EndPoint)
{
using (var client = new TorSocks5Client(torSocks5EndPoint))
{

Refactor default constructors