From 42da82e00768487d3a51c8e3e5f085a06dd3a536 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 14 Mar 2017 06:28:55 -0700 Subject: [PATCH] wallet: fix tests and add compat routes. --- lib/wallet/http.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ test/http-test.js | 7 +++---- test/node-test.js | 7 +++---- 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/lib/wallet/http.js b/lib/wallet/http.js index 8aeeea74..baebf223 100644 --- a/lib/wallet/http.js +++ b/lib/wallet/http.js @@ -202,6 +202,26 @@ HTTPServer.prototype.initRouter = function initRouter() { res.send(200, req.wallet.master.toJSON(true)); }); + // Create wallet (compat) + this.post('/', co(function* (req, res) { + var valid = req.valid(); + var wallet; + + wallet = yield this.walletdb.create({ + id: valid.str('id'), + type: valid.str('type'), + m: valid.u32('m'), + n: valid.u32('n'), + passphrase: valid.str('passphrase'), + master: valid.str('master'), + mnemonic: valid.str('mnemonic'), + accountKey: valid.str('accountKey'), + watchOnly: valid.bool('watchOnly') + }); + + res.send(200, wallet.toJSON()); + })); + // Create wallet this.put('/:id', co(function* (req, res) { var valid = req.valid(); @@ -242,6 +262,32 @@ HTTPServer.prototype.initRouter = function initRouter() { res.send(200, account.toJSON()); })); + // Create account (compat) + this.post('/:id/account', co(function* (req, res) { + var valid = req.valid(); + var passphrase = valid.str('passphrase'); + var options, account; + + options = { + name: valid.str(['account', 'name']), + witness: valid.bool('witness'), + watchOnly: valid.bool('watchOnly'), + type: valid.str('type'), + m: valid.u32('m'), + n: valid.u32('n'), + lookahead: valid.u32('lookahead') + }; + + account = yield req.wallet.createAccount(options, passphrase); + + if (!account) { + res.send(404); + return; + } + + res.send(200, account.toJSON()); + })); + // Create account this.put('/:id/account/:account', co(function* (req, res) { var valid = req.valid(); diff --git a/test/http-test.js b/test/http-test.js index eb16a4ce..4965c6aa 100644 --- a/test/http-test.js +++ b/test/http-test.js @@ -11,6 +11,7 @@ var MTX = require('../lib/primitives/mtx'); var HTTP = require('../lib/http'); var FullNode = require('../lib/node/fullnode'); var pkg = require('../lib/pkg'); +var plugin = require('../lib/wallet/plugin'); describe('HTTP', function() { var node, wallet, walletdb, addr, hash; @@ -19,9 +20,7 @@ describe('HTTP', function() { network: 'regtest', apiKey: 'foo', walletAuth: true, - db: 'memory', - loader: require, - plugins: ['walletdb'] + db: 'memory' }); wallet = new HTTP.Wallet({ @@ -29,7 +28,7 @@ describe('HTTP', function() { apiKey: 'foo' }); - walletdb = node.require('walletdb'); + walletdb = node.use(plugin); node.on('error', function() {}); diff --git a/test/node-test.js b/test/node-test.js index 3f34e083..883c6c47 100644 --- a/test/node-test.js +++ b/test/node-test.js @@ -8,17 +8,16 @@ var Coin = require('../lib/primitives/coin'); var Script = require('../lib/script/script'); var FullNode = require('../lib/node/fullnode'); var MTX = require('../lib/primitives/mtx'); +var plugin = require('../lib/wallet/plugin'); describe('Node', function() { var node = new FullNode({ db: 'memory', apiKey: 'foo', - network: 'regtest', - loader: require, - plugins: ['../lib/wallet/plugin'] + network: 'regtest' }); var chain = node.chain; - var walletdb = node.require('walletdb'); + var walletdb = node.use(plugin); var miner = node.miner; var wallet, tip1, tip2, cb1, cb2, mineBlock;