Add RestoreAsync
MODIFY
WalletWasabi.Tests/HwiTests/DeviceConnectedTests/Katas.cs
WalletWasabi.Tests/HwiTests/DeviceConnectedTests/Katas.cs
@@ -16,6 +16,7 @@ namespace WalletWasabi.Tests.HwiTests.DeviceConnectedTests
/// Kata tests are intended to be run one by one.
/// A kata is a type of test that requires user interaction.
/// User interaction shall be defined in the beginning of the each kata.
+ /// Only write katas those require button push responses (eg. don't call setup on trezor.)
/// </summary>
public class Katas
{
@@ -31,13 +32,10 @@ namespace WalletWasabi.Tests.HwiTests.DeviceConnectedTests
{
// --- USER INTERACTIONS ---
//
- // Connect a the device and unlock if it's not wiped.
+ // Connect an already initialized device and unlock it.
// Run this test.
- // Wipe request: confirm.
- // Wipe request: confirm.
// Setup request: refuse.
- // Setup request: confirm and setup.
- // Wipe request: confirm.
+ // Restore request: refuse.
//
// --- USER INTERACTIONS ---
@@ -50,36 +48,12 @@ namespace WalletWasabi.Tests.HwiTests.DeviceConnectedTests
string devicePath = entry.Path;
HardwareWalletVendors 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);
- entry = enumerate.Single();
- Assert.Equal(HardwareWalletVendors.Trezor, entry.Type);
- Assert.NotNull(entry.Path);
- Assert.NotEmpty(entry.Path);
- Assert.False(entry.NeedsPassphraseSent);
- Assert.False(entry.NeedsPinSent);
- Assert.NotNull(entry.Error);
- Assert.NotEmpty(entry.Error);
- Assert.Equal(HwiErrorCode.DeviceNotInitialized, entry.Code);
- Assert.Null(entry.Fingerprint);
-
- // User should confirm the device action here.
- await client.WipeAsync(deviceType, devicePath, cts.Token);
-
- // User should refuse the device action here.
+ // USER: REFUSE
await Assert.ThrowsAsync<HwiException>(async () => await client.SetupAsync(deviceType, devicePath, cts.Token));
- // User should confirm the device action and setup a new device here.
- await client.SetupAsync(deviceType, devicePath, cts.Token);
-
- // User should confirm the device action here.
- await client.WipeAsync(deviceType, devicePath, cts.Token);
+ // USER: REFUSE
+ await Assert.ThrowsAsync<HwiException>(async () => await client.RestoreAsync(deviceType, devicePath, cts.Token));
- // ToDo: Restore
// ToDo: Backup
// ToDo: getxpub
// ToDo: displayaddress

MODIFY
WalletWasabi.Tests/HwiTests/NoDeviceConnectedTests/IMockHwiProcessBridge.cs
WalletWasabi.Tests/HwiTests/NoDeviceConnectedTests/IMockHwiProcessBridge.cs
@@ -55,6 +55,15 @@ namespace WalletWasabi.Tests.HwiTests.NoDeviceConnectedTests
return Task.FromResult((response, code));
}
}
+ else if (arguments == "--device-path \"webusb: 001:4\" --device-type \"trezor\" --interactive restore" || arguments == "--testnet --device-path \"webusb: 001:4\" --device-type \"trezor\" --interactive restore")
+ {
+ 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
@@ -43,9 +43,11 @@ namespace WalletWasabi.Tests.HwiTests.NoDeviceConnectedTests
Assert.Null(entry.Fingerprint);
var deviceType = entry.Type.Value;
+ var devicePath = entry.Path;
- await client.WipeAsync(deviceType, entry.Path, cts.Token);
- await client.SetupAsync(deviceType, entry.Path, cts.Token);
+ await client.WipeAsync(deviceType, devicePath, cts.Token);
+ await client.SetupAsync(deviceType, devicePath, cts.Token);
+ await client.RestoreAsync(deviceType, devicePath, cts.Token);
}
}

MODIFY
WalletWasabi/Hwi2/HwiClient.cs
WalletWasabi/Hwi2/HwiClient.cs
@@ -87,6 +87,14 @@ namespace WalletWasabi.Hwi2
cancel).ConfigureAwait(false);
}
+ public async Task RestoreAsync(HardwareWalletVendors deviceType, string devicePath, CancellationToken cancel)
+ {
+ await SendCommandAsync(
+ options: new[] { HwiOption.DevicePath(devicePath), HwiOption.DeviceType(deviceType), HwiOption.Interactive },
+ command: HwiCommands.Restore,
+ cancel).ConfigureAwait(false);
+ }
+
public async Task<Version> GetVersionAsync(CancellationToken cancel)
{
string responseString = await SendCommandAsync(options: new[] { HwiOption.Version }, command: null, cancel).ConfigureAwait(false);

Add RestoreAsync