http: more tests.

This commit is contained in:
Christopher Jeffrey 2017-03-15 20:26:43 -07:00
parent 0d844be588
commit c0e4c169ba
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
6 changed files with 37 additions and 19 deletions

View File

@ -105,7 +105,8 @@ CLI.prototype.getAccount = co(function* getAccount() {
}); });
CLI.prototype.createAccount = co(function* createAccount() { CLI.prototype.createAccount = co(function* createAccount() {
var options = { name: this.config.str(0) }; var name = this.config.str(0);
var options = {};
var account; var account;
options.type = this.config.str('type'); options.type = this.config.str('type');
@ -114,7 +115,7 @@ CLI.prototype.createAccount = co(function* createAccount() {
options.witness = this.config.bool('witness'); options.witness = this.config.bool('witness');
options.accountKey = this.config.str('watch'); options.accountKey = this.config.str('watch');
account = yield this.wallet.createAccount(options); account = yield this.wallet.createAccount(name, options);
this.log(account); this.log(account);
}); });

View File

@ -927,7 +927,7 @@ HTTPClient.prototype.getMaster = function getMaster(id) {
* Get wallet account. * Get wallet account.
* @param {WalletID} id * @param {WalletID} id
* @param {String} account * @param {String} account
* @returns {Promise} - Returns Array. * @returns {Promise}
*/ */
HTTPClient.prototype.getAccount = function getAccount(id, account) { HTTPClient.prototype.getAccount = function getAccount(id, account) {
@ -938,22 +938,14 @@ HTTPClient.prototype.getAccount = function getAccount(id, account) {
/** /**
* Create account. * Create account.
* @param {WalletID} id * @param {WalletID} id
* @param {String} name
* @param {Object} options * @param {Object} options
* @returns {Promise} - Returns Array. * @returns {Promise}
*/ */
HTTPClient.prototype.createAccount = function createAccount(id, options) { HTTPClient.prototype.createAccount = function createAccount(id, name, options) {
var path; var path = '/wallet/' + id + '/account/' + name;
return this._put(path, options || {});
if (!options)
options = {};
if (typeof options === 'string')
options = { account: options };
path = '/wallet/' + id + '/account' + options.account;
return this._put(path, options);
}; };
/** /**

View File

@ -310,8 +310,8 @@ HTTPWallet.prototype.getAccount = function getAccount(account) {
* @see Wallet#createAccount * @see Wallet#createAccount
*/ */
HTTPWallet.prototype.createAccount = function createAccount(options) { HTTPWallet.prototype.createAccount = function createAccount(name, options) {
return this.client.createAccount(this.id, options); return this.client.createAccount(this.id, name, options);
}; };
/** /**

View File

@ -17,7 +17,6 @@ var workerPool = require('../workers/workerpool').pool;
var ec = require('../crypto/ec'); var ec = require('../crypto/ec');
var native = require('../utils/native'); var native = require('../utils/native');
var Config = require('./config'); var Config = require('./config');
var SigCache = require('../script/sigcache');
/** /**
* Base class from which every other * Base class from which every other

View File

@ -275,6 +275,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
type: valid.str('type'), type: valid.str('type'),
m: valid.u32('m'), m: valid.u32('m'),
n: valid.u32('n'), n: valid.u32('n'),
accountKey: valid.str('accountKey'),
lookahead: valid.u32('lookahead') lookahead: valid.u32('lookahead')
}; };
@ -301,6 +302,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
type: valid.str('type'), type: valid.str('type'),
m: valid.u32('m'), m: valid.u32('m'),
n: valid.u32('n'), n: valid.u32('n'),
accountKey: valid.str('accountKey'),
lookahead: valid.u32('lookahead') lookahead: valid.u32('lookahead')
}; };

View File

@ -154,6 +154,30 @@ describe('HTTP', function() {
assert.equal(info.blocks, 0); assert.equal(info.blocks, 0);
})); }));
it('should create account', co(function* () {
var info = yield wallet.createAccount('foo1');
assert(info);
assert(info.initialized);
assert.equal(info.name, 'foo1');
assert.equal(info.accountIndex, 1);
assert.equal(info.m, 1);
assert.equal(info.n, 1);
}));
it('should create account', co(function* () {
var info = yield wallet.createAccount('foo2', {
type: 'multisig',
m: 1,
n: 2
});
assert(info);
assert(!info.initialized);
assert.equal(info.name, 'foo2');
assert.equal(info.accountIndex, 2);
assert.equal(info.m, 1);
assert.equal(info.n, 2);
}));
it('should get a block template', co(function* () { it('should get a block template', co(function* () {
var json = yield wallet.client.rpc.execute('getblocktemplate', []); var json = yield wallet.client.rpc.execute('getblocktemplate', []);
assert.deepStrictEqual(json, { assert.deepStrictEqual(json, {