Merge pull request #198 from kleetus/compat/bool-validation
RPC method compatibility with bitcoin core.
This commit is contained in:
commit
3fda5bedab
@ -407,6 +407,14 @@ Validator.prototype.bool = function bool(key, fallback) {
|
|||||||
if (value === null)
|
if (value === null)
|
||||||
return fallback;
|
return fallback;
|
||||||
|
|
||||||
|
// bitcoin core mixes semantics of truthiness amoung rpc methods
|
||||||
|
// most "verbose" parameters are bools, but getrawtransaction is 1/0
|
||||||
|
if (value === 1)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (value === 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (typeof value !== 'string') {
|
if (typeof value !== 'string') {
|
||||||
if (typeof value !== 'boolean')
|
if (typeof value !== 'boolean')
|
||||||
throw new ValidationError(fmt(key) + ' must be a boolean.');
|
throw new ValidationError(fmt(key) + ' must be a boolean.');
|
||||||
|
|||||||
@ -154,6 +154,11 @@ describe('HTTP', function() {
|
|||||||
assert.equal(info.blocks, 0);
|
assert.equal(info.blocks, 0);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('should execute an rpc call with bool parameter', co(function* () {
|
||||||
|
var info = yield wallet.client.rpc.execute('getrawmempool', [true]);
|
||||||
|
assert.deepStrictEqual(info, {});
|
||||||
|
}));
|
||||||
|
|
||||||
it('should create account', co(function* () {
|
it('should create account', co(function* () {
|
||||||
var info = yield wallet.createAccount('foo1');
|
var info = yield wallet.createAccount('foo1');
|
||||||
assert(info);
|
assert(info);
|
||||||
|
|||||||
@ -9,6 +9,7 @@ var crypto = require('../lib/crypto/crypto');
|
|||||||
var schnorr = require('../lib/crypto/schnorr');
|
var schnorr = require('../lib/crypto/schnorr');
|
||||||
var Amount = require('../lib/btc/amount');
|
var Amount = require('../lib/btc/amount');
|
||||||
var consensus = require('../lib/protocol/consensus');
|
var consensus = require('../lib/protocol/consensus');
|
||||||
|
var Validator = require('../lib/utils/validator');
|
||||||
|
|
||||||
describe('Utils', function() {
|
describe('Utils', function() {
|
||||||
var vectors, signed, unsigned;
|
var vectors, signed, unsigned;
|
||||||
@ -328,4 +329,10 @@ describe('Utils', function() {
|
|||||||
assert(schnorr.verify(msg, sig, pub));
|
assert(schnorr.verify(msg, sig, pub));
|
||||||
assert.deepEqual(schnorr.recover(sig, msg), pub);
|
assert.deepEqual(schnorr.recover(sig, msg), pub);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should validate integers 0 and 1 as booleans', function() {
|
||||||
|
var validator = new Validator({shouldBeTrue: 1, shouldBeFalse: 0});
|
||||||
|
assert(validator.bool('shouldBeTrue') === true);
|
||||||
|
assert(validator.bool('shouldBeFalse') === false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user