Mock Trezor T wipe
MODIFY
WalletWasabi.Tests/HwiTests/DeviceConnectedTests/UserWorkflowTests.cs
WalletWasabi.Tests/HwiTests/DeviceConnectedTests/UserWorkflowTests.cs
@@ -28,8 +28,9 @@ namespace WalletWasabi.Tests.HwiTests.DeviceConnectedTests
//
// Connect a the device.
// Run this test.
- // First wipe request: confirm.
- // Second wipe request: pull out the device.
+ // Wipe request: confirm.
+ // Wipe request: confirm.
+ // Wipe request: pull out the device.
//
// --- USER INTERACTIONS ---
@@ -39,9 +40,17 @@ namespace WalletWasabi.Tests.HwiTests.DeviceConnectedTests
using (var cts = new CancellationTokenSource(ReasonableRequestTimeout))
{
var enumerate = await client.EnumerateAsync(cts.Token);
+ HwiEnumerateEntry entry = enumerate.Single();
+ devicePath = entry.Path;
+ deviceType = entry.Type.Value;
+
+ // User should confirm the device action here.
+ await client.WipeAsync(deviceType, devicePath, cts.Token);
+
+ enumerate = await client.EnumerateAsync(cts.Token);
Assert.Single(enumerate);
- HwiEnumerateEntry entry = enumerate.Single();
+ entry = enumerate.Single();
Assert.Equal(HardwareWalletVendors.Trezor, entry.Type);
Assert.NotNull(entry.Path);
Assert.NotEmpty(entry.Path);
@@ -51,9 +60,6 @@ namespace WalletWasabi.Tests.HwiTests.DeviceConnectedTests
Assert.NotEmpty(entry.Error);
Assert.Equal(HwiErrorCode.NotInitialized, entry.Code);
Assert.Null(entry.Fingerprint);
-
- devicePath = entry.Path;
- deviceType = entry.Type.Value;
}
using (var cts = new CancellationTokenSource(ReasonableRequestTimeout))

MODIFY
WalletWasabi.Tests/HwiTests/NoDeviceConnectedTests/IMockHwiProcessBridge.cs
WalletWasabi.Tests/HwiTests/NoDeviceConnectedTests/IMockHwiProcessBridge.cs
@@ -19,7 +19,7 @@ namespace WalletWasabi.Tests.HwiTests.NoDeviceConnectedTests
public Task<(string response, int exitCode)> SendCommandAsync(string arguments, CancellationToken cancel)
{
- if (arguments == "enumerate")
+ if (arguments == "enumerate" || arguments == "--testnet enumerate")
{
if (Model == HardwareWalletModels.TrezorT)
{
@@ -28,10 +28,17 @@ namespace WalletWasabi.Tests.HwiTests.NoDeviceConnectedTests
return Task.FromResult((response, code));
}
}
-
+ else if (arguments == "--device-path \"webusb: 001:4\" --device-type \"trezor\" wipe" || arguments == "--testnet --device-path \"webusb: 001:4\" --device-type \"trezor\" wipe")
{
- throw new NotImplementedException($"Mocking is not implemented for '{arguments}'");
+ if (Model == HardwareWalletModels.TrezorT)
+ {
+ var response = "{\"success\": true}\r\n";
+ var code = 0;
+ return Task.FromResult((response, code));
+ }
}
+
+ throw new NotImplementedException($"Mocking is not implemented for '{arguments}'");
}
}
}

MODIFY
WalletWasabi.Tests/HwiTests/NoDeviceConnectedTests/MockedDeviceTests.cs
WalletWasabi.Tests/HwiTests/NoDeviceConnectedTests/MockedDeviceTests.cs
@@ -22,10 +22,12 @@ namespace WalletWasabi.Tests.HwiTests.NoDeviceConnectedTests
#region Tests
- [Fact]
- public async Task CanEnumerateTestsAsync()
+ [Theory]
+ [MemberData(nameof(GetDifferentNetworkValues))]
+ public async Task TrezorTMockTestsAsync(Network network)
{
- var client = new HwiClient(Network.Main, new IMockHwiProcessBridge(HardwareWalletModels.TrezorT));
+ var client = new HwiClient(network, new IMockHwiProcessBridge(HardwareWalletModels.TrezorT));
+
using (var cts = new CancellationTokenSource(ReasonableRequestTimeout))
{
IEnumerable<HwiEnumerateEntry> enumerate = await client.EnumerateAsync(cts.Token);
@@ -39,9 +41,30 @@ namespace WalletWasabi.Tests.HwiTests.NoDeviceConnectedTests
Assert.NotEmpty(entry.Error);
Assert.Equal(HwiErrorCode.NotInitialized, entry.Code);
Assert.Null(entry.Fingerprint);
+
+ await client.WipeAsync(entry.Type.Value, entry.Path, cts.Token);
}
}
#endregion Tests
+
+ #region HelperMethods
+
+ public static IEnumerable<object[]> GetDifferentNetworkValues()
+ {
+ var networks = new List<Network>
+ {
+ Network.Main,
+ Network.TestNet,
+ Network.RegTest
+ };
+
+ foreach (Network network in networks)
+ {
+ yield return new object[] { network };
+ }
+ }
+
+ #endregion HelperMethods
}
}

MODIFY
WalletWasabi/Hwi2/Parsers/HwiParser.cs
WalletWasabi/Hwi2/Parsers/HwiParser.cs
@@ -254,7 +254,7 @@ namespace WalletWasabi.Hwi2.Parsers
if (network != Network.Main)
{
- fullOptions.Add(new HwiOption(HwiOptions.TestNet));
+ fullOptions.Insert(0, new HwiOption(HwiOptions.TestNet));
}
var optionsString = string.Join(" --", fullOptions.Select(x =>

Mock Trezor T wipe