From 179c53d97f530b8b381a84422d80c16a8ed939d4 Mon Sep 17 00:00:00 2001 From: Nodar Chkuaselidze Date: Sun, 18 Mar 2018 20:40:23 -0700 Subject: [PATCH] wdb: fix hasAccount --- lib/wallet/wallet.js | 2 +- test/wallet-test.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/wallet/wallet.js b/lib/wallet/wallet.js index 1d0cea24..065b8468 100644 --- a/lib/wallet/wallet.js +++ b/lib/wallet/wallet.js @@ -762,7 +762,7 @@ class Wallet extends EventEmitter { if (index === -1) return false; - return this.db.hasAccount(this.wid, index); + return this.wdb.hasAccount(this.wid, index); } /** diff --git a/test/wallet-test.js b/test/wallet-test.js index 818530b2..050ae3e0 100644 --- a/test/wallet-test.js +++ b/test/wallet-test.js @@ -804,6 +804,37 @@ describe('Wallet', function() { await testP2SH(true, true); }); + it('should create account', async () => { + const wallet = await wdb.create(); + const account = await wallet.createAccount({ + name: 'foo' + }); + + assert(account); + assert(account.initialized); + assert.strictEqual(account.name, 'foo'); + assert.strictEqual(account.accountIndex, 1); + assert.strictEqual(account.m, 1); + assert.strictEqual(account.n, 1); + }); + + it('should fail to create duplicate account', async () => { + const wallet = await wdb.create(); + const name = 'foo'; + + await wallet.createAccount({ name }); + + let err; + try { + await wallet.createAccount({ name }); + } catch (e) { + err = e; + } + + assert(err); + assert.strictEqual(err.message, 'Account already exists.'); + }); + it('should fill tx with account 1', async () => { const alice = await wdb.create(); const bob = await wdb.create();