@@ -18,14 +18,17 @@ const Input = require('../lib/primitives/input');
18
18
const Outpoint = require ( '../lib/primitives/outpoint' ) ;
19
19
const Script = require ( '../lib/script/script' ) ;
20
20
const HD = require ( '../lib/hd' ) ;
21
- const PrivateKey = require ( '../lib/hd/private' ) ;
22
21
23
22
const KEY1 = 'xprv9s21ZrQH143K3Aj6xQBymM31Zb4BVc7wxqfUhMZrzewdDVCt'
24
23
+ 'qUP9iWfcHgJofs25xbaUpCps9GDXj83NiWvQCAkWQhVj5J4CorfnpKX94AZ' ;
25
24
26
25
const KEY2 = 'xprv9s21ZrQH143K3mqiSThzPtWAabQ22Pjp3uSNnZ53A5bQ4udp'
27
26
+ 'faKekc2m4AChLYH1XDzANhrSdxHYWUeTWjYJwFwWFyHkTMnMeAcW4JyRCZa' ;
28
27
28
+ // abandon abandon... about key at m'/44'/0'/0'
29
+ const PUBKEY = 'xpub6BosfCnifzxcFwrSzQiqu2DBVTshkCXacvNsWGYJVVhhaw'
30
+ + 'A7d4R5WSWGFNbi8Aw6ZRc1brxMyWMzG3DSSSSoekkudhUd9yLb6qx39T9nMdj' ;
31
+
29
32
const enabled = true ;
30
33
const workers = new WorkerPool ( { enabled } ) ;
31
34
const wdb = new WalletDB ( { workers } ) ;
@@ -35,7 +38,6 @@ let importedWallet = null;
35
38
let importedKey = null ;
36
39
let doubleSpendWallet = null ;
37
40
let doubleSpendCoin = null ;
38
- let watchWallet = null ;
39
41
40
42
function fromU32 ( num ) {
41
43
const data = Buffer . allocUnsafe ( 4 ) ;
@@ -1304,48 +1306,56 @@ describe('Wallet', function() {
1304
1306
} ) ;
1305
1307
1306
1308
it ( 'should require account key to create watch only wallet' , async ( ) => {
1309
+ let err = null ;
1310
+
1307
1311
try {
1308
- watchWallet = await wdb . create ( {
1312
+ await wdb . create ( {
1309
1313
watchOnly : true
1310
1314
} ) ;
1311
1315
} catch ( e ) {
1312
- assert . strictEqual (
1313
- e . message ,
1314
- 'Must add HD public keys to watch only wallet.'
1315
- ) ;
1316
+ err = e ;
1316
1317
}
1317
1318
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
+ ) ;
1324
1324
} ) ;
1325
1325
1326
1326
it ( 'should import pubkey' , async ( ) => {
1327
1327
const key = KeyRing . generate ( ) ;
1328
1328
const pub = new KeyRing ( key . publicKey ) ;
1329
1329
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 ) ;
1331
1336
1332
- const path = await watchWallet . getPath ( pub . getHash ( ) ) ;
1337
+ const path = await wallet . getPath ( pub . getHash ( ) ) ;
1333
1338
assert . bufferEqual ( path . hash , pub . getHash ( ) ) ;
1334
1339
1335
- const wkey = await watchWallet . getKey ( pub . getHash ( ) ) ;
1340
+ const wkey = await wallet . getKey ( pub . getHash ( ) ) ;
1336
1341
assert ( wkey ) ;
1337
1342
} ) ;
1338
1343
1339
1344
it ( 'should import address' , async ( ) => {
1340
1345
const key = KeyRing . generate ( ) ;
1341
1346
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 ( ) ) ;
1343
1353
1344
- const path = await watchWallet . getPath ( key . getHash ( ) ) ;
1354
+ const path = await wallet . getPath ( key . getHash ( ) ) ;
1345
1355
assert ( path ) ;
1346
1356
assert . bufferEqual ( path . hash , key . getHash ( ) ) ;
1347
1357
1348
- const wkey = await watchWallet . getKey ( key . getHash ( ) ) ;
1358
+ const wkey = await wallet . getKey ( key . getHash ( ) ) ;
1349
1359
assert ( ! wkey ) ;
1350
1360
} ) ;
1351
1361
0 commit comments