Skip to content

Commit 43d9ffa

Browse files
braydonfpinheadmz
authored andcommitted
test: independent watch-only tests and assert error
1 parent 4c45e2a commit 43d9ffa

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

test/wallet-test.js

+29-19
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ const Input = require('../lib/primitives/input');
1818
const Outpoint = require('../lib/primitives/outpoint');
1919
const Script = require('../lib/script/script');
2020
const HD = require('../lib/hd');
21-
const PrivateKey = require('../lib/hd/private');
2221

2322
const KEY1 = 'xprv9s21ZrQH143K3Aj6xQBymM31Zb4BVc7wxqfUhMZrzewdDVCt'
2423
+ 'qUP9iWfcHgJofs25xbaUpCps9GDXj83NiWvQCAkWQhVj5J4CorfnpKX94AZ';
2524

2625
const KEY2 = 'xprv9s21ZrQH143K3mqiSThzPtWAabQ22Pjp3uSNnZ53A5bQ4udp'
2726
+ 'faKekc2m4AChLYH1XDzANhrSdxHYWUeTWjYJwFwWFyHkTMnMeAcW4JyRCZa';
2827

28+
// abandon abandon... about key at m'/44'/0'/0'
29+
const PUBKEY = 'xpub6BosfCnifzxcFwrSzQiqu2DBVTshkCXacvNsWGYJVVhhaw'
30+
+ 'A7d4R5WSWGFNbi8Aw6ZRc1brxMyWMzG3DSSSSoekkudhUd9yLb6qx39T9nMdj';
31+
2932
const enabled = true;
3033
const workers = new WorkerPool({ enabled });
3134
const wdb = new WalletDB({ workers });
@@ -35,7 +38,6 @@ let importedWallet = null;
3538
let importedKey = null;
3639
let doubleSpendWallet = null;
3740
let doubleSpendCoin = null;
38-
let watchWallet = null;
3941

4042
function fromU32(num) {
4143
const data = Buffer.allocUnsafe(4);
@@ -1304,48 +1306,56 @@ describe('Wallet', function() {
13041306
});
13051307

13061308
it('should require account key to create watch only wallet', async () => {
1309+
let err = null;
1310+
13071311
try {
1308-
watchWallet = await wdb.create({
1312+
await wdb.create({
13091313
watchOnly: true
13101314
});
13111315
} catch (e) {
1312-
assert.strictEqual(
1313-
e.message,
1314-
'Must add HD public keys to watch only wallet.'
1315-
);
1316+
err = e;
13161317
}
13171318

1318-
const privateKey = PrivateKey.generate();
1319-
const xpub = privateKey.xpubkey('main');
1320-
watchWallet = await wdb.create({
1321-
watchOnly: true,
1322-
accountKey: xpub
1323-
});
1319+
assert(err);
1320+
assert.strictEqual(
1321+
err.message,
1322+
'Must add HD public keys to watch only wallet.'
1323+
);
13241324
});
13251325

13261326
it('should import pubkey', async () => {
13271327
const key = KeyRing.generate();
13281328
const pub = new KeyRing(key.publicKey);
13291329

1330-
await watchWallet.importKey('default', pub);
1330+
const wallet = await wdb.create({
1331+
watchOnly: true,
1332+
accountKey: PUBKEY
1333+
});
1334+
1335+
await wallet.importKey('default', pub);
13311336

1332-
const path = await watchWallet.getPath(pub.getHash());
1337+
const path = await wallet.getPath(pub.getHash());
13331338
assert.bufferEqual(path.hash, pub.getHash());
13341339

1335-
const wkey = await watchWallet.getKey(pub.getHash());
1340+
const wkey = await wallet.getKey(pub.getHash());
13361341
assert(wkey);
13371342
});
13381343

13391344
it('should import address', async () => {
13401345
const key = KeyRing.generate();
13411346

1342-
await watchWallet.importAddress('default', key.getAddress());
1347+
const wallet = await wdb.create({
1348+
watchOnly: true,
1349+
accountKey: PUBKEY
1350+
});
1351+
1352+
await wallet.importAddress('default', key.getAddress());
13431353

1344-
const path = await watchWallet.getPath(key.getHash());
1354+
const path = await wallet.getPath(key.getHash());
13451355
assert(path);
13461356
assert.bufferEqual(path.hash, key.getHash());
13471357

1348-
const wkey = await watchWallet.getKey(key.getHash());
1358+
const wkey = await wallet.getKey(key.getHash());
13491359
assert(!wkey);
13501360
});
13511361

0 commit comments

Comments
 (0)