Skip to content

Commit

Permalink
Merge pull request GingerPrivacy#17 from drkgry/sync_wallet_3
Browse files Browse the repository at this point in the history
Sync wallet 3
  • Loading branch information
drkgry authored Oct 3, 2024
2 parents a4f936f + 32d8eb7 commit a34ec8c
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 37 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/UnitTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ on:
pull_request:
branches:
- master
push:
branches:
- master

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]


steps:
- name: Checkout code
Expand All @@ -27,10 +32,4 @@ jobs:

- name: Test
run: dotnet test --no-restore --configuration Release --filter "UnitTests" --logger "console;verbosity=detailed"
continue-on-error: true

- name: Check test results
if: failure()
run: |
echo "Tests failed on ${{ matrix.os }}"
exit 1

2 changes: 2 additions & 0 deletions WalletWasabi.Documentation/WasabiCompatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ This document lists all the officially supported software and devices by Wasabi
- ColdCard MK2
- ColdCard MK3
- ColdCard MK4
- ColdCard Q
- Ledger Nano S
- Ledger Nano S Plus
- Ledger Nano X
- Trezor Model T
- Trezor Safe 3
- Trezor Safe 5

<sup><sup>1*</sup> The device by default asks for a "Pairing code", currently, there is no such function in Wasabi. Therefore, either disable the feature or unlock the device with BitBoxApp or hwi-qt before using it with Wasabi.</sup>

Expand Down
72 changes: 72 additions & 0 deletions WalletWasabi.Tests/AcceptanceTests/HwiKatas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,78 @@ public async Task TrezorSafe3KataAsync()
Assert.Equal(TransactionCheckResult.Success, checkResult);
}

[Fact]
public async Task TrezorSafe5KataAsync()
{
// --- USER INTERACTIONS ---
//
// Connect and initialize your Trezor Safe 5 with the following seed phrase:
// more maid moon upgrade layer alter marine screen benefit way cover alcohol
// NEVER STORE REAL MONEY ON THIS WALLET. IT IS NOT SAFE.
// Run this test.
// displayaddress request: swipe up 1 time and confirm
// displayaddress request: swipe up 1 time and confirm
// signtx request: select cancel 1 time and tap
// signtx request: swipe up 1 time and hold confirm
//
// --- USER INTERACTIONS ---

var network = Network.Main;
var client = new HwiClient(network);
using var cts = new CancellationTokenSource(ReasonableRequestTimeout);
var enumerate = await client.EnumerateAsync(cts.Token);
Assert.Single(enumerate);
HwiEnumerateEntry entry = enumerate.Single();
Assert.NotNull(entry.Path);
Assert.True(HwiValidationHelper.ValidatePathString(entry.Model, entry.Path));
Assert.Equal(HardwareWalletModels.Trezor_Safe_5, entry.Model);
Assert.NotNull(entry.Fingerprint);

string devicePath = entry.Path;
HardwareWalletModels deviceType = entry.Model;
HDFingerprint fingerprint = entry.Fingerprint!.Value;

await Assert.ThrowsAsync<HwiException>(async () => await client.SetupAsync(deviceType, devicePath, false, cts.Token));

await Assert.ThrowsAsync<HwiException>(async () => await client.RestoreAsync(deviceType, devicePath, false, cts.Token));

await Assert.ThrowsAsync<HwiException>(async () => await client.PromptPinAsync(deviceType, devicePath, cts.Token));
await Assert.ThrowsAsync<HwiException>(async () => await client.SendPinAsync(deviceType, devicePath, 1111, cts.Token));

KeyPath keyPath1 = new("m/84h/0h/0h/0/0");
KeyPath keyPath2 = new("m/84h/0h/0h/0/1");
ExtPubKey xpub1 = await client.GetXpubAsync(deviceType, devicePath, keyPath1, cts.Token);
ExtPubKey xpub2 = await client.GetXpubAsync(deviceType, devicePath, keyPath2, cts.Token);
Assert.NotNull(xpub1);
Assert.NotNull(xpub2);
Assert.NotEqual(xpub1, xpub2);

// USER: CONFIRM
BitcoinWitPubKeyAddress address1 = await client.DisplayAddressAsync(deviceType, devicePath, keyPath1, cts.Token);
// USER: CONFIRM
BitcoinWitPubKeyAddress address2 = await client.DisplayAddressAsync(fingerprint, keyPath2, cts.Token);
Assert.NotNull(address1);
Assert.NotNull(address2);
Assert.NotEqual(address1, address2);
var expectedAddress1 = xpub1.PubKey.GetAddress(ScriptPubKeyType.Segwit, network);
var expectedAddress2 = xpub2.PubKey.GetAddress(ScriptPubKeyType.Segwit, network);
Assert.Equal(expectedAddress1, address1);
Assert.Equal(expectedAddress2, address2);

// USER SHOULD REFUSE ACTION
var result = await Assert.ThrowsAsync<HwiException>(async () => await client.SignTxAsync(deviceType, devicePath, Psbt, cts.Token));
Assert.Equal(HwiErrorCode.ActionCanceled, result.ErrorCode);

// USER: Hold to confirm
PSBT signedPsbt = await client.SignTxAsync(deviceType, devicePath, Psbt, cts.Token);

Transaction signedTx = signedPsbt.GetOriginalTransaction();
Assert.Equal(Psbt.GetOriginalTransaction().GetHash(), signedTx.GetHash());

var checkResult = signedTx.Check();
Assert.Equal(TransactionCheckResult.Success, checkResult);
}

