From 3a7484d782860095af4b3e21b041e8375aa4e547 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 11 Aug 2017 18:25:54 -0700 Subject: [PATCH] test: refactor assertions. --- test/aes-test.js | 12 +++---- test/bip150-test.js | 20 +++++------ test/bip151-test.js | 20 +++++------ test/bip70-test.js | 3 +- test/block-test.js | 7 ++-- test/bloom-test.js | 7 ++-- test/chachapoly-test.js | 5 +++ test/coins-test.js | 3 +- test/gcs-test.js | 8 ++--- test/hd-test.js | 20 +++++------ test/http-test.js | 10 +++--- test/node-test.js | 13 +++---- test/protocol-test.js | 6 ++-- test/schnorr-test.js | 2 +- test/script-test.js | 2 +- test/tx-test.js | 5 +-- test/util/assert.js | 75 +++++++++++++++++++++++++++++++++++++++-- test/utils-test.js | 57 +++++++++++++++++-------------- 18 files changed, 182 insertions(+), 93 deletions(-) diff --git a/test/aes-test.js b/test/aes-test.js index 139c301e..32c547ef 100644 --- a/test/aes-test.js +++ b/test/aes-test.js @@ -6,13 +6,13 @@ const assert = require('./util/assert'); const aes = require('../lib/crypto/aes'); +const key = Buffer.from( + '3a0c0bf669694ac7685e6806eeadee8e56c9b9bd22c3caa81c718ed4bbf809a1', + 'hex'); + +const iv = Buffer.from('6dd26d9045b73c377a9ed2ffeca72ffd', 'hex'); + describe('AES', function() { - const key = Buffer.from( - '3a0c0bf669694ac7685e6806eeadee8e56c9b9bd22c3caa81c718ed4bbf809a1', - 'hex'); - - const iv = Buffer.from('6dd26d9045b73c377a9ed2ffeca72ffd', 'hex'); - it('should encrypt and decrypt with 2 blocks', () => { const data = Buffer.from( 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', diff --git a/test/bip150-test.js b/test/bip150-test.js index 579e874d..40a8bcb6 100644 --- a/test/bip150-test.js +++ b/test/bip150-test.js @@ -70,7 +70,7 @@ describe('BIP150', function() { server.once('packet', (cmd, body) => { emitted = true; assert.strictEqual(cmd, 'fake'); - assert.strictEqual(body.toString('hex'), 'deadbeef'); + assert.bufferEqual(body, payload()); }); server.feed(packet); assert(emitted); @@ -82,7 +82,7 @@ describe('BIP150', function() { client.once('packet', (cmd, body) => { emitted = true; assert.strictEqual(cmd, 'fake'); - assert.strictEqual(body.toString('hex'), 'deadbeef'); + assert.bufferEqual(body, payload()); }); client.feed(packet); assert(emitted); @@ -94,7 +94,7 @@ describe('BIP150', function() { server.once('packet', (cmd, body) => { emitted = true; assert.strictEqual(cmd, 'fake'); - assert.strictEqual(body.toString('hex'), 'deadbeef'); + assert.bufferEqual(body, payload()); }); server.feed(packet); assert(emitted); @@ -106,7 +106,7 @@ describe('BIP150', function() { client.once('packet', (cmd, body) => { emitted = true; assert.strictEqual(cmd, 'fake'); - assert.strictEqual(body.toString('hex'), 'deadbeef'); + assert.bufferEqual(body, payload()); }); client.feed(packet); assert(emitted); @@ -145,7 +145,7 @@ describe('BIP150', function() { server.once('packet', (cmd, body) => { emitted = true; assert.strictEqual(cmd, 'fake'); - assert.strictEqual(body.toString('hex'), 'deadbeef'); + assert.bufferEqual(body, payload()); }); server.feed(packet); assert(emitted); @@ -157,7 +157,7 @@ describe('BIP150', function() { client.once('packet', (cmd, body) => { emitted = true; assert.strictEqual(cmd, 'fake'); - assert.strictEqual(body.toString('hex'), 'deadbeef'); + assert.bufferEqual(body, payload()); }); client.feed(packet); assert(emitted); @@ -169,7 +169,7 @@ describe('BIP150', function() { server.once('packet', (cmd, body) => { emitted = true; assert.strictEqual(cmd, 'fake'); - assert.strictEqual(body.toString('hex'), 'deadbeef'); + assert.bufferEqual(body, payload()); }); server.feed(packet); assert(emitted); @@ -181,7 +181,7 @@ describe('BIP150', function() { client.once('packet', (cmd, body) => { emitted = true; assert.strictEqual(cmd, 'fake'); - assert.strictEqual(body.toString('hex'), 'deadbeef'); + assert.bufferEqual(body, payload()); }); client.feed(packet); assert(emitted); @@ -195,12 +195,12 @@ describe('BIP150', function() { client.once('packet', (cmd, body) => { cemitted = true; assert.strictEqual(cmd, 'fake'); - assert.strictEqual(body.toString('hex'), 'deadbeef'); + assert.bufferEqual(body, payload()); }); server.once('packet', (cmd, body) => { semitted = true; assert.strictEqual(cmd, 'fake'); - assert.strictEqual(body.toString('hex'), 'deadbeef'); + assert.bufferEqual(body, payload()); }); client.feed(spacket); server.feed(cpacket); diff --git a/test/bip151-test.js b/test/bip151-test.js index b7b0a6ab..fe68fe6c 100644 --- a/test/bip151-test.js +++ b/test/bip151-test.js @@ -45,7 +45,7 @@ describe('BIP151', function() { server.once('packet', (cmd, body) => { emitted = true; assert.strictEqual(cmd, 'fake'); - assert.strictEqual(body.toString('hex'), 'deadbeef'); + assert.bufferEqual(body, payload()); }); server.feed(packet); assert(emitted); @@ -57,7 +57,7 @@ describe('BIP151', function() { client.once('packet', (cmd, body) => { emitted = true; assert.strictEqual(cmd, 'fake'); - assert.strictEqual(body.toString('hex'), 'deadbeef'); + assert.bufferEqual(body, payload()); }); client.feed(packet); assert(emitted); @@ -69,7 +69,7 @@ describe('BIP151', function() { server.once('packet', (cmd, body) => { emitted = true; assert.strictEqual(cmd, 'fake'); - assert.strictEqual(body.toString('hex'), 'deadbeef'); + assert.bufferEqual(body, payload()); }); server.feed(packet); assert(emitted); @@ -81,7 +81,7 @@ describe('BIP151', function() { client.once('packet', (cmd, body) => { emitted = true; assert.strictEqual(cmd, 'fake'); - assert.strictEqual(body.toString('hex'), 'deadbeef'); + assert.bufferEqual(body, payload()); }); client.feed(packet); assert(emitted); @@ -120,7 +120,7 @@ describe('BIP151', function() { server.once('packet', (cmd, body) => { emitted = true; assert.strictEqual(cmd, 'fake'); - assert.strictEqual(body.toString('hex'), 'deadbeef'); + assert.bufferEqual(body, payload()); }); server.feed(packet); assert(emitted); @@ -132,7 +132,7 @@ describe('BIP151', function() { client.once('packet', (cmd, body) => { emitted = true; assert.strictEqual(cmd, 'fake'); - assert.strictEqual(body.toString('hex'), 'deadbeef'); + assert.bufferEqual(body, payload()); }); client.feed(packet); assert(emitted); @@ -144,7 +144,7 @@ describe('BIP151', function() { server.once('packet', (cmd, body) => { emitted = true; assert.strictEqual(cmd, 'fake'); - assert.strictEqual(body.toString('hex'), 'deadbeef'); + assert.bufferEqual(body, payload()); }); server.feed(packet); assert(emitted); @@ -156,7 +156,7 @@ describe('BIP151', function() { client.once('packet', (cmd, body) => { emitted = true; assert.strictEqual(cmd, 'fake'); - assert.strictEqual(body.toString('hex'), 'deadbeef'); + assert.bufferEqual(body, payload()); }); client.feed(packet); assert(emitted); @@ -170,12 +170,12 @@ describe('BIP151', function() { client.once('packet', (cmd, body) => { cemitted = true; assert.strictEqual(cmd, 'fake'); - assert.strictEqual(body.toString('hex'), 'deadbeef'); + assert.bufferEqual(body, payload()); }); server.once('packet', (cmd, body) => { semitted = true; assert.strictEqual(cmd, 'fake'); - assert.strictEqual(body.toString('hex'), 'deadbeef'); + assert.bufferEqual(body, payload()); }); client.feed(spacket); server.feed(cpacket); diff --git a/test/bip70-test.js b/test/bip70-test.js index d45446ea..1e63ce2e 100644 --- a/test/bip70-test.js +++ b/test/bip70-test.js @@ -182,7 +182,8 @@ describe('BIP70', function() { assert.deepStrictEqual(req.paymentDetails.getData('json'), {foo:'bar'}); assert.strictEqual(req.version, 25); - assert.strictEqual(req.paymentDetails.paymentUrl, 'http://bcoin.io/payment'); + assert.strictEqual(req.paymentDetails.paymentUrl, + 'http://bcoin.io/payment'); assert.strictEqual(req.paymentDetails.network, 'testnet'); assert(req.paymentDetails.time <= util.now()); assert.strictEqual(req.paymentDetails.expires, diff --git a/test/block-test.js b/test/block-test.js index 0f716eec..b30c8187 100644 --- a/test/block-test.js +++ b/test/block-test.js @@ -39,10 +39,11 @@ const undo928828 = fs.readFileSync(`${__dirname}/data/undo928828.raw`); const block1087400 = fs.readFileSync(`${__dirname}/data/block1087400.raw`); const undo1087400 = fs.readFileSync(`${__dirname}/data/undo1087400.raw`); -describe('Block', function() { - const mblock = MerkleBlock.fromRaw(merkle300025); - const block = Block.fromRaw(block300025); +// Abstract +const mblock = MerkleBlock.fromRaw(merkle300025); +const block = Block.fromRaw(block300025); +describe('Block', function() { this.timeout(10000); it('should parse partial merkle tree', () => { diff --git a/test/bloom-test.js b/test/bloom-test.js index 520509a5..34b8934d 100644 --- a/test/bloom-test.js +++ b/test/bloom-test.js @@ -67,15 +67,18 @@ describe('Bloom', function() { const item2 = '047b00000078da0dca3b0ec2300c00d0ab4466ed10' + 'e763272c6c9ca052972c69e3884a9022084215e2eef' + '0e6f781656b5d5a87231cd4349e534b6dea55ad4ff55e'; - const filterRaw = Buffer.from('' + + const expected = Buffer.from('' + '000000000000000000000000000000000000000000000000088004000000000000000' + '000000000200000000000000000000000000000000800000000000000000002000000' + '000000000000002000000000000000000000000000000000000000000040000200000' + '0000000001000000800000080000000', 'hex'); + filter.add(item1, 'hex'); filter.add(item2, 'hex'); - assert.bufferEqual(filter.filter, filterRaw); + + assert.bufferEqual(filter.filter, expected); }); it('should handle 1m ops with regular filter', () => { diff --git a/test/chachapoly-test.js b/test/chachapoly-test.js index 3dd297be..27beb23c 100644 --- a/test/chachapoly-test.js +++ b/test/chachapoly-test.js @@ -173,7 +173,12 @@ describe('ChaCha20 / Poly1305 / AEAD', function() { const tag = Buffer.from('a8061dc1305136c6c22b8baf0c0127a9', 'hex'); const mac = Poly1305.auth(msg, key); + assert(Poly1305.verify(mac, tag)); + + mac[0] = 0; + + assert(!Poly1305.verify(mac, tag)); }); it('should create an AEAD and encrypt', () => { diff --git a/test/coins-test.js b/test/coins-test.js index a19d4366..c787e53b 100644 --- a/test/coins-test.js +++ b/test/coins-test.js @@ -44,13 +44,12 @@ describe('Coins', function() { const entry = coins.get(0); assert(entry); - assert(!entry.spent); assert.strictEqual(entry.version, 1); assert.strictEqual(entry.height, 1); assert.strictEqual(entry.coinbase, false); assert.strictEqual(entry.raw, null); - assert(entry.output instanceof Output); + assert.instanceOf(entry.output, Output); assert.strictEqual(entry.spent, false); const output = view.getOutputFor(input); diff --git a/test/gcs-test.js b/test/gcs-test.js index 67e4040d..38ecf014 100644 --- a/test/gcs-test.js +++ b/test/gcs-test.js @@ -142,12 +142,12 @@ describe('GCS', function() { match = filter2.matchAny(key, contents2); assert(!match); - const c = contents2.slice(); - c.push(Buffer.from('Nate')); + const contents = contents2.slice(); + contents.push(Buffer.from('Nate')); - match = filter1.matchAny(key, c); + match = filter1.matchAny(key, contents); assert(match); - match = filter2.matchAny(key, c); + match = filter2.matchAny(key, contents); assert(match); }); diff --git a/test/hd-test.js b/test/hd-test.js index a059aee8..7b1293c5 100644 --- a/test/hd-test.js +++ b/test/hd-test.js @@ -14,13 +14,9 @@ const vector2 = vectors.vector2; let master = null; let child = null; -function unbase58(data) { - return base58.decode(data).toString('hex'); -} - function base58Equal(a, b) { assert.strictEqual(a, b); - assert.strictEqual(unbase58(a), unbase58(b)); + assert.bufferEqual(base58.decode(a), base58.decode(b)); } describe('HD', function() { @@ -93,16 +89,18 @@ describe('HD', function() { HD.PublicKey.fromBase58(master.toPublic().toBase58()); }); - it('should deserialize and reserialize', () => { + it('should deserialize and reserialize json', () => { const key = HD.generate(); - assert.strictEqual(HD.fromJSON(key.toJSON()).toBase58(), key.toBase58()); + const json = key.toJSON(); + base58Equal(HD.fromJSON(json).toBase58(), key.toBase58()); }); for (const vector of [vector1, vector2]) { let master = null; it('should create from a seed', () => { - const key = HD.PrivateKey.fromSeed(Buffer.from(vector.seed, 'hex')); + const seed = Buffer.from(vector.seed, 'hex'); + const key = HD.PrivateKey.fromSeed(seed); const pub = key.toPublic(); base58Equal(key.toBase58(), vector.m.prv); @@ -112,10 +110,10 @@ describe('HD', function() { }); for (const path of Object.keys(vector)) { - const kp = vector[path]; - if (path === 'seed' || path === 'm') - return; + continue; + + const kp = vector[path]; it(`should derive ${path} from master`, () => { const key = master.derivePath(path); diff --git a/test/http-test.js b/test/http-test.js index 173fc789..e37b3eb8 100644 --- a/test/http-test.js +++ b/test/http-test.js @@ -51,17 +51,19 @@ describe('HTTP', function() { const info = await wallet.client.getInfo(); assert.strictEqual(info.network, node.network.type); assert.strictEqual(info.version, pkg.version); + assert.typeOf(info.pool, 'object'); assert.strictEqual(info.pool.agent, node.pool.options.agent); - assert.strictEqual(typeof info.chain, 'object'); + assert.typeOf(info.chain, 'object'); assert.strictEqual(info.chain.height, 0); }); it('should get wallet info', async () => { const info = await wallet.getInfo(); assert.strictEqual(info.id, 'test'); - addr = info.account.receiveAddress; - assert.strictEqual(typeof addr, 'string'); - addr = Address.fromString(addr); + assert.typeOf(info.account, 'object'); + const str = info.account.receiveAddress; + assert.typeOf(str, 'string'); + addr = Address.fromString(str); }); it('should fill with funds', async () => { diff --git a/test/node-test.js b/test/node-test.js index 0516276c..37bbb8f6 100644 --- a/test/node-test.js +++ b/test/node-test.js @@ -471,10 +471,11 @@ describe('Node', function() { id: '1' }, {}); - assert.strictEqual(typeof json.result.curtime, 'number'); - assert.strictEqual(typeof json.result.mintime, 'number'); - assert.strictEqual(typeof json.result.maxtime, 'number'); - assert.strictEqual(typeof json.result.expires, 'number'); + 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.deepStrictEqual(json, { result: { @@ -584,7 +585,7 @@ describe('Node', function() { await wallet.db.addTX(tx); const missing = await node.mempool.addTX(tx); - assert(!missing || missing.length === 0); + assert(!missing); assert.strictEqual(node.mempool.map.size, 1); @@ -609,7 +610,7 @@ describe('Node', function() { await wallet.db.addTX(tx); const missing = await node.mempool.addTX(tx); - assert(!missing || missing.length === 0); + assert(!missing); assert.strictEqual(node.mempool.map.size, 2); diff --git a/test/protocol-test.js b/test/protocol-test.js index 22e26aa3..f316cdf1 100644 --- a/test/protocol-test.js +++ b/test/protocol-test.js @@ -97,15 +97,15 @@ describe('Protocol', function() { ]; packetTest('addr', new packets.AddrPacket(hosts), (payload) => { - assert.strictEqual(typeof payload.items.length, 'number'); + assert.typeOf(payload.items, 'array'); assert.strictEqual(payload.items.length, 2); - assert.strictEqual(typeof payload.items[0].time, 'number'); + assert.typeOf(payload.items[0].time, 'number'); 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.strictEqual(typeof payload.items[1].time, 'number'); + assert.typeOf(payload.items[1].time, 'number'); 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); diff --git a/test/schnorr-test.js b/test/schnorr-test.js index 8992e304..0934fd56 100644 --- a/test/schnorr-test.js +++ b/test/schnorr-test.js @@ -14,7 +14,7 @@ describe('Schnorr', function() { const pub = secp256k1.publicKeyCreate(key, true); const msg = digest.hash256(Buffer.from('foo', 'ascii')); const sig = schnorr.sign(msg, key); - assert(schnorr.verify(msg, sig, pub)); + assert.strictEqual(schnorr.verify(msg, sig, pub), true); assert.bufferEqual(schnorr.recover(sig, msg), pub); }); }); diff --git a/test/script-test.js b/test/script-test.js index 74c9eaa3..f954e67c 100644 --- a/test/script-test.js +++ b/test/script-test.js @@ -345,7 +345,7 @@ describe('Script', function() { } if (expected !== 'OK') { - assert(err); + assert.typeOf(err, 'error'); assert.strictEqual(err.code, expected); return; } diff --git a/test/tx-test.js b/test/tx-test.js index 7cf89a3b..b6af5a14 100644 --- a/test/tx-test.js +++ b/test/tx-test.js @@ -41,8 +41,9 @@ function clearCache(tx, noCache) { } const copy = tx.clone(); - assert.strictEqual(tx.txid(), copy.txid()); - assert.strictEqual(tx.wtxid(), copy.wtxid()); + + assert.bufferEqual(tx.hash(), copy.hash()); + assert.bufferEqual(tx.witnessHash(), copy.witnessHash()); } function parseTXTest(data) { diff --git a/test/util/assert.js b/test/util/assert.js index 6beb7a1d..0dfa4121 100644 --- a/test/util/assert.js +++ b/test/util/assert.js @@ -9,11 +9,61 @@ const assert = function assert(ok, message) { Object.setPrototypeOf(assert, _assert); +assert.typeOf = function typeOf(value, expected, message) { + const type = _typeOf(value); + if (type !== expected) { + throw new assert.AssertionError({ + mesage: message, + actual: type, + expected: expected, + operator: '===', + stackStartFunction: typeOf + }); + } +}; + +assert.notTypeOf = function notTypeOf(value, expected, message) { + const type = _typeOf(value); + if (type === expected) { + throw new assert.AssertionError({ + mesage: message, + actual: type, + expected: expected, + operator: '!==', + stackStartFunction: notTypeOf + }); + } +}; + +assert.instanceOf = function instanceOf(object, parent, message) { + if (!(object instanceof parent)) { + throw new assert.AssertionError({ + mesage: message, + actual: _getConstructor(object), + expected: parent.name, + operator: '===', + stackStartFunction: instanceOf + }); + } +}; + +assert.notInstanceOf = function notInstanceOf(object, parent, message) { + if (object instanceof parent) { + throw new assert.AssertionError({ + mesage: message, + actual: _getConstructor(object), + expected: parent.name, + operator: '!==', + stackStartFunction: notInstanceOf + }); + } +}; + assert.isBuffer = function isBuffer(value, message) { if (!Buffer.isBuffer(value)) { throw new assert.AssertionError({ mesage: message, - actual: typeOf(value), + actual: _typeOf(value), expected: 'buffer', operator: '===', stackStartFunction: isBuffer @@ -25,6 +75,9 @@ assert.bufferEqual = function bufferEqual(actual, expected, message) { assert.isBuffer(actual, message); assert.isBuffer(expected, message); + if (actual === expected) + return; + if (!actual.equals(expected)) { throw new assert.AssertionError({ mesage: message, @@ -51,7 +104,7 @@ assert.notBufferEqual = function notBufferEqual(actual, expected, message) { } }; -function typeOf(value) { +function _typeOf(value) { if (value === null) return 'null'; @@ -73,4 +126,22 @@ function typeOf(value) { return typeof value; } +function _getConstructor(value) { + if (value === undefined) + return 'Undefined'; + + if (value === null) + return 'Null'; + + const proto = Object.getPrototypeOf(value); + + if (proto == null) + return 'Null'; + + const ctor = proto.constructor; + const name = ctor ? ctor.name : null; + + return name || 'Unknown'; +} + module.exports = assert; diff --git a/test/utils-test.js b/test/utils-test.js index b6b26ffc..9bd2b60b 100644 --- a/test/utils-test.js +++ b/test/utils-test.js @@ -33,6 +33,30 @@ const base58Tests = [ ['00000000000000000000', '1111111111'] ]; +const unsigned = [ + new BN('ffeeffee'), + new BN('001fffeeffeeffee'), + new BN('eeffeeff'), + new BN('001feeffeeffeeff'), + new BN(0), + new BN(1) +]; + +const signed = [ + new BN('ffeeffee'), + new BN('001fffeeffeeffee'), + new BN('eeffeeff'), + new BN('001feeffeeffeeff'), + new BN(0), + new BN(1), + new BN('ffeeffee').ineg(), + new BN('001fffeeffeeffee').ineg(), + new BN('eeffeeff').ineg(), + new BN('001feeffeeffeeff').ineg(), + new BN(0).ineg(), + new BN(1).ineg() +]; + describe('Utils', function() { it('should encode/decode base58', () => { const buf = Buffer.from('000000deadbeef', 'hex'); @@ -56,14 +80,16 @@ describe('Utils', function() { 'hex' ); - assert(consensus.verifyPOW(hash, bits)); + assert.strictEqual(consensus.verifyPOW(hash, bits), true); }); it('should convert satoshi to btc', () => { let btc = Amount.btc(5460); assert.strictEqual(btc, '0.0000546'); + btc = Amount.btc(54678 * 1000000); assert.strictEqual(btc, '546.78'); + btc = Amount.btc(5460 * 10000000); assert.strictEqual(btc, '546.0'); }); @@ -71,12 +97,16 @@ describe('Utils', function() { it('should convert btc to satoshi', () => { let btc = Amount.value('0.0000546'); assert.strictEqual(btc, 5460); + btc = Amount.value('546.78'); assert.strictEqual(btc, 54678 * 1000000); + btc = Amount.value('546'); assert.strictEqual(btc, 5460 * 10000000); + btc = Amount.value('546.0'); assert.strictEqual(btc, 5460 * 10000000); + btc = Amount.value('546.0000'); assert.strictEqual(btc, 5460 * 10000000); @@ -105,6 +135,7 @@ describe('Utils', function() { }); assert.strictEqual(parseFloat('0.15645647') * 1e8, 15645646.999999998); + assert.strictEqual(util.fromFloat(0.15645647, 8), 15645647); assert.strictEqual(util.fromFixed('0.15645647', 8), 15645647); assert.strictEqual(util.toFixed(15645647, 8), '0.15645647'); }); @@ -182,30 +213,6 @@ describe('Utils', function() { assert.deepEqual(b, [0x8e, 0xfe, 0xfe, 0xff, 0x00]); }); - const unsigned = [ - new BN('ffeeffee'), - new BN('001fffeeffeeffee'), - new BN('eeffeeff'), - new BN('001feeffeeffeeff'), - new BN(0), - new BN(1) - ]; - - const signed = [ - new BN('ffeeffee'), - new BN('001fffeeffeeffee'), - new BN('eeffeeff'), - new BN('001feeffeeffeeff'), - new BN(0), - new BN(1), - new BN('ffeeffee').ineg(), - new BN('001fffeeffeeffee').ineg(), - new BN('eeffeeff').ineg(), - new BN('001feeffeeffeeff').ineg(), - new BN(0).ineg(), - new BN(1).ineg() - ]; - for (const num of unsigned) { const bits = num.bitLength();