From 43d9ffadeffadfaa39b3df87beb800103f5c1ed5 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Mon, 11 Feb 2019 13:30:40 -0800 Subject: [PATCH] test: independent watch-only tests and assert error --- test/wallet-test.js | 48 +++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/test/wallet-test.js b/test/wallet-test.js index 1f532e189..cddd9bf18 100644 --- a/test/wallet-test.js +++ b/test/wallet-test.js @@ -18,7 +18,6 @@ const Input = require('../lib/primitives/input'); const Outpoint = require('../lib/primitives/outpoint'); const Script = require('../lib/script/script'); const HD = require('../lib/hd'); -const PrivateKey = require('../lib/hd/private'); const KEY1 = 'xprv9s21ZrQH143K3Aj6xQBymM31Zb4BVc7wxqfUhMZrzewdDVCt' + 'qUP9iWfcHgJofs25xbaUpCps9GDXj83NiWvQCAkWQhVj5J4CorfnpKX94AZ'; @@ -26,6 +25,10 @@ const KEY1 = 'xprv9s21ZrQH143K3Aj6xQBymM31Zb4BVc7wxqfUhMZrzewdDVCt' const KEY2 = 'xprv9s21ZrQH143K3mqiSThzPtWAabQ22Pjp3uSNnZ53A5bQ4udp' + 'faKekc2m4AChLYH1XDzANhrSdxHYWUeTWjYJwFwWFyHkTMnMeAcW4JyRCZa'; +// abandon abandon... about key at m'/44'/0'/0' +const PUBKEY = 'xpub6BosfCnifzxcFwrSzQiqu2DBVTshkCXacvNsWGYJVVhhaw' + + 'A7d4R5WSWGFNbi8Aw6ZRc1brxMyWMzG3DSSSSoekkudhUd9yLb6qx39T9nMdj'; + const enabled = true; const workers = new WorkerPool({ enabled }); const wdb = new WalletDB({ workers }); @@ -35,7 +38,6 @@ let importedWallet = null; let importedKey = null; let doubleSpendWallet = null; let doubleSpendCoin = null; -let watchWallet = null; function fromU32(num) { const data = Buffer.allocUnsafe(4); @@ -1304,48 +1306,56 @@ describe('Wallet', function() { }); it('should require account key to create watch only wallet', async () => { + let err = null; + try { - watchWallet = await wdb.create({ + await wdb.create({ watchOnly: true }); } catch (e) { - assert.strictEqual( - e.message, - 'Must add HD public keys to watch only wallet.' - ); + err = e; } - const privateKey = PrivateKey.generate(); - const xpub = privateKey.xpubkey('main'); - watchWallet = await wdb.create({ - watchOnly: true, - accountKey: xpub - }); + assert(err); + assert.strictEqual( + err.message, + 'Must add HD public keys to watch only wallet.' + ); }); it('should import pubkey', async () => { const key = KeyRing.generate(); const pub = new KeyRing(key.publicKey); - await watchWallet.importKey('default', pub); + const wallet = await wdb.create({ + watchOnly: true, + accountKey: PUBKEY + }); + + await wallet.importKey('default', pub); - const path = await watchWallet.getPath(pub.getHash()); + const path = await wallet.getPath(pub.getHash()); assert.bufferEqual(path.hash, pub.getHash()); - const wkey = await watchWallet.getKey(pub.getHash()); + const wkey = await wallet.getKey(pub.getHash()); assert(wkey); }); it('should import address', async () => { const key = KeyRing.generate(); - await watchWallet.importAddress('default', key.getAddress()); + const wallet = await wdb.create({ + watchOnly: true, + accountKey: PUBKEY + }); + + await wallet.importAddress('default', key.getAddress()); - const path = await watchWallet.getPath(key.getHash()); + const path = await wallet.getPath(key.getHash()); assert(path); assert.bufferEqual(path.hash, key.getHash()); - const wkey = await watchWallet.getKey(key.getHash()); + const wkey = await wallet.getKey(key.getHash()); assert(!wkey); });