[Fact]
public async Task TrezorOneKataAsync()
{
Expand Down
1 change: 1 addition & 0 deletions WalletWasabi.Tests/Helpers/WabiSabiFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ public static CoinJoinClient CreateTestCoinJoinClient(
coinSelector,
new CoinJoinConfiguration("CoinJoinCoordinatorIdentifier", 0.3m, 150.0m, 1, AllowSoloCoinjoining: true),
new LiquidityClueProvider(),
0,
TimeSpan.Zero,
TimeSpan.Zero,
null);
Expand Down
43 changes: 23 additions & 20 deletions WalletWasabi.Tests/UnitTests/BitcoinCore/CoreConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ public void RemovesEmptyDuplications()

var config = new CoreConfig();
config.AddOrUpdate(configStringBuilder.ToString());
var expectedConfig =
var expectedConfig = EnsureNewLine(
"""
foo = bar
bar = bar
""";
""");
Assert.Equal(expectedConfig, config.ToString());
}

[Fact]
public void CanParse()
{
var testConfig =
var testConfig = EnsureNewLine(
"""
foo=buz
foo = bar
""";
""");

testConfig += Environment.NewLine;
testConfig += Environment.NewLine;
testConfig += Environment.NewLine;
testConfig +=
testConfig += EnsureNewLine(
"""
foo = bar
foo bar = buz quxx
Expand All @@ -48,11 +48,11 @@ public void CanParse()
foo
bar
#qoo=boo
""";
""");
var coreConfig = new CoreConfig();
coreConfig.AddOrUpdate(testConfig);

var expectedConfig =
var expectedConfig = EnsureNewLine(
"""
foo = bar
Expand All @@ -63,7 +63,7 @@ public void CanParse()
bar
#qoo=boo
""";
""");

Assert.Equal(expectedConfig, coreConfig.ToString());

Expand Down Expand Up @@ -122,7 +122,7 @@ public void CanParse()
Assert.Equal("bar", fooValue);
Assert.Equal("0", tooValue);

expectedConfig =
expectedConfig = EnsureNewLine(
"""
foo = bar
Expand All @@ -134,11 +134,11 @@ public void CanParse()
moo = 1
too = 0
""";
""");

Assert.Equal(expectedConfig, coreConfig.ToString());

var expectedConfig2 =
var expectedConfig2 = EnsureNewLine(
"""
foo = bar
Expand All @@ -150,27 +150,27 @@ public void CanParse()
moo = 1
too = 0
""";
""");
Assert.Equal(expectedConfig2, coreConfig2.ToString());
}

[Fact]
public void KeepsOrder()
{
var testConfig =
var testConfig = EnsureNewLine(
"""
foo=bar
buz=qux
""";
""");
var coreConfig = new CoreConfig();
coreConfig.AddOrUpdate(testConfig);

var expectedConfig =
var expectedConfig = EnsureNewLine(
"""
foo = bar
buz = qux
""";
""");

Assert.Equal(expectedConfig, coreConfig.ToString());

Expand All @@ -183,7 +183,7 @@ public void KeepsOrder()
[Fact]
public void HandlesSections()
{
var testConfig =
var testConfig = EnsureNewLine(
"""
qux=1
[main]
Expand All @@ -198,11 +198,11 @@ public void HandlesSections()
[main]
buz=1
test.buz=2
""";
""");
var coreConfig = new CoreConfig();
coreConfig.AddOrUpdate(testConfig);

var expectedConfig =
var expectedConfig = EnsureNewLine(
"""
qux = 1
main.foo = 1
Expand All @@ -214,8 +214,11 @@ public void HandlesSections()
main.buz = 1
test.buz = 2
""";
""");

Assert.Equal(expectedConfig, coreConfig.ToString());
}

// Depending on the source the new lines in """...""" block might be a simple '\n' regardless of the OS
public string EnsureNewLine(string text) => text.Replace("\r\n", "\n").Replace("\n", Environment.NewLine);
}
Loading

0 comments on commit a34ec8c

Please sign in to comment.