Skip to content

Commit 3d31e1f

Browse files
Merge pull request #8107 from BitGo/BTC-2650.port-impl-btc-to-wasm-utxo
feat(abstract-utxo): replace utxo-lib with wasm-utxo in tests
2 parents 7b1dc9f + 2b6aa37 commit 3d31e1f

16 files changed

Lines changed: 301 additions & 357 deletions

modules/abstract-utxo/test/unit/impl/btc/unit/btc.ts

Lines changed: 0 additions & 260 deletions
This file was deleted.

modules/abstract-utxo/test/unit/impl/btc/unit/fixtures/btcBackupKey.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

modules/abstract-utxo/test/unit/impl/btc/unit/fixtures/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

modules/abstract-utxo/test/unit/impl/ltc/unit/index.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

modules/abstract-utxo/test/unit/keychains.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import * as assert from 'assert';
22

33
import 'should';
4+
import { type TestBitGoAPI, TestBitGo } from '@bitgo/sdk-test';
5+
import { BitGoAPI } from '@bitgo/sdk-api';
6+
47
import { AbstractUtxoCoin } from '../../src';
8+
import { Tbtc } from '../../src/impl/btc';
59

610
import { utxoCoins } from './util';
711

@@ -16,3 +20,54 @@ function run(coin: AbstractUtxoCoin) {
1620
}
1721

1822
utxoCoins.forEach((c) => run(c));
23+
24+
describe('Audit Key', function () {
25+
// Encrypted backup key fixture for testing assertIsValidKey
26+
const btcBackupKey = {
27+
key:
28+
'{"iv":"JgqqE4W45/tKBSMSYqD+qg==","v":1,"iter":10000,"ks":256,"ts":64,"mode"' +
29+
':"ccm","adata":"","cipher":"aes","salt":"kiLPf8VSdI0=","ct":"zUh4Oko/06g02E' +
30+
'wnqOfzJbTwtE2p3b19jDk8Tum07Jv3N/RP7Bo0w/ObLBO1uIJFossO3nJ1JS+7t/vPQhdCtN8oD' +
31+
'6YrZnEZYrRwN6JQkL1uYPnZ1PoWbYI9navK5CLU1KQwDTO9YEN46++OrzFH+CjpQVLblaw="}',
32+
};
33+
34+
let bitgo: TestBitGoAPI;
35+
let coin: Tbtc;
36+
37+
before(function () {
38+
bitgo = TestBitGo.decorate(BitGoAPI, { env: 'test' });
39+
bitgo.safeRegister('tbtc', Tbtc.createInstance);
40+
bitgo.initializeTestVars();
41+
coin = bitgo.coin('tbtc') as Tbtc;
42+
});
43+
44+
it('should return for valid inputs', function () {
45+
coin.assertIsValidKey({
46+
encryptedPrv: btcBackupKey.key,
47+
walletPassphrase: 'kAm[EFQ6o=SxlcLFDw%,',
48+
});
49+
});
50+
51+
it('should throw error if the walletPassphrase is incorrect', function () {
52+
assert.throws(
53+
() =>
54+
coin.assertIsValidKey({
55+
encryptedPrv: btcBackupKey.key,
56+
walletPassphrase: 'foo',
57+
}),
58+
{ message: "failed to decrypt prv: ccm: tag doesn't match" }
59+
);
60+
});
61+
62+
it('should throw if the key is altered', function () {
63+
const alteredKey = btcBackupKey.key.replace(/[0-9]/g, '0');
64+
assert.throws(
65+
() =>
66+
coin.assertIsValidKey({
67+
encryptedPrv: alteredKey,
68+
walletPassphrase: 'kAm[EFQ6o=SxlcLFDw%,',
69+
}),
70+
{ message: 'failed to decrypt prv: json decrypt: invalid parameters' }
71+
);
72+
});
73+
});

0 commit comments

Comments
 (0)