test: remove test assert util and use bsert
This commit is contained in:
parent
f00985fefb
commit
a3a34dbfe6
@ -5,7 +5,7 @@
|
||||
|
||||
const Address = require('../lib/primitives/address');
|
||||
const Script = require('../lib/script/script');
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const nodejsUtil = require('util');
|
||||
|
||||
describe('Address', function() {
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const Address = require('../lib/primitives/address');
|
||||
|
||||
// see https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const common = require('./util/common');
|
||||
const {BloomFilter} = require('bfilter');
|
||||
const {BufferMap} = require('buffer-map');
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
const Logger = require('blgr');
|
||||
const bio = require('bufio');
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const common = require('./util/common');
|
||||
const {resolve} = require('path');
|
||||
const fs = require('bfile');
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const consensus = require('../lib/protocol/consensus');
|
||||
const Coin = require('../lib/primitives/coin');
|
||||
const Script = require('../lib/script/script');
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
'use strict';
|
||||
|
||||
const Coin = require('../lib/primitives/coin');
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const common = require('../test/util/common');
|
||||
const nodejsUtil = require('util');
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
'use strict';
|
||||
|
||||
const bio = require('bufio');
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const Output = require('../lib/primitives/output');
|
||||
const Input = require('../lib/primitives/input');
|
||||
const Outpoint = require('../lib/primitives/outpoint');
|
||||
@ -48,7 +48,7 @@ describe('Coins', function() {
|
||||
assert.strictEqual(entry.height, 1);
|
||||
assert.strictEqual(entry.coinbase, false);
|
||||
assert.strictEqual(entry.raw, null);
|
||||
assert.instanceOf(entry.output, Output);
|
||||
assert(entry.output instanceof Output);
|
||||
assert.strictEqual(entry.spent, false);
|
||||
|
||||
const output = view.getOutputFor(input);
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const consensus = require('../lib/protocol/consensus');
|
||||
const BN = require('bcrypto/lib/bn.js');
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
const {base58} = require('bstring');
|
||||
const pbkdf2 = require('bcrypto/lib/pbkdf2');
|
||||
const sha512 = require('bcrypto/lib/sha512');
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const HD = require('../lib/hd');
|
||||
const vectors = require('./data/hd.json');
|
||||
const vector1 = vectors.vector1;
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
'use strict';
|
||||
|
||||
const Headers = require('../lib/primitives/headers');
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const common = require('./util/common');
|
||||
|
||||
const block1 = common.readBlock('block1');
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
'use strict';
|
||||
|
||||
const {BloomFilter} = require('bfilter');
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const consensus = require('../lib/protocol/consensus');
|
||||
const Address = require('../lib/primitives/address');
|
||||
const Script = require('../lib/script/script');
|
||||
@ -87,15 +87,15 @@ describe('HTTP', function() {
|
||||
const info = await nclient.getInfo();
|
||||
assert.strictEqual(info.network, node.network.type);
|
||||
assert.strictEqual(info.version, pkg.version);
|
||||
assert.typeOf(info.pool, 'object');
|
||||
assert(typeof info.pool === 'object');
|
||||
assert.strictEqual(info.pool.agent, node.pool.options.agent);
|
||||
assert.typeOf(info.chain, 'object');
|
||||
assert(typeof info.chain === 'object');
|
||||
assert.strictEqual(info.chain.height, 0);
|
||||
assert.typeOf(info.indexes, 'object');
|
||||
assert.typeOf(info.indexes.addr, 'object');
|
||||
assert(typeof info.indexes === 'object');
|
||||
assert(typeof info.indexes.addr === 'object');
|
||||
assert.equal(info.indexes.addr.enabled, false);
|
||||
assert.equal(info.indexes.addr.height, 0);
|
||||
assert.typeOf(info.indexes.tx, 'object');
|
||||
assert(typeof info.indexes.tx === 'object');
|
||||
assert.equal(info.indexes.addr.enabled, false);
|
||||
assert.equal(info.indexes.tx.height, 0);
|
||||
});
|
||||
@ -105,7 +105,7 @@ describe('HTTP', function() {
|
||||
assert.strictEqual(info.id, 'test');
|
||||
const acct = await wallet.getAccount('default');
|
||||
const str = acct.receiveAddress;
|
||||
assert.typeOf(str, 'string');
|
||||
assert(typeof str === 'string');
|
||||
addr = Address.fromString(str, node.network);
|
||||
});
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const reorg = require('./util/reorg');
|
||||
const Script = require('../lib/script/script');
|
||||
const Opcode = require('../lib/script/opcode');
|
||||
@ -313,9 +313,12 @@ describe('Indexer', function() {
|
||||
maxTxs: 10
|
||||
});
|
||||
|
||||
await assert.asyncThrows(async () => {
|
||||
await assert.rejects(async () => {
|
||||
await indexer.getHashesByAddress(vectors[0].addr, {limit: 11});
|
||||
}, 'Limit above max');
|
||||
}, {
|
||||
name: 'Error',
|
||||
message: 'Limit above max of 10.'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -795,8 +798,8 @@ describe('Indexer', function() {
|
||||
httpPort: ports.node
|
||||
});
|
||||
|
||||
assert.equal(node.txindex, undefined);
|
||||
assert.equal(node.addrindex, undefined);
|
||||
assert.equal(node.txindex, null);
|
||||
assert.equal(node.addrindex, null);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -1184,23 +1187,32 @@ describe('Indexer', function() {
|
||||
|
||||
describe('Errors', function() {
|
||||
it('will give error if limit is exceeded', async () => {
|
||||
await assert.asyncThrows(async () => {
|
||||
await assert.rejects(async () => {
|
||||
await nclient.request(
|
||||
'GET', `/tx/address/${vectors[0].addr}`, {limit: 101});
|
||||
}, 'Limit above max');
|
||||
}, {
|
||||
name: 'Error',
|
||||
message: 'Limit above max of 100.'
|
||||
});
|
||||
});
|
||||
|
||||
it('will give error with invalid after hash', async () => {
|
||||
await assert.asyncThrows(async () => {
|
||||
await assert.rejects(async () => {
|
||||
await nclient.request(
|
||||
'GET', `/tx/address/${vectors[0].addr}`, {after: 'deadbeef'});
|
||||
}, {
|
||||
name: 'Error',
|
||||
message: 'after must be a hex string.'
|
||||
});
|
||||
});
|
||||
|
||||
it('will give error with invalid reverse', async () => {
|
||||
await assert.asyncThrows(async () => {
|
||||
await assert.rejects(async () => {
|
||||
await nclient.request(
|
||||
'GET', `/tx/address/${vectors[0].addr}`, {reverse: 'sure'});
|
||||
}, {
|
||||
name: 'Error',
|
||||
message: 'reverse must be a boolean.'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
const bio = require('bufio');
|
||||
const util = require('../lib/utils/util');
|
||||
const Input = require('../lib/primitives/input');
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const common = require('./util/common');
|
||||
|
||||
// Take input rawbytes from the raw data format
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const KeyRing = require('../lib/primitives/keyring');
|
||||
const Script = require('../lib/script/script');
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const random = require('bcrypto/lib/random');
|
||||
const common = require('../lib/blockchain/common');
|
||||
const Block = require('../lib/primitives/block');
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const Mnemonic = require('../lib/hd/mnemonic');
|
||||
const HDPrivateKey = require('../lib/hd/private');
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const test = require('./util/common');
|
||||
const {BloomFilter} = require('bfilter');
|
||||
const Logger = require('blgr');
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const consensus = require('../lib/protocol/consensus');
|
||||
const Coin = require('../lib/primitives/coin');
|
||||
const Script = require('../lib/script/script');
|
||||
@ -505,11 +505,11 @@ describe('Node', function() {
|
||||
id: '1'
|
||||
}, {});
|
||||
|
||||
assert.typeOf(json.result, 'object');
|
||||
assert.typeOf(json.result.curtime, 'number');
|
||||
assert.typeOf(json.result.mintime, 'number');
|
||||
assert.typeOf(json.result.maxtime, 'number');
|
||||
assert.typeOf(json.result.expires, 'number');
|
||||
assert(typeof json.result === 'object');
|
||||
assert(Number.isInteger(json.result.curtime));
|
||||
assert(Number.isInteger(json.result.mintime));
|
||||
assert(Number.isInteger(json.result.maxtime));
|
||||
assert(Number.isInteger(json.result.expires));
|
||||
|
||||
assert.deepStrictEqual(json, {
|
||||
result: {
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
'use strict';
|
||||
|
||||
const Outpoint = require('../lib/primitives/outpoint');
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const common = require('./util/common');
|
||||
const util = require('../lib/utils/util');
|
||||
const TX = require('../lib/primitives/tx');
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const Chain = require('../lib/blockchain/chain');
|
||||
const ChainEntry = require('../lib/blockchain/chainentry');
|
||||
const Network = require('../lib/protocol/network');
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const Network = require('../lib/protocol/network');
|
||||
const util = require('../lib/utils/util');
|
||||
const NetAddress = require('../lib/net/netaddress');
|
||||
@ -102,15 +102,15 @@ describe('Protocol', function() {
|
||||
];
|
||||
|
||||
packetTest('addr', new packets.AddrPacket(hosts), (payload) => {
|
||||
assert.typeOf(payload.items, 'array');
|
||||
assert(Array.isArray(payload.items));
|
||||
assert.strictEqual(payload.items.length, 2);
|
||||
|
||||
assert.typeOf(payload.items[0].time, 'number');
|
||||
assert(Number.isInteger(payload.items[0].time));
|
||||
assert.strictEqual(payload.items[0].services, 1);
|
||||
assert.strictEqual(payload.items[0].host, hosts[0].host);
|
||||
assert.strictEqual(payload.items[0].port, hosts[0].port);
|
||||
|
||||
assert.typeOf(payload.items[1].time, 'number');
|
||||
assert(Number.isInteger(payload.items[1].time));
|
||||
assert.strictEqual(payload.items[1].services, 1);
|
||||
assert.strictEqual(payload.items[1].host, hosts[1].host);
|
||||
assert.strictEqual(payload.items[1].port, hosts[1].port);
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const consensus = require('../lib/protocol/consensus');
|
||||
const Address = require('../lib/primitives/address');
|
||||
const FullNode = require('../lib/node/fullnode');
|
||||
@ -80,13 +80,19 @@ describe('RPC', function() {
|
||||
assert(await nclient.execute('help', []));
|
||||
assert(await wclient.execute('help', []));
|
||||
|
||||
await assert.asyncThrows(async () => {
|
||||
await assert.rejects(async () => {
|
||||
await nclient.execute('help', ['getinfo']);
|
||||
}, 'getinfo');
|
||||
}, {
|
||||
name: 'Error',
|
||||
message: /^getinfo/
|
||||
});
|
||||
|
||||
await assert.asyncThrows(async () => {
|
||||
await assert.rejects(async () => {
|
||||
await wclient.execute('help', ['getbalance']);
|
||||
}, 'getbalance');
|
||||
}, {
|
||||
name: 'Error',
|
||||
message: /^getbalance/
|
||||
});
|
||||
});
|
||||
|
||||
it('should rpc getinfo', async () => {
|
||||
@ -105,9 +111,12 @@ describe('RPC', function() {
|
||||
});
|
||||
|
||||
it('should fail rpc getnewaddress from nonexistent account', async () => {
|
||||
await assert.asyncThrows(async () => {
|
||||
await assert.rejects(async () => {
|
||||
await wclient.execute('getnewaddress', ['bad-account-name']);
|
||||
}, 'Account not found.');
|
||||
}, {
|
||||
name: 'Error',
|
||||
message: 'Account not found.'
|
||||
});
|
||||
});
|
||||
|
||||
it('should rpc getaccountaddress', async () => {
|
||||
@ -138,15 +147,21 @@ describe('RPC', function() {
|
||||
});
|
||||
|
||||
it('should fail malformed rpc sendmany', async () => {
|
||||
await assert.asyncThrows(async () => {
|
||||
await assert.rejects(async () => {
|
||||
await wclient.execute('sendmany', ['default', null]);
|
||||
}, 'Invalid send-to address');
|
||||
}, {
|
||||
name: 'Error',
|
||||
message: 'Invalid send-to address.'
|
||||
});
|
||||
|
||||
const sendTo = {};
|
||||
sendTo[addressHot] = null;
|
||||
await assert.asyncThrows(async () => {
|
||||
await assert.rejects(async () => {
|
||||
await wclient.execute('sendmany', ['default', sendTo]);
|
||||
}, 'Invalid amount.');
|
||||
}, {
|
||||
name: 'Error',
|
||||
message: 'Invalid amount.'
|
||||
});
|
||||
});
|
||||
|
||||
it('should rpc listreceivedbyaddress', async () => {
|
||||
@ -198,9 +213,12 @@ describe('RPC', function() {
|
||||
});
|
||||
|
||||
it('should fail rpc listtransactions from nonexistent account', async () => {
|
||||
assert.asyncThrows(async () => {
|
||||
assert.rejects(async () => {
|
||||
await wclient.execute('listtransactions', ['nonexistent']);
|
||||
}, 'Account not found.');
|
||||
}, {
|
||||
name: 'Error',
|
||||
message: 'Account not found.'
|
||||
});
|
||||
});
|
||||
|
||||
it('should rpc listunspent', async () => {
|
||||
@ -244,9 +262,12 @@ describe('RPC', function() {
|
||||
assert.strictEqual(listOldBlock.transactions.length, 2);
|
||||
|
||||
const nonexistentBlock = consensus.ZERO_HASH.toString('hex');
|
||||
await assert.asyncThrows(async () => {
|
||||
await assert.rejects(async () => {
|
||||
await wclient.execute('listsinceblock', [nonexistentBlock]);
|
||||
}, 'Block not found');
|
||||
}, {
|
||||
name: 'Error',
|
||||
message: 'Block not found.'
|
||||
});
|
||||
});
|
||||
|
||||
it('should cleanup', async () => {
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const Script = require('../lib/script/script');
|
||||
const Witness = require('../lib/script/witness');
|
||||
const Stack = require('../lib/script/stack');
|
||||
@ -336,7 +336,7 @@ describe('Script', function() {
|
||||
}
|
||||
|
||||
if (expected !== 'OK') {
|
||||
assert.typeOf(err, 'error');
|
||||
assert(err instanceof Error);
|
||||
assert.strictEqual(err.code, expected);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
const {inspect} = require('util');
|
||||
const {encoding} = require('bufio');
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const random = require('bcrypto/lib/random');
|
||||
const util = require('../lib/utils/util');
|
||||
const consensus = require('../lib/protocol/consensus');
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const Network = require('../lib/protocol/network');
|
||||
const TXMeta = require('../lib/primitives/txmeta');
|
||||
|
||||
|
||||
@ -1,230 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const _assert = require('assert');
|
||||
const util = require('util');
|
||||
|
||||
const assert = function assert(value, message) {
|
||||
if (!value) {
|
||||
throw new assert.AssertionError({
|
||||
message,
|
||||
actual: value,
|
||||
expected: true,
|
||||
operator: '==',
|
||||
stackStartFunction: assert
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Object.setPrototypeOf(assert, _assert);
|
||||
|
||||
assert.typeOf = function typeOf(value, expected, message) {
|
||||
_isString(expected, '`expected` must be a string.', typeOf);
|
||||
|
||||
const actual = _typeOf(value);
|
||||
|
||||
if (actual !== expected) {
|
||||
throw new assert.AssertionError({
|
||||
message,
|
||||
actual,
|
||||
expected,
|
||||
operator: 'typeof ==',
|
||||
stackStartFunction: typeOf
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
assert.notTypeOf = function notTypeOf(value, expected, message) {
|
||||
_isString(expected, '`expected` must be a string.', notTypeOf);
|
||||
|
||||
const actual = _typeOf(value);
|
||||
|
||||
if (actual === expected) {
|
||||
throw new assert.AssertionError({
|
||||
message,
|
||||
actual,
|
||||
expected,
|
||||
operator: 'typeof !=',
|
||||
stackStartFunction: notTypeOf
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
assert.instanceOf = function instanceOf(object, parent, message) {
|
||||
_isFunction(parent, '`parent` must be a constructor.', instanceOf);
|
||||
|
||||
if (!(object instanceof parent)) {
|
||||
throw new assert.AssertionError({
|
||||
message,
|
||||
actual: _getConstructorName(object),
|
||||
expected: _getFunctionName(parent),
|
||||
operator: 'instanceof',
|
||||
stackStartFunction: instanceOf
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
assert.notInstanceOf = function notInstanceOf(object, parent, message) {
|
||||
_isFunction(parent, '`parent` must be a constructor.', notInstanceOf);
|
||||
|
||||
if (object instanceof parent) {
|
||||
throw new assert.AssertionError({
|
||||
message,
|
||||
actual: _getConstructorName(object),
|
||||
expected: _getFunctionName(parent),
|
||||
operator: 'not instanceof',
|
||||
stackStartFunction: notInstanceOf
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
assert.bufferEqual = function bufferEqual(actual, expected, message) {
|
||||
_isBuffer(actual, '`actual` must be a buffer.', bufferEqual);
|
||||
_isBuffer(expected, '`expected` must be a buffer.', bufferEqual);
|
||||
|
||||
if (actual !== expected && !actual.equals(expected)) {
|
||||
throw new assert.AssertionError({
|
||||
message,
|
||||
actual: actual.toString('hex'),
|
||||
expected: expected.toString('hex'),
|
||||
operator: '===',
|
||||
stackStartFunction: bufferEqual
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
assert.notBufferEqual = function notBufferEqual(actual, expected, message) {
|
||||
_isBuffer(actual, '`actual` must be a buffer.', notBufferEqual);
|
||||
_isBuffer(expected, '`expected` must be a buffer.', notBufferEqual);
|
||||
|
||||
if (actual === expected || actual.equals(expected)) {
|
||||
throw new assert.AssertionError({
|
||||
message,
|
||||
actual: actual.toString('hex'),
|
||||
expected: expected.toString('hex'),
|
||||
operator: '!==',
|
||||
stackStartFunction: notBufferEqual
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// node V10 implements assert.rejects() but this is compatible with V8
|
||||
assert.asyncThrows = async function asyncThrows(func, expectedError) {
|
||||
let err = null;
|
||||
try {
|
||||
await func();
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
assert(err, 'Expected error.');
|
||||
if (expectedError) {
|
||||
const re = new RegExp('^' + expectedError);
|
||||
assert(re.test(err.message), err.message);
|
||||
}
|
||||
};
|
||||
|
||||
function _isString(value, message, stackStartFunction) {
|
||||
if (typeof value !== 'string') {
|
||||
throw new assert.AssertionError({
|
||||
message,
|
||||
actual: _typeOf(value),
|
||||
expected: 'string',
|
||||
operator: 'typeof ==',
|
||||
stackStartFunction
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function _isFunction(value, message, stackStartFunction) {
|
||||
if (typeof value !== 'function') {
|
||||
throw new assert.AssertionError({
|
||||
message,
|
||||
actual: _typeOf(value),
|
||||
expected: 'function',
|
||||
operator: 'typeof ==',
|
||||
stackStartFunction
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function _isBuffer(value, message, stackStartFunction) {
|
||||
if (!Buffer.isBuffer(value)) {
|
||||
throw new assert.AssertionError({
|
||||
message,
|
||||
actual: _typeOf(value),
|
||||
expected: 'buffer',
|
||||
operator: 'typeof ==',
|
||||
stackStartFunction
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function _typeOf(value) {
|
||||
const type = typeof value;
|
||||
|
||||
switch (type) {
|
||||
case 'object':
|
||||
if (value === null)
|
||||
return 'null';
|
||||
|
||||
if (Array.isArray(value))
|
||||
return 'array';
|
||||
|
||||
if (Buffer.isBuffer(value))
|
||||
return 'buffer';
|
||||
|
||||
if (ArrayBuffer.isView(value))
|
||||
return 'arraybuffer';
|
||||
|
||||
if (util.isError(value))
|
||||
return 'error';
|
||||
|
||||
if (util.isDate(value))
|
||||
return 'date';
|
||||
|
||||
if (util.isRegExp(value))
|
||||
return 'regexp';
|
||||
|
||||
break;
|
||||
case 'number':
|
||||
if (!isFinite(value))
|
||||
return 'nan';
|
||||
break;
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
function _getConstructorName(object) {
|
||||
if (object === undefined)
|
||||
return 'undefined';
|
||||
|
||||
if (object === null)
|
||||
return 'null';
|
||||
|
||||
const proto = Object.getPrototypeOf(object);
|
||||
|
||||
// Should never happen.
|
||||
if (proto === undefined)
|
||||
throw new Error('Bad prototype.');
|
||||
|
||||
// Inherited from `null`.
|
||||
if (proto === null)
|
||||
return 'Null';
|
||||
|
||||
// Someone overwrote their
|
||||
// constructor property?
|
||||
if (!proto.constructor)
|
||||
return 'Object';
|
||||
|
||||
// Non-named constructor function.
|
||||
if (!proto.constructor.name)
|
||||
return 'Unknown';
|
||||
|
||||
return proto.constructor.name;
|
||||
}
|
||||
|
||||
function _getFunctionName(func) {
|
||||
return func.name || 'Unknown';
|
||||
}
|
||||
|
||||
module.exports = assert;
|
||||
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('bsert');
|
||||
const {tmpdir} = require('os');
|
||||
const path = require('path');
|
||||
const fs = require('bfile');
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('bsert');
|
||||
const {BufferMap, BufferSet} = require('buffer-map');
|
||||
const Network = require('../../lib/protocol/network');
|
||||
const MTX = require('../../lib/primitives/mtx');
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const assert = require('bsert');
|
||||
const FullNode = require('../../lib/node/fullnode');
|
||||
const Network = require('../../lib/protocol/network');
|
||||
const Logger = require('blgr');
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('./assert');
|
||||
const assert = require('bsert');
|
||||
const Chain = require('../../lib/blockchain/chain');
|
||||
const CPUMiner = require('../../lib/mining/cpuminer');
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
const Validator = require('bval');
|
||||
const {base58} = require('bstring');
|
||||
const {encoding} = require('bufio');
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const Amount = require('../lib/btc/amount');
|
||||
const fixed = require('../lib/utils/fixed');
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
'use strict';
|
||||
|
||||
const {NodeClient, WalletClient} = require('bclient');
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const FullNode = require('../lib/node/fullnode');
|
||||
const Network = require('../lib/protocol/network');
|
||||
const Mnemonic = require('../lib/hd/mnemonic');
|
||||
@ -259,7 +259,10 @@ describe('Wallet RPC Methods', function() {
|
||||
// Match the bitcoind response when sending the incorrect
|
||||
// network. Expect an RPC error
|
||||
const fn = async () => await wclient.execute('getaddressinfo', [failed]);
|
||||
await assert.asyncThrows(fn, 'Invalid address.');
|
||||
await assert.rejects(fn, {
|
||||
name: 'Error',
|
||||
message: 'Invalid address.'
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail for invalid address', async () => {
|
||||
@ -269,7 +272,10 @@ describe('Wallet RPC Methods', function() {
|
||||
failed = failed.slice(1, failed.length);
|
||||
|
||||
const fn = async () => await wclient.execute('getaddressinfo', [failed]);
|
||||
await assert.asyncThrows(fn, 'Invalid address.');
|
||||
await assert.rejects(fn, {
|
||||
name: 'Error',
|
||||
message: 'Invalid address.'
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('./util/assert');
|
||||
const assert = require('bsert');
|
||||
const consensus = require('../lib/protocol/consensus');
|
||||
const util = require('../lib/utils/util');
|
||||
const hash256 = require('bcrypto/lib/hash256');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user