test: refactor a number of tests.

This commit is contained in:
Christopher Jeffrey 2017-08-09 15:28:03 -07:00
parent 7d4d2e6c7c
commit 2cf45c84cf
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
27 changed files with 2022 additions and 1960 deletions

View File

@ -4,153 +4,46 @@
'use strict'; 'use strict';
const assert = require('assert'); const assert = require('assert');
const digest = require('../lib/crypto/digest');
const aes = require('../lib/crypto/aes'); const aes = require('../lib/crypto/aes');
const pbkdf2 = require('../lib/crypto/pbkdf2');
const ncrypto = require('crypto');
describe('AES', function() { describe('AES', function() {
function pbkdf2key(passphrase, iterations, dkLen, ivLen, alg) { const key = Buffer.from(
const key = pbkdf2.derive( '3a0c0bf669694ac7685e6806eeadee8e56c9b9bd22c3caa81c718ed4bbf809a1',
passphrase, '', iterations, dkLen + ivLen, 'sha512'); 'hex');
return {
key: key.slice(0, dkLen),
iv: key.slice(dkLen, dkLen + ivLen)
};
}
function nencrypt(data, passphrase) { const iv = Buffer.from('6dd26d9045b73c377a9ed2ffeca72ffd', 'hex');
assert(ncrypto, 'No crypto module available.');
assert(passphrase, 'No passphrase.');
if (typeof data === 'string') it('should encrypt and decrypt with 2 blocks', () => {
data = Buffer.from(data, 'utf8'); const data = Buffer.from(
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
'hex');
if (typeof passphrase === 'string') const expected = Buffer.from(''
passphrase = Buffer.from(passphrase, 'utf8'); + '83de502a9c83112ca6383f2214a892a0cdad5ab2b3e192e'
+ '9921ddb126b25262c41f1dcff4d67ccfb40e4116e5a4569c1',
'hex');
const key = pbkdf2key(passphrase, 2048, 32, 16); const ciphertext = aes.encipher(data, key, iv);
const cipher = ncrypto.createCipheriv('aes-256-cbc', key.key, key.iv); assert.deepStrictEqual(ciphertext, expected);
return Buffer.concat([ const plaintext = aes.decipher(ciphertext, key, iv);
cipher.update(data), assert.deepStrictEqual(plaintext, data);
cipher.final()
]);
}
function ndecrypt(data, passphrase) {
assert(ncrypto, 'No crypto module available.');
assert(passphrase, 'No passphrase.');
if (typeof data === 'string')
data = Buffer.from(data, 'hex');
if (typeof passphrase === 'string')
passphrase = Buffer.from(passphrase, 'utf8');
const key = pbkdf2key(passphrase, 2048, 32, 16);
const decipher = ncrypto.createDecipheriv('aes-256-cbc', key.key, key.iv);
return Buffer.concat([
decipher.update(data),
decipher.final()
]);
}
function bencrypt(data, passphrase) {
assert(ncrypto, 'No crypto module available.');
assert(passphrase, 'No passphrase.');
if (typeof data === 'string')
data = Buffer.from(data, 'utf8');
if (typeof passphrase === 'string')
passphrase = Buffer.from(passphrase, 'utf8');
const key = pbkdf2key(passphrase, 2048, 32, 16);
return aes.encipher(data, key.key, key.iv);
}
function bdecrypt(data, passphrase) {
assert(ncrypto, 'No crypto module available.');
assert(passphrase, 'No passphrase.');
if (typeof data === 'string')
data = Buffer.from(data, 'hex');
if (typeof passphrase === 'string')
passphrase = Buffer.from(passphrase, 'utf8');
const key = pbkdf2key(passphrase, 2048, 32, 16);
return aes.decipher(data, key.key, key.iv);
}
function encrypt(data, passphrase) {
assert(ncrypto, 'No crypto module available.');
assert(passphrase, 'No passphrase.');
if (typeof data === 'string')
data = Buffer.from(data, 'utf8');
if (typeof passphrase === 'string')
passphrase = Buffer.from(passphrase, 'utf8');
const key = pbkdf2key(passphrase, 2048, 32, 16);
return aes.encipher(data, key.key, key.iv);
}
function decrypt(data, passphrase) {
assert(ncrypto, 'No crypto module available.');
assert(passphrase, 'No passphrase.');
if (typeof data === 'string')
data = Buffer.from(data, 'hex');
if (typeof passphrase === 'string')
passphrase = Buffer.from(passphrase, 'utf8');
const key = pbkdf2key(passphrase, 2048, 32, 16);
return aes.decipher(data, key.key, key.iv);
}
it('should encrypt and decrypt a hash with 2 blocks', () => {
const hash = digest.sha256(Buffer.alloc(0));
const enchash = encrypt(hash, 'foo');
const dechash = decrypt(enchash, 'foo');
const hash2 = digest.sha256(Buffer.alloc(0));
const enchash2 = nencrypt(hash2, 'foo');
const dechash2 = ndecrypt(enchash2, 'foo');
const hash3 = digest.sha256(Buffer.alloc(0));
const enchash3 = bencrypt(hash3, 'foo');
const dechash3 = bdecrypt(enchash3, 'foo');
assert.deepEqual(hash, hash2);
assert.deepEqual(enchash, enchash2);
assert.deepEqual(dechash, dechash2);
assert.deepEqual(dechash, dechash3);
}); });
it('should encrypt and decrypt a hash with uneven blocks', () => { it('should encrypt and decrypt with uneven blocks', () => {
const hash = Buffer.concat([ const data = Buffer.from(
digest.sha256(Buffer.alloc(0)), 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855010203',
Buffer.from([1,2,3])]); 'hex');
const enchash = encrypt(hash, 'foo'); const expected = Buffer.from(''
const dechash = decrypt(enchash, 'foo'); + '83de502a9c83112ca6383f2214a892a0cdad5ab2b3e192e9'
+ '921ddb126b25262c5211801019a30c0c6f795296923e0af8',
'hex');
const hash2 = Buffer.concat([ const ciphertext = aes.encipher(data, key, iv);
digest.sha256(Buffer.alloc(0)), assert.deepStrictEqual(ciphertext, expected);
Buffer.from([1,2,3])]);
const enchash2 = nencrypt(hash2, 'foo'); const plaintext = aes.decipher(ciphertext, key, iv);
const dechash2 = ndecrypt(enchash2, 'foo'); assert.deepStrictEqual(plaintext, data);
assert.deepEqual(hash, hash2);
assert.deepEqual(enchash, enchash2);
assert.deepEqual(dechash, dechash2);
}); });
}); });

View File

@ -22,7 +22,6 @@
// THE SOFTWARE. // THE SOFTWARE.
/* eslint-env mocha */ /* eslint-env mocha */
/* eslint max-len: "off" */
/* eslint prefer-arrow-callback: "off" */ /* eslint prefer-arrow-callback: "off" */
'use strict'; 'use strict';
@ -33,9 +32,11 @@ const Address = require('../lib/primitives/address');
const validChecksums = [ const validChecksums = [
'A12UEL5L', 'A12UEL5L',
'an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1tt5tgs', 'an83characterlonghumanreadablepartthatcontains'
+ 'thenumber1andtheexcludedcharactersbio1tt5tgs',
'abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw', 'abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw',
'11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j', '11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq'
+ 'qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j',
'split1checkupstagehandshakeupstreamerranterredcaperred2y9e3w' 'split1checkupstagehandshakeupstreamerranterredcaperred2y9e3w'
]; ];
@ -57,7 +58,8 @@ const validAddresses = [
]) ])
], ],
[ [
'bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx', 'bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw50'
+ '8d6qejxtdg4y5r3zarvary0c5xw7k7grplx',
Buffer.from([ Buffer.from([
0x81, 0x28, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, 0x81, 0x28, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54,
0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6, 0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6,
@ -94,7 +96,8 @@ const invalidAddresses = [
'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t5', 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t5',
'BC13W508D6QEJXTDG4Y5R3ZARVARY0C5XW7KN40WF2', 'BC13W508D6QEJXTDG4Y5R3ZARVARY0C5XW7KN40WF2',
'bc1rw5uspcuh', 'bc1rw5uspcuh',
'bc10w508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7kw5rljs90', 'bc10w508d6qejxtdg4y5r3zarvary0c5xw7kw508d'
+ '6qejxtdg4y5r3zarvary0c5xw7kw5rljs90',
'BC1QR508D6QEJXTDG4Y5R3ZARVARYV98GJ9P', 'BC1QR508D6QEJXTDG4Y5R3ZARVARYV98GJ9P',
'tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sL5k7', 'tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sL5k7',
'tb1pw508d6qejxtdg4y5r3zarqfsj6c3', 'tb1pw508d6qejxtdg4y5r3zarqfsj6c3',
@ -140,7 +143,7 @@ describe('Bech32', function() {
for (const [addr, script] of validAddresses) { for (const [addr, script] of validAddresses) {
it(`should have valid address for ${addr}`, () => { it(`should have valid address for ${addr}`, () => {
let hrp = 'bc'; let hrp = 'bc';
let ret; let ret = null;
try { try {
ret = fromAddress(hrp, addr); ret = fromAddress(hrp, addr);
@ -175,14 +178,16 @@ describe('Bech32', function() {
for (const addr of invalidAddresses) { for (const addr of invalidAddresses) {
it(`should have invalid address for ${addr}`, () => { it(`should have invalid address for ${addr}`, () => {
let ok1; let ok1 = null;
try { try {
ok1 = fromAddress('bc', addr); ok1 = fromAddress('bc', addr);
} catch (e) { } catch (e) {
ok1 = null; ok1 = null;
} }
let ok2; let ok2 = null;
try { try {
ok2 = fromAddress('tb', addr); ok2 = fromAddress('tb', addr);
} catch (e) { } catch (e) {
@ -196,7 +201,7 @@ describe('Bech32', function() {
for (const [addr, script] of validAddresses) { for (const [addr, script] of validAddresses) {
it(`should have valid address for ${addr}`, () => { it(`should have valid address for ${addr}`, () => {
let ret; let ret = null;
try { try {
ret = Address.fromBech32(addr, 'main'); ret = Address.fromBech32(addr, 'main');
@ -230,14 +235,16 @@ describe('Bech32', function() {
for (const addr of invalidAddresses) { for (const addr of invalidAddresses) {
it(`should have invalid address for ${addr}`, () => { it(`should have invalid address for ${addr}`, () => {
let ok1; let ok1 = null;
try { try {
ok1 = Address.fromBech32(addr, 'main'); ok1 = Address.fromBech32(addr, 'main');
} catch (e) { } catch (e) {
ok1 = null; ok1 = null;
} }
let ok2; let ok2 = null;
try { try {
ok2 = Address.fromBech32(addr, 'testnet'); ok2 = Address.fromBech32(addr, 'testnet');
} catch (e) { } catch (e) {

View File

@ -8,24 +8,24 @@ const secp256k1 = require('../lib/crypto/secp256k1');
const BIP150 = require('../lib/net/bip150'); const BIP150 = require('../lib/net/bip150');
const BIP151 = require('../lib/net/bip151'); const BIP151 = require('../lib/net/bip151');
const db = new BIP150.AuthDB();
const ck = secp256k1.generatePrivateKey();
const sk = secp256k1.generatePrivateKey();
db.addAuthorized(secp256k1.publicKeyCreate(ck, true));
db.addKnown('127.0.0.2', secp256k1.publicKeyCreate(sk, true));
const client = new BIP151();
const server = new BIP151();
client.bip150 = new BIP150(client, '127.0.0.2', true, db, ck);
server.bip150 = new BIP150(server, '127.0.0.1', false, db, sk);
function payload() {
return Buffer.from('deadbeef', 'hex');
}
describe('BIP150', function() { describe('BIP150', function() {
const db = new BIP150.AuthDB();
const ck = secp256k1.generatePrivateKey();
const sk = secp256k1.generatePrivateKey();
db.addAuthorized(secp256k1.publicKeyCreate(ck, true));
db.addKnown('127.0.0.2', secp256k1.publicKeyCreate(sk, true));
const client = new BIP151();
const server = new BIP151();
client.bip150 = new BIP150(client, '127.0.0.2', true, db, ck);
server.bip150 = new BIP150(server, '127.0.0.1', false, db, sk);
function payload() {
return Buffer.from('deadbeef', 'hex');
}
it('should do encinit', () => { it('should do encinit', () => {
const init = server.toEncinit(); const init = server.toEncinit();
client.encinit(init.publicKey, init.cipher); client.encinit(init.publicKey, init.cipher);
@ -69,8 +69,8 @@ describe('BIP150', function() {
let emitted = false; let emitted = false;
server.once('packet', (cmd, body) => { server.once('packet', (cmd, body) => {
emitted = true; emitted = true;
assert.equal(cmd, 'fake'); assert.strictEqual(cmd, 'fake');
assert.equal(body.toString('hex'), 'deadbeef'); assert.strictEqual(body.toString('hex'), 'deadbeef');
}); });
server.feed(packet); server.feed(packet);
assert(emitted); assert(emitted);
@ -81,8 +81,8 @@ describe('BIP150', function() {
let emitted = false; let emitted = false;
client.once('packet', (cmd, body) => { client.once('packet', (cmd, body) => {
emitted = true; emitted = true;
assert.equal(cmd, 'fake'); assert.strictEqual(cmd, 'fake');
assert.equal(body.toString('hex'), 'deadbeef'); assert.strictEqual(body.toString('hex'), 'deadbeef');
}); });
client.feed(packet); client.feed(packet);
assert(emitted); assert(emitted);
@ -93,8 +93,8 @@ describe('BIP150', function() {
let emitted = false; let emitted = false;
server.once('packet', (cmd, body) => { server.once('packet', (cmd, body) => {
emitted = true; emitted = true;
assert.equal(cmd, 'fake'); assert.strictEqual(cmd, 'fake');
assert.equal(body.toString('hex'), 'deadbeef'); assert.strictEqual(body.toString('hex'), 'deadbeef');
}); });
server.feed(packet); server.feed(packet);
assert(emitted); assert(emitted);
@ -105,8 +105,8 @@ describe('BIP150', function() {
let emitted = false; let emitted = false;
client.once('packet', (cmd, body) => { client.once('packet', (cmd, body) => {
emitted = true; emitted = true;
assert.equal(cmd, 'fake'); assert.strictEqual(cmd, 'fake');
assert.equal(body.toString('hex'), 'deadbeef'); assert.strictEqual(body.toString('hex'), 'deadbeef');
}); });
client.feed(packet); client.feed(packet);
assert(emitted); assert(emitted);
@ -122,7 +122,7 @@ describe('BIP150', function() {
let emitted = false; let emitted = false;
server.once('packet', (cmd, body) => { server.once('packet', (cmd, body) => {
emitted = true; emitted = true;
assert.equal(cmd, 'encack'); assert.strictEqual(cmd, 'encack');
server.encack(body); server.encack(body);
}); });
server.feed(packet); server.feed(packet);
@ -144,8 +144,8 @@ describe('BIP150', function() {
let emitted = false; let emitted = false;
server.once('packet', (cmd, body) => { server.once('packet', (cmd, body) => {
emitted = true; emitted = true;
assert.equal(cmd, 'fake'); assert.strictEqual(cmd, 'fake');
assert.equal(body.toString('hex'), 'deadbeef'); assert.strictEqual(body.toString('hex'), 'deadbeef');
}); });
server.feed(packet); server.feed(packet);
assert(emitted); assert(emitted);
@ -156,8 +156,8 @@ describe('BIP150', function() {
let emitted = false; let emitted = false;
client.once('packet', (cmd, body) => { client.once('packet', (cmd, body) => {
emitted = true; emitted = true;
assert.equal(cmd, 'fake'); assert.strictEqual(cmd, 'fake');
assert.equal(body.toString('hex'), 'deadbeef'); assert.strictEqual(body.toString('hex'), 'deadbeef');
}); });
client.feed(packet); client.feed(packet);
assert(emitted); assert(emitted);
@ -168,8 +168,8 @@ describe('BIP150', function() {
let emitted = false; let emitted = false;
server.once('packet', (cmd, body) => { server.once('packet', (cmd, body) => {
emitted = true; emitted = true;
assert.equal(cmd, 'fake'); assert.strictEqual(cmd, 'fake');
assert.equal(body.toString('hex'), 'deadbeef'); assert.strictEqual(body.toString('hex'), 'deadbeef');
}); });
server.feed(packet); server.feed(packet);
assert(emitted); assert(emitted);
@ -180,8 +180,8 @@ describe('BIP150', function() {
let emitted = false; let emitted = false;
client.once('packet', (cmd, body) => { client.once('packet', (cmd, body) => {
emitted = true; emitted = true;
assert.equal(cmd, 'fake'); assert.strictEqual(cmd, 'fake');
assert.equal(body.toString('hex'), 'deadbeef'); assert.strictEqual(body.toString('hex'), 'deadbeef');
}); });
client.feed(packet); client.feed(packet);
assert(emitted); assert(emitted);
@ -194,13 +194,13 @@ describe('BIP150', function() {
let semitted = false; let semitted = false;
client.once('packet', (cmd, body) => { client.once('packet', (cmd, body) => {
cemitted = true; cemitted = true;
assert.equal(cmd, 'fake'); assert.strictEqual(cmd, 'fake');
assert.equal(body.toString('hex'), 'deadbeef'); assert.strictEqual(body.toString('hex'), 'deadbeef');
}); });
server.once('packet', (cmd, body) => { server.once('packet', (cmd, body) => {
semitted = true; semitted = true;
assert.equal(cmd, 'fake'); assert.strictEqual(cmd, 'fake');
assert.equal(body.toString('hex'), 'deadbeef'); assert.strictEqual(body.toString('hex'), 'deadbeef');
}); });
client.feed(spacket); client.feed(spacket);
server.feed(cpacket); server.feed(cpacket);

View File

@ -6,14 +6,14 @@
const assert = require('assert'); const assert = require('assert');
const BIP151 = require('../lib/net/bip151'); const BIP151 = require('../lib/net/bip151');
const client = new BIP151();
const server = new BIP151();
function payload() {
return Buffer.from('deadbeef', 'hex');
}
describe('BIP151', function() { describe('BIP151', function() {
const client = new BIP151();
const server = new BIP151();
function payload() {
return Buffer.from('deadbeef', 'hex');
}
it('should do encinit', () => { it('should do encinit', () => {
let init = server.toEncinit(); let init = server.toEncinit();
client.encinit(init.publicKey, init.cipher); client.encinit(init.publicKey, init.cipher);
@ -44,8 +44,8 @@ describe('BIP151', function() {
let emitted = false; let emitted = false;
server.once('packet', (cmd, body) => { server.once('packet', (cmd, body) => {
emitted = true; emitted = true;
assert.equal(cmd, 'fake'); assert.strictEqual(cmd, 'fake');
assert.equal(body.toString('hex'), 'deadbeef'); assert.strictEqual(body.toString('hex'), 'deadbeef');
}); });
server.feed(packet); server.feed(packet);
assert(emitted); assert(emitted);
@ -56,8 +56,8 @@ describe('BIP151', function() {
let emitted = false; let emitted = false;
client.once('packet', (cmd, body) => { client.once('packet', (cmd, body) => {
emitted = true; emitted = true;
assert.equal(cmd, 'fake'); assert.strictEqual(cmd, 'fake');
assert.equal(body.toString('hex'), 'deadbeef'); assert.strictEqual(body.toString('hex'), 'deadbeef');
}); });
client.feed(packet); client.feed(packet);
assert(emitted); assert(emitted);
@ -68,8 +68,8 @@ describe('BIP151', function() {
let emitted = false; let emitted = false;
server.once('packet', (cmd, body) => { server.once('packet', (cmd, body) => {
emitted = true; emitted = true;
assert.equal(cmd, 'fake'); assert.strictEqual(cmd, 'fake');
assert.equal(body.toString('hex'), 'deadbeef'); assert.strictEqual(body.toString('hex'), 'deadbeef');
}); });
server.feed(packet); server.feed(packet);
assert(emitted); assert(emitted);
@ -80,8 +80,8 @@ describe('BIP151', function() {
let emitted = false; let emitted = false;
client.once('packet', (cmd, body) => { client.once('packet', (cmd, body) => {
emitted = true; emitted = true;
assert.equal(cmd, 'fake'); assert.strictEqual(cmd, 'fake');
assert.equal(body.toString('hex'), 'deadbeef'); assert.strictEqual(body.toString('hex'), 'deadbeef');
}); });
client.feed(packet); client.feed(packet);
assert(emitted); assert(emitted);
@ -97,7 +97,7 @@ describe('BIP151', function() {
let emitted = false; let emitted = false;
server.once('packet', (cmd, body) => { server.once('packet', (cmd, body) => {
emitted = true; emitted = true;
assert.equal(cmd, 'encack'); assert.strictEqual(cmd, 'encack');
server.encack(body); server.encack(body);
}); });
server.feed(packet); server.feed(packet);
@ -119,8 +119,8 @@ describe('BIP151', function() {
let emitted = false; let emitted = false;
server.once('packet', (cmd, body) => { server.once('packet', (cmd, body) => {
emitted = true; emitted = true;
assert.equal(cmd, 'fake'); assert.strictEqual(cmd, 'fake');
assert.equal(body.toString('hex'), 'deadbeef'); assert.strictEqual(body.toString('hex'), 'deadbeef');
}); });
server.feed(packet); server.feed(packet);
assert(emitted); assert(emitted);
@ -131,8 +131,8 @@ describe('BIP151', function() {
let emitted = false; let emitted = false;
client.once('packet', (cmd, body) => { client.once('packet', (cmd, body) => {
emitted = true; emitted = true;
assert.equal(cmd, 'fake'); assert.strictEqual(cmd, 'fake');
assert.equal(body.toString('hex'), 'deadbeef'); assert.strictEqual(body.toString('hex'), 'deadbeef');
}); });
client.feed(packet); client.feed(packet);
assert(emitted); assert(emitted);
@ -143,8 +143,8 @@ describe('BIP151', function() {
let emitted = false; let emitted = false;
server.once('packet', (cmd, body) => { server.once('packet', (cmd, body) => {
emitted = true; emitted = true;
assert.equal(cmd, 'fake'); assert.strictEqual(cmd, 'fake');
assert.equal(body.toString('hex'), 'deadbeef'); assert.strictEqual(body.toString('hex'), 'deadbeef');
}); });
server.feed(packet); server.feed(packet);
assert(emitted); assert(emitted);
@ -155,8 +155,8 @@ describe('BIP151', function() {
let emitted = false; let emitted = false;
client.once('packet', (cmd, body) => { client.once('packet', (cmd, body) => {
emitted = true; emitted = true;
assert.equal(cmd, 'fake'); assert.strictEqual(cmd, 'fake');
assert.equal(body.toString('hex'), 'deadbeef'); assert.strictEqual(body.toString('hex'), 'deadbeef');
}); });
client.feed(packet); client.feed(packet);
assert(emitted); assert(emitted);
@ -169,13 +169,13 @@ describe('BIP151', function() {
let semitted = false; let semitted = false;
client.once('packet', (cmd, body) => { client.once('packet', (cmd, body) => {
cemitted = true; cemitted = true;
assert.equal(cmd, 'fake'); assert.strictEqual(cmd, 'fake');
assert.equal(body.toString('hex'), 'deadbeef'); assert.strictEqual(body.toString('hex'), 'deadbeef');
}); });
server.once('packet', (cmd, body) => { server.once('packet', (cmd, body) => {
semitted = true; semitted = true;
assert.equal(cmd, 'fake'); assert.strictEqual(cmd, 'fake');
assert.equal(body.toString('hex'), 'deadbeef'); assert.strictEqual(body.toString('hex'), 'deadbeef');
}); });
client.feed(spacket); client.feed(spacket);
server.feed(cpacket); server.feed(cpacket);

View File

@ -28,22 +28,21 @@ x509.verifyTime = function() {
return true; return true;
}; };
function testRequest(data) {
const req = bip70.PaymentRequest.fromRaw(data);
assert.strictEqual(req.pkiType, 'x509+sha256');
assert(req.pkiData);
assert(req.getChain());
assert(req.paymentDetails);
assert(req.paymentDetails.memo.length !== 0);
assert(req.paymentDetails.paymentUrl.length !== 0);
assert.deepStrictEqual(req.toRaw(), data);
assert(req.verify());
}
describe('BIP70', function() { describe('BIP70', function() {
function testRequest(data) {
const req = bip70.PaymentRequest.fromRaw(data);
assert.equal(req.pkiType, 'x509+sha256');
assert(req.pkiData);
assert(req.getChain());
assert(req.paymentDetails);
assert(req.paymentDetails.memo.length !== 0);
assert(req.paymentDetails.paymentUrl.length !== 0);
const raw = req.toRaw();
assert.equal(raw.toString('hex'), data.toString('hex'));
assert(req.verify());
}
it('should parse and verify a payment request', () => { it('should parse and verify a payment request', () => {
testRequest(tests.valid); testRequest(tests.valid);
testRequest(tests.invalid); testRequest(tests.invalid);
@ -53,14 +52,14 @@ describe('BIP70', function() {
it('should verify cert chain', () => { it('should verify cert chain', () => {
const req1 = bip70.PaymentRequest.fromRaw(tests.valid); const req1 = bip70.PaymentRequest.fromRaw(tests.valid);
assert.equal(req1.version, 1); assert.strictEqual(req1.version, 1);
assert.equal(req1.getChain().length, 4); assert.strictEqual(req1.getChain().length, 4);
assert.equal(req1.paymentDetails.paymentUrl, assert.strictEqual(req1.paymentDetails.paymentUrl,
'https://test.bitpay.com/i/CMWpuFsjgmQ2ZLiyGfcF1W'); 'https://test.bitpay.com/i/CMWpuFsjgmQ2ZLiyGfcF1W');
assert.equal(req1.paymentDetails.network, 'test'); assert.strictEqual(req1.paymentDetails.network, 'test');
assert.equal(req1.paymentDetails.time, 1408645830); assert.strictEqual(req1.paymentDetails.time, 1408645830);
assert.equal(req1.paymentDetails.expires, 1408646730); assert.strictEqual(req1.paymentDetails.expires, 1408646730);
assert.equal(req1.paymentDetails.outputs.length, 1); assert.strictEqual(req1.paymentDetails.outputs.length, 1);
assert(!req1.paymentDetails.merchantData); assert(!req1.paymentDetails.merchantData);
assert(req1.paymentDetails.isExpired()); assert(req1.paymentDetails.isExpired());
@ -68,37 +67,37 @@ describe('BIP70', function() {
const req2 = bip70.PaymentRequest.fromRaw(tests.invalid); const req2 = bip70.PaymentRequest.fromRaw(tests.invalid);
assert.equal(req2.version, 1); assert.strictEqual(req2.version, 1);
assert.equal(req2.getChain().length, 3); assert.strictEqual(req2.getChain().length, 3);
assert.equal(req2.paymentDetails.paymentUrl, assert.strictEqual(req2.paymentDetails.paymentUrl,
'https://bitpay.com/i/PAQtNxX7KL8BtJBnfXyTaH'); 'https://bitpay.com/i/PAQtNxX7KL8BtJBnfXyTaH');
assert.equal(req2.paymentDetails.network, 'main'); assert.strictEqual(req2.paymentDetails.network, 'main');
assert.equal(req2.paymentDetails.time, 1442409238); assert.strictEqual(req2.paymentDetails.time, 1442409238);
assert.equal(req2.paymentDetails.expires, 1442410138); assert.strictEqual(req2.paymentDetails.expires, 1442410138);
assert.equal(req2.paymentDetails.outputs.length, 1); assert.strictEqual(req2.paymentDetails.outputs.length, 1);
assert.equal(req2.paymentDetails.merchantData.length, 76); assert.strictEqual(req2.paymentDetails.merchantData.length, 76);
assert(req2.paymentDetails.getData('json')); assert(req2.paymentDetails.getData('json'));
assert(req2.paymentDetails.isExpired()); assert(req2.paymentDetails.isExpired());
assert(req2.verifyChain()); assert(req2.verifyChain());
req2.paymentDetails.setData({foo:1}, 'json'); req2.paymentDetails.setData({foo:1}, 'json');
assert.equal(req2.paymentDetails.merchantData.length, 9); assert.strictEqual(req2.paymentDetails.merchantData.length, 9);
assert.deepStrictEqual(req2.paymentDetails.getData('json'), {foo:1}); assert.deepStrictEqual(req2.paymentDetails.getData('json'), {foo:1});
assert(!req2.verify()); assert(!req2.verify());
const req3 = bip70.PaymentRequest.fromRaw(tests.untrusted); const req3 = bip70.PaymentRequest.fromRaw(tests.untrusted);
assert.equal(req3.version, -1); assert.strictEqual(req3.version, -1);
assert.equal(req3.getChain().length, 2); assert.strictEqual(req3.getChain().length, 2);
assert.equal(req3.paymentDetails.paymentUrl, assert.strictEqual(req3.paymentDetails.paymentUrl,
'https://www.coinbase.com/rp/55f9ca703d5d80008c0001f4'); 'https://www.coinbase.com/rp/55f9ca703d5d80008c0001f4');
assert.equal(req3.paymentDetails.network, null); assert.strictEqual(req3.paymentDetails.network, null);
assert.equal(req3.paymentDetails.time, 1442433682); assert.strictEqual(req3.paymentDetails.time, 1442433682);
assert.equal(req3.paymentDetails.expires, 1442434548); assert.strictEqual(req3.paymentDetails.expires, 1442434548);
assert.equal(req3.paymentDetails.outputs.length, 1); assert.strictEqual(req3.paymentDetails.outputs.length, 1);
assert.equal(req3.paymentDetails.merchantData.length, 32); assert.strictEqual(req3.paymentDetails.merchantData.length, 32);
assert.equal(req3.paymentDetails.getData('utf8'), assert.strictEqual(req3.paymentDetails.getData('utf8'),
'bb79b6f2310e321bd3b1d929edbeb358'); 'bb79b6f2310e321bd3b1d929edbeb358');
assert(req3.paymentDetails.isExpired()); assert(req3.paymentDetails.isExpired());
@ -134,8 +133,8 @@ describe('BIP70', function() {
it('should get chain and ca for request', () => { it('should get chain and ca for request', () => {
const req = bip70.PaymentRequest.fromRaw(tests.valid); const req = bip70.PaymentRequest.fromRaw(tests.valid);
assert.equal(req.getChain().length, 4); assert.strictEqual(req.getChain().length, 4);
assert.equal(req.getCA().name, assert.strictEqual(req.getCA().name,
'Go Daddy Class 2 Certification Authority'); 'Go Daddy Class 2 Certification Authority');
}); });
@ -145,16 +144,16 @@ describe('BIP70', function() {
const req2 = bip70.PaymentRequest.fromRaw(tests.untrusted); const req2 = bip70.PaymentRequest.fromRaw(tests.untrusted);
assert(req2.verifyChain()); assert(req2.verifyChain());
assert.equal(req2.getCA().name, assert.strictEqual(req2.getCA().name,
'DigiCert SHA2 Extended Validation Server CA'); 'DigiCert SHA2 Extended Validation Server CA');
}); });
it('should parse a payment ack', () => { it('should parse a payment ack', () => {
const ack = bip70.PaymentACK.fromRaw(tests.ack); const ack = bip70.PaymentACK.fromRaw(tests.ack);
assert.equal(ack.memo.length, 95); assert.strictEqual(ack.memo.length, 95);
assert.equal(ack.memo, 'Transaction received by BitPay.' assert.strictEqual(ack.memo, 'Transaction received by BitPay.'
+ ' Invoice will be marked as paid if the transaction is confirmed.'); + ' Invoice will be marked as paid if the transaction is confirmed.');
assert.equal(ack.toRaw().toString('hex'), tests.ack.toString('hex')); assert.deepStrictEqual(ack.toRaw(), tests.ack);
}); });
it('should create a payment request, sign, and verify', () => { it('should create a payment request, sign, and verify', () => {
@ -162,7 +161,7 @@ describe('BIP70', function() {
version: 25, version: 25,
paymentDetails: { paymentDetails: {
network: 'testnet', network: 'testnet',
paymentUrl: 'http://bcoin.io/payme', paymentUrl: 'http://bcoin.io/payment',
memo: 'foobar', memo: 'foobar',
time: util.now(), time: util.now(),
expires: util.now() + 3600, expires: util.now() + 3600,
@ -174,21 +173,21 @@ describe('BIP70', function() {
} }
}); });
assert.equal(req.pkiType, null); assert.strictEqual(req.pkiType, null);
assert(!req.pkiData); assert(!req.pkiData);
assert.equal(req.getChain().length, 0); assert.strictEqual(req.getChain().length, 0);
assert(req.paymentDetails); assert(req.paymentDetails);
assert(req.paymentDetails.memo.length !== 0); assert(req.paymentDetails.memo.length !== 0);
assert(req.paymentDetails.paymentUrl.length !== 0); assert(req.paymentDetails.paymentUrl.length !== 0);
assert.deepStrictEqual(req.paymentDetails.getData('json'), {foo:'bar'}); assert.deepStrictEqual(req.paymentDetails.getData('json'), {foo:'bar'});
assert.equal(req.version, 25); assert.strictEqual(req.version, 25);
assert.equal(req.paymentDetails.paymentUrl, 'http://bcoin.io/payme'); assert.strictEqual(req.paymentDetails.paymentUrl, 'http://bcoin.io/payment');
assert.equal(req.paymentDetails.network, 'testnet'); assert.strictEqual(req.paymentDetails.network, 'testnet');
assert(req.paymentDetails.time <= util.now()); assert(req.paymentDetails.time <= util.now());
assert.equal(req.paymentDetails.expires, assert.strictEqual(req.paymentDetails.expires,
req.paymentDetails.time + 3600); req.paymentDetails.time + 3600);
assert.equal(req.paymentDetails.outputs.length, 2); assert.strictEqual(req.paymentDetails.outputs.length, 2);
assert(req.paymentDetails.merchantData); assert(req.paymentDetails.merchantData);
assert(!req.paymentDetails.isExpired()); assert(!req.paymentDetails.isExpired());
@ -197,8 +196,8 @@ describe('BIP70', function() {
req.sign(tests.ca.priv); req.sign(tests.ca.priv);
assert(req.pkiData); assert(req.pkiData);
assert.equal(req.pkiType, 'x509+sha256'); assert.strictEqual(req.pkiType, 'x509+sha256');
assert.equal(req.getChain().length, 1); assert.strictEqual(req.getChain().length, 1);
assert(req.verify()); assert(req.verify());
assert(!req.verifyChain()); assert(!req.verifyChain());
@ -207,7 +206,7 @@ describe('BIP70', function() {
x509.setTrust([tests.ca.crt]); x509.setTrust([tests.ca.crt]);
assert(req.verifyChain()); assert(req.verifyChain());
assert.equal(req.getCA().name, 'JJs CA'); assert.strictEqual(req.getCA().name, 'JJs CA');
req.version = 24; req.version = 24;
assert(!req.verify()); assert(!req.verify());

View File

@ -1,11 +1,10 @@
/* eslint-env mocha */ /* eslint-env mocha */
/* eslint max-len: "off" */
/* eslint prefer-arrow-callback: "off" */ /* eslint prefer-arrow-callback: "off" */
'use strict'; 'use strict';
const assert = require('assert'); const assert = require('assert');
const fs = require('fs'); const fs = require('../lib/utils/fs');
const common = require('./util/common'); const common = require('./util/common');
const Bloom = require('../lib/utils/bloom'); const Bloom = require('../lib/utils/bloom');
const Block = require('../lib/primitives/block'); const Block = require('../lib/primitives/block');
@ -53,15 +52,15 @@ describe('Block', function() {
const tree = mblock.getTree(); const tree = mblock.getTree();
assert.equal(tree.matches.length, 2); assert.strictEqual(tree.matches.length, 2);
assert.equal(mblock.hash('hex'), assert.strictEqual(mblock.hash('hex'),
'8cc72c02a958de5a8b35a23bb7e3bced8bf840cc0a4e1c820000000000000000'); '8cc72c02a958de5a8b35a23bb7e3bced8bf840cc0a4e1c820000000000000000');
assert.equal(mblock.rhash(), assert.strictEqual(mblock.rhash(),
'0000000000000000821c4e0acc40f88bedbce3b73ba2358b5ade58a9022cc78c'); '0000000000000000821c4e0acc40f88bedbce3b73ba2358b5ade58a9022cc78c');
assert.equal( assert.strictEqual(
tree.matches[0].toString('hex'), tree.matches[0].toString('hex'),
'7393f84cd04ca8931975c66282ebf1847c78d8de6c2578d4f9bae23bc6f30857'); '7393f84cd04ca8931975c66282ebf1847c78d8de6c2578d4f9bae23bc6f30857');
assert.equal( assert.strictEqual(
tree.matches[1].toString('hex'), tree.matches[1].toString('hex'),
'ec8c51de3170301430ec56f6703533d9ea5b05c6fa7068954bcb90eed8c2ee5c'); 'ec8c51de3170301430ec56f6703533d9ea5b05c6fa7068954bcb90eed8c2ee5c');
}); });
@ -69,8 +68,8 @@ describe('Block', function() {
it('should decode/encode merkle block', () => { it('should decode/encode merkle block', () => {
const merkle = MerkleBlock.fromRaw(merkle300025); const merkle = MerkleBlock.fromRaw(merkle300025);
merkle.refresh(); merkle.refresh();
assert.deepEqual(merkle.toRaw(), merkle300025); assert.deepStrictEqual(merkle.toRaw(), merkle300025);
assert.deepEqual(merkle300025, mblock.toRaw()); assert.deepStrictEqual(merkle300025, mblock.toRaw());
}); });
it('should be verify merkle block', () => { it('should be verify merkle block', () => {
@ -81,14 +80,14 @@ describe('Block', function() {
it('should be encoded/decoded and still verify', () => { it('should be encoded/decoded and still verify', () => {
const raw = mblock.toRaw(); const raw = mblock.toRaw();
const merkle = MerkleBlock.fromRaw(raw); const merkle = MerkleBlock.fromRaw(raw);
assert.deepEqual(merkle.toRaw(), raw); assert.deepStrictEqual(merkle.toRaw(), raw);
assert(merkle.verify()); assert(merkle.verify());
}); });
it('should be jsonified/unjsonified and still verify', () => { it('should be jsonified/unjsonified and still verify', () => {
const json = mblock.toJSON(); const json = mblock.toJSON();
const merkle = MerkleBlock.fromJSON(json); const merkle = MerkleBlock.fromJSON(json);
assert.deepEqual(merkle.toJSON(), json); assert.deepStrictEqual(merkle.toJSON(), json);
assert(merkle.verify()); assert(merkle.verify());
}); });
@ -105,17 +104,17 @@ describe('Block', function() {
height++; height++;
} }
assert.equal(height, 6930000); assert.strictEqual(height, 6930000);
assert.equal(total, 2099999997690000); assert.strictEqual(total, 2099999997690000);
}); });
it('should parse JSON', () => { it('should parse JSON', () => {
const block = Block.fromJSON(Block.fromRaw(block300025).toJSON()); const block = Block.fromJSON(Block.fromRaw(block300025).toJSON());
assert.equal(block.hash('hex'), assert.strictEqual(block.hash('hex'),
'8cc72c02a958de5a8b35a23bb7e3bced8bf840cc0a4e1c820000000000000000'); '8cc72c02a958de5a8b35a23bb7e3bced8bf840cc0a4e1c820000000000000000');
assert.equal(block.rhash(), assert.strictEqual(block.rhash(),
'0000000000000000821c4e0acc40f88bedbce3b73ba2358b5ade58a9022cc78c'); '0000000000000000821c4e0acc40f88bedbce3b73ba2358b5ade58a9022cc78c');
assert.equal(block.merkleRoot, block.createMerkleRoot('hex')); assert.strictEqual(block.merkleRoot, block.createMerkleRoot('hex'));
}); });
it('should create a merkle block', () => { it('should create a merkle block', () => {
@ -132,7 +131,7 @@ describe('Block', function() {
const merkle = MerkleBlock.fromBlock(block, filter); const merkle = MerkleBlock.fromBlock(block, filter);
assert(merkle.verifyBody()); assert(merkle.verifyBody());
assert.deepEqual(merkle.toRaw(), mblock.toRaw()); assert.deepStrictEqual(merkle.toRaw(), mblock.toRaw());
}); });
it('should verify a historical block', () => { it('should verify a historical block', () => {
@ -146,7 +145,7 @@ describe('Block', function() {
assert(block.txs[0].isCoinbase()); assert(block.txs[0].isCoinbase());
assert(block.txs[0].isSane()); assert(block.txs[0].isSane());
assert(!block.hasWitness()); assert(!block.hasWitness());
assert.equal(block.getWeight(), 1136924); assert.strictEqual(block.getWeight(), 1136924);
let sigops = 0; let sigops = 0;
let reward = 0; let reward = 0;
@ -164,9 +163,9 @@ describe('Block', function() {
reward += consensus.getReward(height, 210000); reward += consensus.getReward(height, 210000);
assert.equal(sigops, 5280); assert.strictEqual(sigops, 5280);
assert.equal(reward, 2507773345); assert.strictEqual(reward, 2507773345);
assert.equal(reward, block.txs[0].outputs[0].value); assert.strictEqual(reward, block.txs[0].outputs[0].value);
}); });
it('should fail with a bad merkle root', () => { it('should fail with a bad merkle root', () => {
@ -175,7 +174,7 @@ describe('Block', function() {
block2.refresh(); block2.refresh();
assert(!block2.verifyPOW()); assert(!block2.verifyPOW());
const [, reason] = block2.checkBody(); const [, reason] = block2.checkBody();
assert.equal(reason, 'bad-txnmrklroot'); assert.strictEqual(reason, 'bad-txnmrklroot');
assert(!block2.verify()); assert(!block2.verify());
block2.merkleRoot = block.merkleRoot; block2.merkleRoot = block.merkleRoot;
block2.refresh(); block2.refresh();
@ -188,7 +187,7 @@ describe('Block', function() {
mblock2.refresh(); mblock2.refresh();
assert(!mblock2.verifyPOW()); assert(!mblock2.verifyPOW());
const [, reason] = mblock2.checkBody(); const [, reason] = mblock2.checkBody();
assert.equal(reason, 'bad-txnmrklroot'); assert.strictEqual(reason, 'bad-txnmrklroot');
assert(!mblock2.verify()); assert(!mblock2.verify());
mblock2.merkleRoot = mblock.merkleRoot; mblock2.merkleRoot = mblock.merkleRoot;
mblock2.refresh(); mblock2.refresh();
@ -212,7 +211,7 @@ describe('Block', function() {
block2.txs.push(block2.txs[block2.txs.length - 1]); block2.txs.push(block2.txs[block2.txs.length - 1]);
block2.refresh(); block2.refresh();
const [, reason] = block2.checkBody(); const [, reason] = block2.checkBody();
assert.equal(reason, 'bad-txns-duplicate'); assert.strictEqual(reason, 'bad-txns-duplicate');
}); });
it('should verify with headers', () => { it('should verify with headers', () => {
@ -229,8 +228,8 @@ describe('Block', function() {
assert(cblock1.init()); assert(cblock1.init());
assert.deepEqual(cblock1.toRaw(), compact426884); assert.deepStrictEqual(cblock1.toRaw(), compact426884);
assert.deepEqual(cblock2.toRaw(), compact426884); assert.deepStrictEqual(cblock2.toRaw(), compact426884);
const map = new Map(); const map = new Map();
@ -245,9 +244,7 @@ describe('Block', function() {
for (const tx of cblock1.available) for (const tx of cblock1.available)
assert(tx); assert(tx);
assert.equal( assert.deepStrictEqual(cblock1.toBlock().toRaw(), block.toRaw());
cblock1.toBlock().toRaw().toString('hex'),
block.toRaw().toString('hex'));
}); });
it('should handle half-full compact block', () => { it('should handle half-full compact block', () => {
@ -257,8 +254,8 @@ describe('Block', function() {
assert(cblock1.init()); assert(cblock1.init());
assert.deepEqual(cblock1.toRaw(), compact426884); assert.deepStrictEqual(cblock1.toRaw(), compact426884);
assert.deepEqual(cblock2.toRaw(), compact426884); assert.deepStrictEqual(cblock2.toRaw(), compact426884);
const map = new Map(); const map = new Map();
@ -271,10 +268,10 @@ describe('Block', function() {
assert(!full); assert(!full);
let req = cblock1.toRequest(); let req = cblock1.toRequest();
assert.equal(req.hash, cblock1.hash('hex')); assert.strictEqual(req.hash, cblock1.hash('hex'));
req = TXRequest.fromRaw(req.toRaw()); req = TXRequest.fromRaw(req.toRaw());
assert.equal(req.hash, cblock1.hash('hex')); assert.strictEqual(req.hash, cblock1.hash('hex'));
let res = TXResponse.fromBlock(block, req); let res = TXResponse.fromBlock(block, req);
res = TXResponse.fromRaw(res.toRaw()); res = TXResponse.fromRaw(res.toRaw());
@ -285,9 +282,7 @@ describe('Block', function() {
for (const tx of cblock1.available) for (const tx of cblock1.available)
assert(tx); assert(tx);
assert.equal( assert.deepStrictEqual(cblock1.toBlock().toRaw(), block.toRaw());
cblock1.toBlock().toRaw().toString('hex'),
block.toRaw().toString('hex'));
}); });
it('should handle compact block', () => { it('should handle compact block', () => {
@ -297,10 +292,10 @@ describe('Block', function() {
assert(cblock1.init()); assert(cblock1.init());
assert.deepEqual(cblock1.toRaw(), compact898352); assert.deepStrictEqual(cblock1.toRaw(), compact898352);
assert.deepEqual(cblock2.toRaw(), compact898352); assert.deepStrictEqual(cblock2.toRaw(), compact898352);
assert.equal(cblock1.sid(block.txs[1].hash()), 125673511480291); assert.strictEqual(cblock1.sid(block.txs[1].hash()), 125673511480291);
const map = new Map(); const map = new Map();
@ -315,9 +310,7 @@ describe('Block', function() {
for (const tx of cblock1.available) for (const tx of cblock1.available)
assert(tx); assert(tx);
assert.equal( assert.deepStrictEqual(cblock1.toBlock().toRaw(), block.toRaw());
cblock1.toBlock().toRaw().toString('hex'),
block.toRaw().toString('hex'));
}); });
it('should handle half-full compact block', () => { it('should handle half-full compact block', () => {
@ -327,10 +320,10 @@ describe('Block', function() {
assert(cblock1.init()); assert(cblock1.init());
assert.deepEqual(cblock1.toRaw(), compact898352); assert.deepStrictEqual(cblock1.toRaw(), compact898352);
assert.deepEqual(cblock2.toRaw(), compact898352); assert.deepStrictEqual(cblock2.toRaw(), compact898352);
assert.equal(cblock1.sid(block.txs[1].hash()), 125673511480291); assert.strictEqual(cblock1.sid(block.txs[1].hash()), 125673511480291);
const map = new Map(); const map = new Map();
@ -343,12 +336,12 @@ describe('Block', function() {
assert(!full); assert(!full);
let req = cblock1.toRequest(); let req = cblock1.toRequest();
assert.equal(req.hash, cblock1.hash('hex')); assert.strictEqual(req.hash, cblock1.hash('hex'));
assert.deepEqual(req.indexes, [5, 6, 7, 8, 9]); assert.deepStrictEqual(req.indexes, [5, 6, 7, 8, 9]);
req = TXRequest.fromRaw(req.toRaw()); req = TXRequest.fromRaw(req.toRaw());
assert.equal(req.hash, cblock1.hash('hex')); assert.strictEqual(req.hash, cblock1.hash('hex'));
assert.deepEqual(req.indexes, [5, 6, 7, 8, 9]); assert.deepStrictEqual(req.indexes, [5, 6, 7, 8, 9]);
let res = TXResponse.fromBlock(block, req); let res = TXResponse.fromBlock(block, req);
res = TXResponse.fromRaw(res.toRaw()); res = TXResponse.fromRaw(res.toRaw());
@ -359,9 +352,7 @@ describe('Block', function() {
for (const tx of cblock1.available) for (const tx of cblock1.available)
assert(tx); assert(tx);
assert.equal( assert.deepStrictEqual(cblock1.toBlock().toRaw(), block.toRaw());
cblock1.toBlock().toRaw().toString('hex'),
block.toRaw().toString('hex'));
}); });
it('should count sigops for block 928927 (testnet)', () => { it('should count sigops for block 928927 (testnet)', () => {
@ -374,8 +365,8 @@ describe('Block', function() {
for (const tx of block.txs) for (const tx of block.txs)
sigops += tx.getSigopsCost(view, flags); sigops += tx.getSigopsCost(view, flags);
assert.equal(sigops, 10015); assert.strictEqual(sigops, 10015);
assert.equal(block.getWeight(), 3992391); assert.strictEqual(block.getWeight(), 3992391);
}); });
it('should count sigops for block 928828 (testnet)', () => { it('should count sigops for block 928828 (testnet)', () => {
@ -388,8 +379,8 @@ describe('Block', function() {
for (const tx of block.txs) for (const tx of block.txs)
sigops += tx.getSigopsCost(view, flags); sigops += tx.getSigopsCost(view, flags);
assert.equal(sigops, 23236); assert.strictEqual(sigops, 23236);
assert.equal(block.getWeight(), 2481560); assert.strictEqual(block.getWeight(), 2481560);
}); });
it('should count sigops for block 1087400 (testnet)', () => { it('should count sigops for block 1087400 (testnet)', () => {
@ -402,7 +393,7 @@ describe('Block', function() {
for (const tx of block.txs) for (const tx of block.txs)
sigops += tx.getSigopsCost(view, flags); sigops += tx.getSigopsCost(view, flags);
assert.equal(sigops, 1298); assert.strictEqual(sigops, 1298);
assert.equal(block.getWeight(), 193331); assert.strictEqual(block.getWeight(), 193331);
}); });
}); });

View File

@ -9,7 +9,13 @@ const RollingFilter = require('../lib/utils/rollingfilter');
const murmur3 = require('../lib/utils/murmur3'); const murmur3 = require('../lib/utils/murmur3');
function testMurmur(str, seed, expect, enc) { function testMurmur(str, seed, expect, enc) {
assert.equal(murmur3(Buffer.from(str, enc || 'ascii'), seed), expect); if (!enc)
enc = 'ascii';
const data = Buffer.from(str, enc);
const hash = murmur3(data, seed);
assert.strictEqual(hash, expect);
} }
describe('Bloom', function() { describe('Bloom', function() {
@ -61,14 +67,15 @@ describe('Bloom', function() {
const item2 = '047b00000078da0dca3b0ec2300c00d0ab4466ed10' const item2 = '047b00000078da0dca3b0ec2300c00d0ab4466ed10'
+ 'e763272c6c9ca052972c69e3884a9022084215e2eef' + 'e763272c6c9ca052972c69e3884a9022084215e2eef'
+ '0e6f781656b5d5a87231cd4349e534b6dea55ad4ff55e'; + '0e6f781656b5d5a87231cd4349e534b6dea55ad4ff55e';
const filterHex = '' const filterRaw = Buffer.from(''
+ '000000000000000000000000000000000000000000000000088004000000000000000' + '000000000000000000000000000000000000000000000000088004000000000000000'
+ '000000000200000000000000000000000000000000800000000000000000002000000' + '000000000200000000000000000000000000000000800000000000000000002000000'
+ '000000000000002000000000000000000000000000000000000000000040000200000' + '000000000000002000000000000000000000000000000000000000000040000200000'
+ '0000000001000000800000080000000'; + '0000000001000000800000080000000',
'hex');
filter.add(item1, 'hex'); filter.add(item1, 'hex');
filter.add(item2, 'hex'); filter.add(item2, 'hex');
assert.equal(filter.filter.toString('hex'), filterHex); assert.deepStrictEqual(filter.filter, filterRaw);
}); });
it('should handle 1m ops with regular filter', () => { it('should handle 1m ops with regular filter', () => {
@ -83,8 +90,8 @@ describe('Bloom', function() {
filter.add(str, 'ascii'); filter.add(str, 'ascii');
do { do {
const str = 'foobar' + j; const str = 'foobar' + j;
assert(filter.test(str, 'ascii') === true); assert(filter.test(str, 'ascii'));
assert(filter.test(str + '-', 'ascii') === false); assert(!filter.test(str + '-', 'ascii'));
} while (j--); } while (j--);
} }
}); });
@ -101,8 +108,8 @@ describe('Bloom', function() {
filter.add(str, 'ascii'); filter.add(str, 'ascii');
do { do {
const str = 'foobar' + j; const str = 'foobar' + j;
assert(filter.test(str, 'ascii') === true); assert(filter.test(str, 'ascii'));
assert(filter.test(str + '-', 'ascii') === false); assert(!filter.test(str + '-', 'ascii'));
} while (j--); } while (j--);
} }
}); });
@ -118,8 +125,8 @@ describe('Bloom', function() {
filter.add(str, 'ascii'); filter.add(str, 'ascii');
do { do {
const str = 'foobar' + j; const str = 'foobar' + j;
assert(filter.test(str, 'ascii') === true); assert(filter.test(str, 'ascii'));
assert(filter.test(str + '-', 'ascii') === false); assert(!filter.test(str + '-', 'ascii'));
} while (j--); } while (j--);
} }
@ -129,8 +136,8 @@ describe('Bloom', function() {
filter.add(str, 'ascii'); filter.add(str, 'ascii');
do { do {
const str = 'foobar' + j; const str = 'foobar' + j;
assert(filter.test(str, 'ascii') === true, str); assert(filter.test(str, 'ascii'));
assert(filter.test(str + '-', 'ascii') === false, str); assert(!filter.test(str + '-', 'ascii'));
} while (j--); } while (j--);
} }
@ -140,8 +147,8 @@ describe('Bloom', function() {
filter.add(str, 'ascii'); filter.add(str, 'ascii');
do { do {
const str = 'foobar' + j; const str = 'foobar' + j;
assert(filter.test(str, 'ascii') === true, str); assert(filter.test(str, 'ascii'));
assert(filter.test(str + '-', 'ascii') === false, str); assert(!filter.test(str + '-', 'ascii'));
} while (j--); } while (j--);
} }
@ -151,10 +158,10 @@ describe('Bloom', function() {
filter.add(str, 'ascii'); filter.add(str, 'ascii');
do { do {
const str = 'foobar' + j; const str = 'foobar' + j;
assert(filter.test(str, 'ascii') === true, str); assert(filter.test(str, 'ascii'));
assert(filter.test(str + '-', 'ascii') === false, str); assert(!filter.test(str + '-', 'ascii'));
} while (j-- > 25); } while (j-- > 25);
assert(filter.test('foobar 24', 'ascii') === false); assert(!filter.test('foobar 24', 'ascii'));
} }
for (let i = 100; i < 125; i++) { for (let i = 100; i < 125; i++) {
@ -163,11 +170,11 @@ describe('Bloom', function() {
filter.add(str, 'ascii'); filter.add(str, 'ascii');
do { do {
const str = 'foobar' + j; const str = 'foobar' + j;
assert(filter.test(str, 'ascii') === true, str); assert(filter.test(str, 'ascii'));
assert(filter.test(str + '-', 'ascii') === false, str); assert(!filter.test(str + '-', 'ascii'));
} while (j-- > 50); } while (j-- > 50);
} }
assert(filter.test('foobar 49', 'ascii') === false); assert(!filter.test('foobar 49', 'ascii'));
}); });
}); });

View File

@ -8,63 +8,55 @@ const ChaCha20 = require('../lib/crypto/chacha20');
const Poly1305 = require('../lib/crypto/poly1305'); const Poly1305 = require('../lib/crypto/poly1305');
const AEAD = require('../lib/crypto/aead'); const AEAD = require('../lib/crypto/aead');
function testChaCha(options) {
const key = Buffer.from(options.key, 'hex');
const nonce = Buffer.from(options.nonce, 'hex');
const plain = Buffer.from(options.plain, 'hex');
const ciphertext = Buffer.from(options.ciphertext, 'hex');
const counter = options.counter;
const ctx1 = new ChaCha20();
ctx1.init(key, nonce, counter);
const plainenc = Buffer.from(plain);
ctx1.encrypt(plainenc);
assert.deepStrictEqual(plainenc, ciphertext);
const ctx2 = new ChaCha20();
ctx2.init(key, nonce, counter);
ctx2.encrypt(ciphertext);
assert.deepStrictEqual(plain, ciphertext);
}
function testAEAD(options) {
const plain = Buffer.from(options.plain, 'hex');
const aad = Buffer.from(options.aad, 'hex');
const key = Buffer.from(options.key, 'hex');
const nonce = Buffer.from(options.nonce, 'hex');
const pk = Buffer.from(options.pk, 'hex');
const ciphertext = Buffer.from(options.ciphertext, 'hex');
const tag = Buffer.from(options.tag, 'hex');
const ctx1 = new AEAD();
ctx1.init(key, nonce);
assert.strictEqual(ctx1.chacha20.getCounter(), 1);
assert.deepStrictEqual(ctx1.polyKey, pk);
ctx1.aad(aad);
const plainenc = Buffer.from(plain);
ctx1.encrypt(plainenc);
assert.deepStrictEqual(plainenc, ciphertext);
assert.deepStrictEqual(ctx1.finish(), tag);
const ctx2 = new AEAD();
ctx2.init(key, nonce);
assert.strictEqual(ctx2.chacha20.getCounter(), 1);
assert.deepStrictEqual(ctx2.polyKey, pk);
ctx2.aad(aad);
ctx2.decrypt(ciphertext);
assert.deepStrictEqual(ciphertext, plain);
assert.deepStrictEqual(ctx2.finish(), tag);
}
describe('ChaCha20 / Poly1305 / AEAD', function() { describe('ChaCha20 / Poly1305 / AEAD', function() {
function testChaCha(options) {
const key = Buffer.from(options.key, 'hex');
const nonce = Buffer.from(options.nonce, 'hex');
const plain = Buffer.from(options.plain, 'hex');
const ciphertext = Buffer.from(options.ciphertext, 'hex');
const counter = options.counter;
{
const chacha = new ChaCha20();
chacha.init(key, nonce, counter);
const plainenc = Buffer.from(plain);
chacha.encrypt(plainenc);
assert.deepEqual(plainenc, ciphertext);
}
{
const chacha = new ChaCha20();
chacha.init(key, nonce, counter);
chacha.encrypt(ciphertext);
assert.deepEqual(plain, ciphertext);
}
}
function testAEAD(options) {
const plain = Buffer.from(options.plain, 'hex');
const aad = Buffer.from(options.aad, 'hex');
const key = Buffer.from(options.key, 'hex');
const nonce = Buffer.from(options.nonce, 'hex');
const pk = Buffer.from(options.pk, 'hex');
const ciphertext = Buffer.from(options.ciphertext, 'hex');
const tag = Buffer.from(options.tag, 'hex');
{
const aead = new AEAD();
aead.init(key, nonce);
assert.equal(aead.chacha20.getCounter(), 1);
assert.deepEqual(aead.polyKey, pk);
aead.aad(aad);
const plainenc = Buffer.from(plain);
aead.encrypt(plainenc);
assert.deepEqual(plainenc, ciphertext);
assert.deepEqual(aead.finish(), tag);
}
{
const aead = new AEAD();
aead.init(key, nonce);
assert.equal(aead.chacha20.getCounter(), 1);
assert.deepEqual(aead.polyKey, pk);
aead.aad(aad);
aead.decrypt(ciphertext);
assert.deepEqual(ciphertext, plain);
assert.deepEqual(aead.finish(), tag);
}
}
it('should perform chacha20', () => { it('should perform chacha20', () => {
testChaCha({ testChaCha({
key: '000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f', key: '000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f',
@ -168,7 +160,7 @@ describe('ChaCha20 / Poly1305 / AEAD', function() {
const mac = Poly1305.auth(msg, key); const mac = Poly1305.auth(msg, key);
assert(Poly1305.verify(mac, expected)); assert(Poly1305.verify(mac, expected));
assert.deepEqual(mac, expected); assert.deepStrictEqual(mac, expected);
}); });
it('should perform poly1305', () => { it('should perform poly1305', () => {

View File

@ -18,70 +18,90 @@ const Output = require('../lib/primitives/output');
const common = require('../lib/blockchain/common'); const common = require('../lib/blockchain/common');
const opcodes = Script.opcodes; const opcodes = Script.opcodes;
const network = Network.get('regtest');
const chain = new Chain({
db: 'memory',
network
});
const miner = new Miner({
chain,
version: 4
});
const cpu = miner.cpu;
const wallet = new MemWallet({
network,
witness: false
});
const witWallet = new MemWallet({
network,
witness: true
});
let tip1 = null;
let tip2 = null;
async function addBlock(block, flags) {
let entry;
try {
entry = await chain.add(block, flags);
} catch (e) {
assert(e.type === 'VerifyError');
return e.reason;
}
if (!entry)
return 'bad-prevblk';
return 'OK';
}
async function mineBlock(job, flags) {
const block = await job.mineAsync();
return await addBlock(block, flags);
}
async function mineCSV(fund) {
const job = await cpu.createJob();
const spend = new MTX();
spend.addOutput({
script: [
Script.array(new BN(1)),
Script.opcodes.OP_CHECKSEQUENCEVERIFY
],
value: 10000
});
spend.addTX(fund, 0);
spend.setLocktime(chain.height);
wallet.sign(spend);
const [tx, view] = spend.commit();
job.addTX(tx, view);
job.refresh();
return await job.mineAsync();
}
chain.on('connect', (entry, block) => {
wallet.addBlock(entry, block.txs);
});
chain.on('disconnect', (entry, block) => {
wallet.removeBlock(entry, block.txs);
});
describe('Chain', function() { describe('Chain', function() {
const network = Network.get('regtest');
const chain = new Chain({ db: 'memory', network: network });
const miner = new Miner({ chain: chain, version: 4 });
const wallet = new MemWallet({ network: network });
const wwallet = new MemWallet({ network: network, witness: true });
const cpu = miner.cpu;
let tip1, tip2;
this.timeout(45000); this.timeout(45000);
async function addBlock(block, flags) {
let entry;
try {
entry = await chain.add(block, flags);
} catch (e) {
assert(e.type === 'VerifyError');
return e.reason;
}
if (!entry)
return 'bad-prevblk';
return 'OK';
}
async function mineBlock(job, flags) {
const block = await job.mineAsync();
return await addBlock(block, flags);
}
async function mineCSV(tx) {
const job = await cpu.createJob();
const rtx = new MTX();
rtx.addOutput({
script: [
Script.array(new BN(1)),
Script.opcodes.OP_CHECKSEQUENCEVERIFY
],
value: 10000
});
rtx.addTX(tx, 0);
rtx.setLocktime(chain.height);
wallet.sign(rtx);
job.addTX(rtx.toTX(), rtx.view);
job.refresh();
return await job.mineAsync();
}
chain.on('connect', (entry, block) => {
wallet.addBlock(entry, block.txs);
});
chain.on('disconnect', (entry, block) => {
wallet.removeBlock(entry, block.txs);
});
it('should open chain and miner', async () => { it('should open chain and miner', async () => {
await chain.open(); await chain.open();
await miner.open(); await miner.open();
@ -99,7 +119,7 @@ describe('Chain', function() {
assert(await chain.add(block)); assert(await chain.add(block));
} }
assert.equal(chain.height, 200); assert.strictEqual(chain.height, 200);
}); });
it('should mine competing chains', async () => { it('should mine competing chains', async () => {
@ -142,19 +162,17 @@ describe('Chain', function() {
}); });
it('should have correct chain value', () => { it('should have correct chain value', () => {
assert.equal(chain.db.state.value, 897500000000); assert.strictEqual(chain.db.state.value, 897500000000);
assert.equal(chain.db.state.coin, 220); assert.strictEqual(chain.db.state.coin, 220);
assert.equal(chain.db.state.tx, 221); assert.strictEqual(chain.db.state.tx, 221);
}); });
it('should have correct wallet balance', async () => { it('should have correct wallet balance', async () => {
assert.equal(wallet.balance, 897500000000); assert.strictEqual(wallet.balance, 897500000000);
}); });
it('should handle a reorg', async () => { it('should handle a reorg', async () => {
let forked = false; assert.strictEqual(chain.height, 210);
assert.equal(chain.height, 210);
const entry = await chain.db.getEntry(tip2.hash); const entry = await chain.db.getEntry(tip2.hash);
assert(entry); assert(entry);
@ -163,6 +181,7 @@ describe('Chain', function() {
const block = await cpu.mineBlock(entry); const block = await cpu.mineBlock(entry);
assert(block); assert(block);
let forked = false;
chain.once('reorganize', () => { chain.once('reorganize', () => {
forked = true; forked = true;
}); });
@ -175,13 +194,13 @@ describe('Chain', function() {
}); });
it('should have correct chain value', () => { it('should have correct chain value', () => {
assert.equal(chain.db.state.value, 900000000000); assert.strictEqual(chain.db.state.value, 900000000000);
assert.equal(chain.db.state.coin, 221); assert.strictEqual(chain.db.state.coin, 221);
assert.equal(chain.db.state.tx, 222); assert.strictEqual(chain.db.state.tx, 222);
}); });
it('should have correct wallet balance', async () => { it('should have correct wallet balance', async () => {
assert.equal(wallet.balance, 900000000000); assert.strictEqual(wallet.balance, 900000000000);
}); });
it('should check main chain', async () => { it('should check main chain', async () => {
@ -205,8 +224,6 @@ describe('Chain', function() {
}); });
it('should prevent double spend on new chain', async () => { it('should prevent double spend on new chain', async () => {
let job = await cpu.createJob();
const mtx = await wallet.create({ const mtx = await wallet.create({
outputs: [{ outputs: [{
address: wallet.getAddress(), address: wallet.getAddress(),
@ -214,22 +231,29 @@ describe('Chain', function() {
}] }]
}); });
job.addTX(mtx.toTX(), mtx.view); {
job.refresh(); const job = await cpu.createJob();
const block = await job.mineAsync(); job.addTX(mtx.toTX(), mtx.view);
job.refresh();
assert(await chain.add(block)); const block = await job.mineAsync();
job = await cpu.createJob(); assert(await chain.add(block));
}
assert(mtx.outputs.length > 1); {
mtx.outputs.pop(); const job = await cpu.createJob();
job.addTX(mtx.toTX(), mtx.view); assert(mtx.outputs.length > 1);
job.refresh(); mtx.outputs.pop();
assert.equal(await mineBlock(job), 'bad-txns-inputs-missingorspent'); job.addTX(mtx.toTX(), mtx.view);
job.refresh();
assert.strictEqual(await mineBlock(job),
'bad-txns-inputs-missingorspent');
}
}); });
it('should fail to connect coins on an alternate chain', async () => { it('should fail to connect coins on an alternate chain', async () => {
@ -246,13 +270,13 @@ describe('Chain', function() {
job.addTX(mtx.toTX(), mtx.view); job.addTX(mtx.toTX(), mtx.view);
job.refresh(); job.refresh();
assert.equal(await mineBlock(job), 'bad-txns-inputs-missingorspent'); assert.strictEqual(await mineBlock(job), 'bad-txns-inputs-missingorspent');
}); });
it('should have correct chain value', () => { it('should have correct chain value', () => {
assert.equal(chain.db.state.value, 905000000000); assert.strictEqual(chain.db.state.value, 905000000000);
assert.equal(chain.db.state.coin, 224); assert.strictEqual(chain.db.state.coin, 224);
assert.equal(chain.db.state.tx, 225); assert.strictEqual(chain.db.state.tx, 225);
}); });
it('should get coin', async () => { it('should get coin', async () => {
@ -285,28 +309,32 @@ describe('Chain', function() {
const coin = await chain.db.getCoin(tx.hash('hex'), 2); const coin = await chain.db.getCoin(tx.hash('hex'), 2);
assert.deepEqual(coin.toRaw(), output.toRaw()); assert.deepStrictEqual(coin.toRaw(), output.toRaw());
}); });
it('should have correct wallet balance', async () => { it('should have correct wallet balance', async () => {
assert.equal(wallet.balance, 907500000000); assert.strictEqual(wallet.balance, 907500000000);
assert.equal(wallet.receiveDepth, 15); assert.strictEqual(wallet.receiveDepth, 15);
assert.equal(wallet.changeDepth, 14); assert.strictEqual(wallet.changeDepth, 14);
assert.equal(wallet.txs, 226); assert.strictEqual(wallet.txs, 226);
}); });
it('should get tips and remove chains', async () => { it('should get tips and remove chains', async () => {
let tips = await chain.db.getTips(); {
const tips = await chain.db.getTips();
assert.notEqual(tips.indexOf(chain.tip.hash), -1); assert.notStrictEqual(tips.indexOf(chain.tip.hash), -1);
assert.equal(tips.length, 2); assert.strictEqual(tips.length, 2);
}
await chain.db.removeChains(); await chain.db.removeChains();
tips = await chain.db.getTips(); {
const tips = await chain.db.getTips();
assert.notEqual(tips.indexOf(chain.tip.hash), -1); assert.notStrictEqual(tips.indexOf(chain.tip.hash), -1);
assert.equal(tips.length, 1); assert.strictEqual(tips.length, 1);
}
}); });
it('should rescan for transactions', async () => { it('should rescan for transactions', async () => {
@ -316,7 +344,7 @@ describe('Chain', function() {
total += txs.length; total += txs.length;
}); });
assert.equal(total, 226); assert.strictEqual(total, 226);
}); });
it('should activate csv', async () => { it('should activate csv', async () => {
@ -324,11 +352,11 @@ describe('Chain', function() {
miner.options.version = -1; miner.options.version = -1;
assert.equal(chain.height, 214); assert.strictEqual(chain.height, 214);
const prev = await chain.tip.getPrevious(); const prev = await chain.tip.getPrevious();
const state = await chain.getState(prev, deployments.csv); const state = await chain.getState(prev, deployments.csv);
assert.equal(state, 1); assert.strictEqual(state, 1);
for (let i = 0; i < 417; i++) { for (let i = 0; i < 417; i++) {
const block = await cpu.mineBlock(); const block = await cpu.mineBlock();
@ -337,31 +365,31 @@ describe('Chain', function() {
case 288: { case 288: {
const prev = await chain.tip.getPrevious(); const prev = await chain.tip.getPrevious();
const state = await chain.getState(prev, deployments.csv); const state = await chain.getState(prev, deployments.csv);
assert.equal(state, 1); assert.strictEqual(state, 1);
break; break;
} }
case 432: { case 432: {
const prev = await chain.tip.getPrevious(); const prev = await chain.tip.getPrevious();
const state = await chain.getState(prev, deployments.csv); const state = await chain.getState(prev, deployments.csv);
assert.equal(state, 2); assert.strictEqual(state, 2);
break; break;
} }
case 576: { case 576: {
const prev = await chain.tip.getPrevious(); const prev = await chain.tip.getPrevious();
const state = await chain.getState(prev, deployments.csv); const state = await chain.getState(prev, deployments.csv);
assert.equal(state, 3); assert.strictEqual(state, 3);
break; break;
} }
} }
} }
assert.equal(chain.height, 631); assert.strictEqual(chain.height, 631);
assert(chain.state.hasCSV()); assert(chain.state.hasCSV());
assert(chain.state.hasWitness()); assert(chain.state.hasWitness());
const cache = await chain.db.getStateCache(); const cache = await chain.db.getStateCache();
assert.deepEqual(cache, chain.db.stateCache); assert.deepStrictEqual(cache, chain.db.stateCache);
assert.equal(chain.db.stateCache.updates.length, 0); assert.strictEqual(chain.db.stateCache.updates.length, 0);
assert(await chain.db.verifyDeployments()); assert(await chain.db.verifyDeployments());
}); });
@ -369,20 +397,20 @@ describe('Chain', function() {
const deployments = network.deployments; const deployments = network.deployments;
const prev = await chain.tip.getPrevious(); const prev = await chain.tip.getPrevious();
const state = await chain.getState(prev, deployments.segwit); const state = await chain.getState(prev, deployments.segwit);
assert.equal(state, 3); assert.strictEqual(state, 3);
}); });
it('should test csv', async () => { it('should test csv', async () => {
const tx = (await chain.db.getBlock(chain.height - 100)).txs[0]; const tx = (await chain.db.getBlock(chain.height - 100)).txs[0];
let block = await mineCSV(tx); const csvBlock = await mineCSV(tx);
assert(await chain.add(block)); assert(await chain.add(csvBlock));
const csv = block.txs[1]; const csv = csvBlock.txs[1];
const rtx = new MTX(); const spend = new MTX();
rtx.addOutput({ spend.addOutput({
script: [ script: [
Script.array(new BN(2)), Script.array(new BN(2)),
Script.opcodes.OP_CHECKSEQUENCEVERIFY Script.opcodes.OP_CHECKSEQUENCEVERIFY
@ -390,24 +418,24 @@ describe('Chain', function() {
value: 10000 value: 10000
}); });
rtx.addTX(csv, 0); spend.addTX(csv, 0);
rtx.setSequence(0, 1, false); spend.setSequence(0, 1, false);
const job = await cpu.createJob(); const job = await cpu.createJob();
job.addTX(rtx.toTX(), rtx.view); job.addTX(spend.toTX(), spend.view);
job.refresh(); job.refresh();
block = await job.mineAsync(); const block = await job.mineAsync();
assert(await chain.add(block)); assert(await chain.add(block));
}); });
it('should fail csv with bad sequence', async () => { it('should fail csv with bad sequence', async () => {
const csv = (await chain.db.getBlock(chain.height - 100)).txs[0]; const csv = (await chain.db.getBlock(chain.height - 100)).txs[0];
const rtx = new MTX(); const spend = new MTX();
rtx.addOutput({ spend.addOutput({
script: [ script: [
Script.array(new BN(1)), Script.array(new BN(1)),
Script.opcodes.OP_CHECKSEQUENCEVERIFY Script.opcodes.OP_CHECKSEQUENCEVERIFY
@ -415,14 +443,14 @@ describe('Chain', function() {
value: 1 * 1e8 value: 1 * 1e8
}); });
rtx.addTX(csv, 0); spend.addTX(csv, 0);
rtx.setSequence(0, 1, false); spend.setSequence(0, 1, false);
const job = await cpu.createJob(); const job = await cpu.createJob();
job.addTX(rtx.toTX(), rtx.view); job.addTX(spend.toTX(), spend.view);
job.refresh(); job.refresh();
assert.equal(await mineBlock(job), 'mandatory-script-verify-flag-failed'); assert.strictEqual(await mineBlock(job), 'mandatory-script-verify-flag-failed');
}); });
it('should mine a block', async () => { it('should mine a block', async () => {
@ -433,15 +461,15 @@ describe('Chain', function() {
it('should fail csv lock checks', async () => { it('should fail csv lock checks', async () => {
const tx = (await chain.db.getBlock(chain.height - 100)).txs[0]; const tx = (await chain.db.getBlock(chain.height - 100)).txs[0];
const block = await mineCSV(tx); const csvBlock = await mineCSV(tx);
assert(await chain.add(block)); assert(await chain.add(csvBlock));
const csv = block.txs[1]; const csv = csvBlock.txs[1];
const rtx = new MTX(); const spend = new MTX();
rtx.addOutput({ spend.addOutput({
script: [ script: [
Script.array(new BN(2)), Script.array(new BN(2)),
Script.opcodes.OP_CHECKSEQUENCEVERIFY Script.opcodes.OP_CHECKSEQUENCEVERIFY
@ -449,38 +477,38 @@ describe('Chain', function() {
value: 1 * 1e8 value: 1 * 1e8
}); });
rtx.addTX(csv, 0); spend.addTX(csv, 0);
rtx.setSequence(0, 2, false); spend.setSequence(0, 2, false);
const job = await cpu.createJob(); const job = await cpu.createJob();
job.addTX(rtx.toTX(), rtx.view); job.addTX(spend.toTX(), spend.view);
job.refresh(); job.refresh();
assert.equal(await mineBlock(job), 'bad-txns-nonfinal'); assert.strictEqual(await mineBlock(job), 'bad-txns-nonfinal');
}); });
it('should have correct wallet balance', async () => { it('should have correct wallet balance', async () => {
assert.equal(wallet.balance, 1412499980000); assert.strictEqual(wallet.balance, 1412499980000);
}); });
it('should fail to connect bad bits', async () => { it('should fail to connect bad bits', async () => {
const job = await cpu.createJob(); const job = await cpu.createJob();
job.attempt.bits = 553713663; job.attempt.bits = 553713663;
assert.equal(await mineBlock(job), 'bad-diffbits'); assert.strictEqual(await mineBlock(job), 'bad-diffbits');
}); });
it('should fail to connect bad MTP', async () => { it('should fail to connect bad MTP', async () => {
const mtp = await chain.tip.getMedianTime(); const mtp = await chain.tip.getMedianTime();
const job = await cpu.createJob(); const job = await cpu.createJob();
job.attempt.time = mtp - 1; job.attempt.time = mtp - 1;
assert.equal(await mineBlock(job), 'time-too-old'); assert.strictEqual(await mineBlock(job), 'time-too-old');
}); });
it('should fail to connect bad time', async () => { it('should fail to connect bad time', async () => {
const job = await cpu.createJob(); const job = await cpu.createJob();
const now = network.now() + 3 * 60 * 60; const now = network.now() + 3 * 60 * 60;
job.attempt.time = now; job.attempt.time = now;
assert.equal(await mineBlock(job), 'time-too-new'); assert.strictEqual(await mineBlock(job), 'time-too-new');
}); });
it('should fail to connect bad locktime', async () => { it('should fail to connect bad locktime', async () => {
@ -488,7 +516,7 @@ describe('Chain', function() {
const tx = await wallet.send({ locktime: 100000 }); const tx = await wallet.send({ locktime: 100000 });
job.pushTX(tx.toTX()); job.pushTX(tx.toTX());
job.refresh(); job.refresh();
assert.equal(await mineBlock(job), 'bad-txns-nonfinal'); assert.strictEqual(await mineBlock(job), 'bad-txns-nonfinal');
}); });
it('should fail to connect bad cb height', async () => { it('should fail to connect bad cb height', async () => {
@ -500,7 +528,7 @@ describe('Chain', function() {
try { try {
network.block.bip34height = 0; network.block.bip34height = 0;
assert.equal(await mineBlock(job), 'bad-cb-height'); assert.strictEqual(await mineBlock(job), 'bad-cb-height');
} finally { } finally {
network.block.bip34height = bip34height; network.block.bip34height = bip34height;
} }
@ -513,7 +541,7 @@ describe('Chain', function() {
input.witness.set(0, Buffer.allocUnsafe(33)); input.witness.set(0, Buffer.allocUnsafe(33));
input.witness.compile(); input.witness.compile();
block.refresh(true); block.refresh(true);
assert.equal(await addBlock(block), 'bad-witness-nonce-size'); assert.strictEqual(await addBlock(block), 'bad-witness-nonce-size');
}); });
it('should fail to connect bad witness nonce', async () => { it('should fail to connect bad witness nonce', async () => {
@ -523,7 +551,7 @@ describe('Chain', function() {
input.witness.set(0, encoding.ONE_HASH); input.witness.set(0, encoding.ONE_HASH);
input.witness.compile(); input.witness.compile();
block.refresh(true); block.refresh(true);
assert.equal(await addBlock(block), 'bad-witness-merkle-match'); assert.strictEqual(await addBlock(block), 'bad-witness-merkle-match');
}); });
it('should fail to connect bad witness commitment', async () => { it('should fail to connect bad witness commitment', async () => {
@ -542,7 +570,7 @@ describe('Chain', function() {
block.refresh(true); block.refresh(true);
block.merkleRoot = block.createMerkleRoot('hex'); block.merkleRoot = block.createMerkleRoot('hex');
assert.equal(await addBlock(block, flags), 'bad-witness-merkle-match'); assert.strictEqual(await addBlock(block, flags), 'bad-witness-merkle-match');
}); });
it('should fail to connect unexpected witness', async () => { it('should fail to connect unexpected witness', async () => {
@ -558,13 +586,13 @@ describe('Chain', function() {
block.refresh(true); block.refresh(true);
block.merkleRoot = block.createMerkleRoot('hex'); block.merkleRoot = block.createMerkleRoot('hex');
assert.equal(await addBlock(block, flags), 'unexpected-witness'); assert.strictEqual(await addBlock(block, flags), 'unexpected-witness');
}); });
it('should add wit addrs to miner', async () => { it('should add wit addrs to miner', async () => {
miner.addresses.length = 0; miner.addresses.length = 0;
miner.addAddress(wwallet.getReceive()); miner.addAddress(witWallet.getReceive());
assert.equal(wwallet.getReceive().getType(), 'witness'); assert.strictEqual(witWallet.getReceive().getType(), 'witness');
}); });
it('should mine 2000 witness blocks', async () => { it('should mine 2000 witness blocks', async () => {
@ -574,24 +602,24 @@ describe('Chain', function() {
assert(await chain.add(block)); assert(await chain.add(block));
} }
assert.equal(chain.height, 2636); assert.strictEqual(chain.height, 2636);
}); });
it('should mine a witness tx', async () => { it('should mine a witness tx', async () => {
let block = await chain.db.getBlock(chain.height - 2000); const prev = await chain.db.getBlock(chain.height - 2000);
const cb = block.txs[0]; const cb = prev.txs[0];
const mtx = new MTX(); const mtx = new MTX();
mtx.addTX(cb, 0); mtx.addTX(cb, 0);
mtx.addOutput(wwallet.getAddress(), 1000); mtx.addOutput(witWallet.getAddress(), 1000);
wwallet.sign(mtx); witWallet.sign(mtx);
const job = await cpu.createJob(); const job = await cpu.createJob();
job.addTX(mtx.toTX(), mtx.view); job.addTX(mtx.toTX(), mtx.view);
job.refresh(); job.refresh();
block = await job.mineAsync(); const block = await job.mineAsync();
assert(await chain.add(block)); assert(await chain.add(block));
}); });
@ -609,16 +637,16 @@ describe('Chain', function() {
mtx.addTX(cb, 0); mtx.addTX(cb, 0);
for (let j = 0; j < 16; j++) for (let j = 0; j < 16; j++)
mtx.addOutput(wwallet.getAddress(), 1); mtx.addOutput(witWallet.getAddress(), 1);
wwallet.sign(mtx); witWallet.sign(mtx);
job.pushTX(mtx.toTX()); job.pushTX(mtx.toTX());
} }
job.refresh(); job.refresh();
assert.equal(await mineBlock(job), 'bad-blk-weight'); assert.strictEqual(await mineBlock(job), 'bad-blk-weight');
}); });
it('should mine fail to connect too much size', async () => { it('should mine fail to connect too much size', async () => {
@ -634,16 +662,16 @@ describe('Chain', function() {
mtx.addTX(cb, 0); mtx.addTX(cb, 0);
for (let j = 0; j < 20; j++) for (let j = 0; j < 20; j++)
mtx.addOutput(wwallet.getAddress(), 1); mtx.addOutput(witWallet.getAddress(), 1);
wwallet.sign(mtx); witWallet.sign(mtx);
job.pushTX(mtx.toTX()); job.pushTX(mtx.toTX());
} }
job.refresh(); job.refresh();
assert.equal(await mineBlock(job), 'bad-blk-length'); assert.strictEqual(await mineBlock(job), 'bad-blk-length');
}); });
it('should mine a big block', async () => { it('should mine a big block', async () => {
@ -659,23 +687,23 @@ describe('Chain', function() {
mtx.addTX(cb, 0); mtx.addTX(cb, 0);
for (let j = 0; j < 15; j++) for (let j = 0; j < 15; j++)
mtx.addOutput(wwallet.getAddress(), 1); mtx.addOutput(witWallet.getAddress(), 1);
wwallet.sign(mtx); witWallet.sign(mtx);
job.pushTX(mtx.toTX()); job.pushTX(mtx.toTX());
} }
job.refresh(); job.refresh();
assert.equal(await mineBlock(job), 'OK'); assert.strictEqual(await mineBlock(job), 'OK');
}); });
it('should fail to connect bad versions', async () => { it('should fail to connect bad versions', async () => {
for (let i = 0; i <= 3; i++) { for (let i = 0; i <= 3; i++) {
const job = await cpu.createJob(); const job = await cpu.createJob();
job.attempt.version = i; job.attempt.version = i;
assert.equal(await mineBlock(job), 'bad-version'); assert.strictEqual(await mineBlock(job), 'bad-version');
} }
}); });
@ -684,7 +712,7 @@ describe('Chain', function() {
job.attempt.fees += 1; job.attempt.fees += 1;
job.refresh(); job.refresh();
assert.equal(await mineBlock(job), 'bad-cb-amount'); assert.strictEqual(await mineBlock(job), 'bad-cb-amount');
}); });
it('should fail to connect premature cb spend', async () => { it('should fail to connect premature cb spend', async () => {
@ -694,14 +722,14 @@ describe('Chain', function() {
const mtx = new MTX(); const mtx = new MTX();
mtx.addTX(cb, 0); mtx.addTX(cb, 0);
mtx.addOutput(wwallet.getAddress(), 1); mtx.addOutput(witWallet.getAddress(), 1);
wwallet.sign(mtx); witWallet.sign(mtx);
job.addTX(mtx.toTX(), mtx.view); job.addTX(mtx.toTX(), mtx.view);
job.refresh(); job.refresh();
assert.equal(await mineBlock(job), assert.strictEqual(await mineBlock(job),
'bad-txns-premature-spend-of-coinbase'); 'bad-txns-premature-spend-of-coinbase');
}); });
@ -712,14 +740,14 @@ describe('Chain', function() {
const mtx = new MTX(); const mtx = new MTX();
mtx.addTX(cb, 0); mtx.addTX(cb, 0);
mtx.addOutput(wwallet.getAddress(), 1e8); mtx.addOutput(witWallet.getAddress(), 1e8);
wwallet.sign(mtx); witWallet.sign(mtx);
job.pushTX(mtx.toTX()); job.pushTX(mtx.toTX());
job.refresh(); job.refresh();
assert.equal(await mineBlock(job), assert.strictEqual(await mineBlock(job),
'bad-txns-in-belowout'); 'bad-txns-in-belowout');
}); });
@ -730,33 +758,36 @@ describe('Chain', function() {
const mtx = new MTX(); const mtx = new MTX();
mtx.addTX(cb, 0); mtx.addTX(cb, 0);
mtx.addOutput(wwallet.getAddress(), Math.floor(consensus.MAX_MONEY / 2));
mtx.addOutput(wwallet.getAddress(), Math.floor(consensus.MAX_MONEY / 2));
mtx.addOutput(wwallet.getAddress(), Math.floor(consensus.MAX_MONEY / 2));
wwallet.sign(mtx); const value = Math.floor(consensus.MAX_MONEY / 2);
mtx.addOutput(witWallet.getAddress(), value);
mtx.addOutput(witWallet.getAddress(), value);
mtx.addOutput(witWallet.getAddress(), value);
witWallet.sign(mtx);
job.pushTX(mtx.toTX()); job.pushTX(mtx.toTX());
job.refresh(); job.refresh();
assert.equal(await mineBlock(job), assert.strictEqual(await mineBlock(job),
'bad-txns-txouttotal-toolarge'); 'bad-txns-txouttotal-toolarge');
}); });
it('should mine 111 multisig blocks', async () => { it('should mine 111 multisig blocks', async () => {
const flags = common.flags.DEFAULT_FLAGS & ~common.flags.VERIFY_POW; const flags = common.flags.DEFAULT_FLAGS & ~common.flags.VERIFY_POW;
let script = new Script(); const redeem = new Script();
script.push(new BN(20)); redeem.push(new BN(20));
for (let i = 0; i < 20; i++) for (let i = 0; i < 20; i++)
script.push(encoding.ZERO_KEY); redeem.push(encoding.ZERO_KEY);
script.push(new BN(20)); redeem.push(new BN(20));
script.push(opcodes.OP_CHECKMULTISIG); redeem.push(opcodes.OP_CHECKMULTISIG);
script.compile(); redeem.compile();
script = Script.fromScripthash(script.hash160()); const script = Script.fromScripthash(redeem.hash160());
for (let i = 0; i < 111; i++) { for (let i = 0; i < 111; i++) {
const block = await cpu.mineBlock(); const block = await cpu.mineBlock();
@ -779,7 +810,7 @@ describe('Chain', function() {
assert(await chain.add(block, flags)); assert(await chain.add(block, flags));
} }
assert.equal(chain.height, 2749); assert.strictEqual(chain.height, 2749);
}); });
it('should fail to connect too many sigops', async () => { it('should fail to connect too many sigops', async () => {
@ -811,14 +842,14 @@ describe('Chain', function() {
mtx.inputs[j - 2].script = new Script([script.toRaw()]); mtx.inputs[j - 2].script = new Script([script.toRaw()]);
} }
mtx.addOutput(wwallet.getAddress(), 1); mtx.addOutput(witWallet.getAddress(), 1);
job.pushTX(mtx.toTX()); job.pushTX(mtx.toTX());
} }
job.refresh(); job.refresh();
assert.equal(await mineBlock(job), 'bad-blk-sigops'); assert.strictEqual(await mineBlock(job), 'bad-blk-sigops');
}); });
it('should cleanup', async () => { it('should cleanup', async () => {

View File

@ -11,7 +11,7 @@ const CoinView = require('../lib/coins/coinview');
const CoinEntry = require('../lib/coins/coinentry'); const CoinEntry = require('../lib/coins/coinentry');
const StaticWriter = require('../lib/utils/staticwriter'); const StaticWriter = require('../lib/utils/staticwriter');
const BufferReader = require('../lib/utils/reader'); const BufferReader = require('../lib/utils/reader');
const parseTX = require('./util/common').parseTX; const {parseTX} = require('./util/common');
const data = parseTX('data/tx1.hex'); const data = parseTX('data/tx1.hex');
const tx1 = data.tx; const tx1 = data.tx;
@ -40,18 +40,18 @@ describe('Coins', function() {
view.addTX(tx1, 1); view.addTX(tx1, 1);
const coins = view.get(hash); const coins = view.get(hash);
assert.equal(coins.outputs.size, tx1.outputs.length); assert.strictEqual(coins.outputs.size, tx1.outputs.length);
const entry = coins.get(0); const entry = coins.get(0);
assert(entry); assert(entry);
assert(!entry.spent); assert(!entry.spent);
assert.equal(entry.version, 1); assert.strictEqual(entry.version, 1);
assert.equal(entry.height, 1); assert.strictEqual(entry.height, 1);
assert.equal(entry.coinbase, false); assert.strictEqual(entry.coinbase, false);
assert.equal(entry.raw, null); assert.strictEqual(entry.raw, null);
assert(entry.output instanceof Output); assert(entry.output instanceof Output);
assert.equal(entry.spent, false); assert.strictEqual(entry.spent, false);
const output = view.getOutputFor(input); const output = view.getOutputFor(input);
assert(output); assert(output);
@ -81,7 +81,7 @@ describe('Coins', function() {
deepCoinsEqual(entry, reserialize(entry)); deepCoinsEqual(entry, reserialize(entry));
assert.strictEqual(coins.outputs.size, length); assert.strictEqual(coins.outputs.size, length);
assert.equal(view.undo.items.length, 1); assert.strictEqual(view.undo.items.length, 1);
}); });
it('should handle coin view', () => { it('should handle coin view', () => {

View File

@ -14,71 +14,75 @@ const Address = require('../lib/primitives/address');
const raw = fs.readFileSync(`${__dirname}/data/block928927.raw`); const raw = fs.readFileSync(`${__dirname}/data/block928927.raw`);
const block = Block.fromRaw(raw); const block = Block.fromRaw(raw);
const key = random.randomBytes(16);
const P = 20;
const contents1 = [
Buffer.from('Alex', 'ascii'),
Buffer.from('Bob', 'ascii'),
Buffer.from('Charlie', 'ascii'),
Buffer.from('Dick', 'ascii'),
Buffer.from('Ed', 'ascii'),
Buffer.from('Frank', 'ascii'),
Buffer.from('George', 'ascii'),
Buffer.from('Harry', 'ascii'),
Buffer.from('Ilya', 'ascii'),
Buffer.from('John', 'ascii'),
Buffer.from('Kevin', 'ascii'),
Buffer.from('Larry', 'ascii'),
Buffer.from('Michael', 'ascii'),
Buffer.from('Nate', 'ascii'),
Buffer.from('Owen', 'ascii'),
Buffer.from('Paul', 'ascii'),
Buffer.from('Quentin', 'ascii')
];
const contents2 = [
Buffer.from('Alice', 'ascii'),
Buffer.from('Betty', 'ascii'),
Buffer.from('Charmaine', 'ascii'),
Buffer.from('Donna', 'ascii'),
Buffer.from('Edith', 'ascii'),
Buffer.from('Faina', 'ascii'),
Buffer.from('Georgia', 'ascii'),
Buffer.from('Hannah', 'ascii'),
Buffer.from('Ilsbeth', 'ascii'),
Buffer.from('Jennifer', 'ascii'),
Buffer.from('Kayla', 'ascii'),
Buffer.from('Lena', 'ascii'),
Buffer.from('Michelle', 'ascii'),
Buffer.from('Natalie', 'ascii'),
Buffer.from('Ophelia', 'ascii'),
Buffer.from('Peggy', 'ascii'),
Buffer.from('Queenie', 'ascii')
];
const op1 = new Outpoint(
'4cba1d1753ed19dbeafffb1a6c805d20e4af00b194a8f85353163cef83319c2c',
4);
const op2 = new Outpoint(
'b7c3c4bce1a23baef2da05f9b7e4bff813449ec7e80f980ec7e4cacfadcd3314',
3);
const op3 = new Outpoint(
'4cba1d1753ed19dbeafffb1a6c805d20e4af00b194a8f85353163cef83319c2c',
400);
const op4 = new Outpoint(
'b7c3c4bce1a23baef2da05f9b7e4bff813449ec7e80f980ec7e4cacfadcd3314',
300);
const addr1 = new Address('bc1qmyrddmxglk49ye2wd29wefaavw7es8k5d555lx');
const addr2 = new Address('bc1q4645ycu0l9pnvxaxnhemushv0w4cd9flkqh95j');
let filter1 = null;
let filter2 = null;
let filter3 = null;
let filter4 = null;
let filter5 = null;
describe('GCS', function() { describe('GCS', function() {
const key = random.randomBytes(16);
const P = 20;
const contents1 = [
Buffer.from('Alex', 'ascii'),
Buffer.from('Bob', 'ascii'),
Buffer.from('Charlie', 'ascii'),
Buffer.from('Dick', 'ascii'),
Buffer.from('Ed', 'ascii'),
Buffer.from('Frank', 'ascii'),
Buffer.from('George', 'ascii'),
Buffer.from('Harry', 'ascii'),
Buffer.from('Ilya', 'ascii'),
Buffer.from('John', 'ascii'),
Buffer.from('Kevin', 'ascii'),
Buffer.from('Larry', 'ascii'),
Buffer.from('Michael', 'ascii'),
Buffer.from('Nate', 'ascii'),
Buffer.from('Owen', 'ascii'),
Buffer.from('Paul', 'ascii'),
Buffer.from('Quentin', 'ascii')
];
const contents2 = [
Buffer.from('Alice', 'ascii'),
Buffer.from('Betty', 'ascii'),
Buffer.from('Charmaine', 'ascii'),
Buffer.from('Donna', 'ascii'),
Buffer.from('Edith', 'ascii'),
Buffer.from('Faina', 'ascii'),
Buffer.from('Georgia', 'ascii'),
Buffer.from('Hannah', 'ascii'),
Buffer.from('Ilsbeth', 'ascii'),
Buffer.from('Jennifer', 'ascii'),
Buffer.from('Kayla', 'ascii'),
Buffer.from('Lena', 'ascii'),
Buffer.from('Michelle', 'ascii'),
Buffer.from('Natalie', 'ascii'),
Buffer.from('Ophelia', 'ascii'),
Buffer.from('Peggy', 'ascii'),
Buffer.from('Queenie', 'ascii')
];
const op1 = new Outpoint(
'4cba1d1753ed19dbeafffb1a6c805d20e4af00b194a8f85353163cef83319c2c',
4);
const op2 = new Outpoint(
'b7c3c4bce1a23baef2da05f9b7e4bff813449ec7e80f980ec7e4cacfadcd3314',
3);
const op3 = new Outpoint(
'4cba1d1753ed19dbeafffb1a6c805d20e4af00b194a8f85353163cef83319c2c',
400);
const op4 = new Outpoint(
'b7c3c4bce1a23baef2da05f9b7e4bff813449ec7e80f980ec7e4cacfadcd3314',
300);
const addr1 = new Address('bc1qmyrddmxglk49ye2wd29wefaavw7es8k5d555lx');
const addr2 = new Address('bc1q4645ycu0l9pnvxaxnhemushv0w4cd9flkqh95j');
let filter1, filter2, filter3, filter4, filter5;
it('should test GCS filter build', () => { it('should test GCS filter build', () => {
filter1 = GCSFilter.fromItems(P, key, contents1); filter1 = GCSFilter.fromItems(P, key, contents1);
assert(filter1); assert(filter1);
@ -96,20 +100,20 @@ describe('GCS', function() {
}); });
it('should test GCS filter metadata', () => { it('should test GCS filter metadata', () => {
assert.equal(filter1.p, P); assert.strictEqual(filter1.p, P);
assert.equal(filter1.n, contents1.length); assert.strictEqual(filter1.n, contents1.length);
assert.equal(filter1.p, filter2.p); assert.strictEqual(filter1.p, filter2.p);
assert.equal(filter1.n, filter2.n); assert.strictEqual(filter1.n, filter2.n);
assert.deepEqual(filter1.data, filter2.data); assert.deepStrictEqual(filter1.data, filter2.data);
assert.equal(filter1.p, filter3.p); assert.strictEqual(filter1.p, filter3.p);
assert.equal(filter1.n, filter3.n); assert.strictEqual(filter1.n, filter3.n);
assert.deepEqual(filter1.data, filter3.data); assert.deepStrictEqual(filter1.data, filter3.data);
assert.equal(filter1.p, filter4.p); assert.strictEqual(filter1.p, filter4.p);
assert.equal(filter1.n, filter4.n); assert.strictEqual(filter1.n, filter4.n);
assert.deepEqual(filter1.data, filter4.data); assert.deepStrictEqual(filter1.data, filter4.data);
assert.equal(filter1.p, filter5.p); assert.strictEqual(filter1.p, filter5.p);
assert.equal(filter1.n, filter5.n); assert.strictEqual(filter1.n, filter5.n);
assert.deepEqual(filter1.data, filter5.data); assert.deepStrictEqual(filter1.data, filter5.data);
}); });
it('should test GCS filter match', () => { it('should test GCS filter match', () => {

View File

@ -11,76 +11,77 @@ const vectors = require('./data/hd.json');
const vector1 = vectors.vector1; const vector1 = vectors.vector1;
const vector2 = vectors.vector2; const vector2 = vectors.vector2;
function ub58(data) { let master = null;
let child = null;
function unbase58(data) {
return base58.decode(data).toString('hex'); return base58.decode(data).toString('hex');
} }
function equal(a, b) { function base58Equal(a, b) {
assert.equal(a, b); assert.strictEqual(a, b);
assert.equal(ub58(a), ub58(b)); assert.strictEqual(unbase58(a), unbase58(b));
} }
describe('HD', function() { describe('HD', function() {
let master, child;
it('should create a pbkdf2 seed', () => { it('should create a pbkdf2 seed', () => {
const seed = pbkdf2.derive( const seed = pbkdf2.derive(
vectors.phrase, 'mnemonicfoo', 2048, 64, 'sha512'); vectors.phrase, 'mnemonicfoo', 2048, 64, 'sha512');
assert.equal(seed.toString('hex'), vectors.seed); assert.strictEqual(seed.toString('hex'), vectors.seed);
}); });
it('should create master private key', () => { it('should create master private key', () => {
const seed = Buffer.from(vectors.seed, 'hex'); const seed = Buffer.from(vectors.seed, 'hex');
const key = HD.PrivateKey.fromSeed(seed); const key = HD.PrivateKey.fromSeed(seed);
assert.equal(key.toBase58(), vectors.master_priv); assert.strictEqual(key.toBase58(), vectors.master_priv);
assert.equal(key.toPublic().toBase58(), vectors.master_pub); assert.strictEqual(key.toPublic().toBase58(), vectors.master_pub);
master = key; master = key;
}); });
it('should derive(0) child from master', () => { it('should derive(0) child from master', () => {
const child1 = master.derive(0); const child1 = master.derive(0);
assert.equal(child1.toBase58(), vectors.child1_priv); assert.strictEqual(child1.toBase58(), vectors.child1_priv);
assert.equal(child1.toPublic().toBase58(), vectors.child1_pub); assert.strictEqual(child1.toPublic().toBase58(), vectors.child1_pub);
}); });
it('should derive(1) child from master public key', () => { it('should derive(1) child from master public key', () => {
const child2 = master.toPublic().derive(1); const child2 = master.toPublic().derive(1);
assert.equal(child2.toBase58(), vectors.child2_pub); assert.strictEqual(child2.toBase58(), vectors.child2_pub);
}); });
it('should derive(1) child from master', () => { it('should derive(1) child from master', () => {
const child3 = master.derive(1); const child3 = master.derive(1);
assert.equal(child3.toBase58(), vectors.child3_priv); assert.strictEqual(child3.toBase58(), vectors.child3_priv);
assert.equal(child3.toPublic().toBase58(), vectors.child3_pub); assert.strictEqual(child3.toPublic().toBase58(), vectors.child3_pub);
}); });
it('should derive(2) child from master', () => { it('should derive(2) child from master', () => {
const child4 = master.derive(2); const child4 = master.derive(2);
assert.equal(child4.toBase58(), vectors.child4_priv); assert.strictEqual(child4.toBase58(), vectors.child4_priv);
assert.equal(child4.toPublic().toBase58(), vectors.child4_pub); assert.strictEqual(child4.toPublic().toBase58(), vectors.child4_pub);
child = child4; child = child4;
}); });
it('should derive(0) child from child(2)', () => { it('should derive(0) child from child(2)', () => {
const child5 = child.derive(0); const child5 = child.derive(0);
assert.equal(child5.toBase58(), vectors.child5_priv); assert.strictEqual(child5.toBase58(), vectors.child5_priv);
assert.equal(child5.toPublic().toBase58(), vectors.child5_pub); assert.strictEqual(child5.toPublic().toBase58(), vectors.child5_pub);
}); });
it('should derive(1) child from child(2)', () => { it('should derive(1) child from child(2)', () => {
const child6 = child.derive(1); const child6 = child.derive(1);
assert.equal(child6.toBase58(), vectors.child6_priv); assert.strictEqual(child6.toBase58(), vectors.child6_priv);
assert.equal(child6.toPublic().toBase58(), vectors.child6_pub); assert.strictEqual(child6.toPublic().toBase58(), vectors.child6_pub);
}); });
it('should derive correctly when private key has leading zeros', () => { it('should derive correctly when private key has leading zeros', () => {
const key = HD.PrivateKey.fromBase58(vectors.zero_priv); const key = HD.PrivateKey.fromBase58(vectors.zero_priv);
assert.equal(key.privateKey.toString('hex'), assert.strictEqual(key.privateKey.toString('hex'),
'00000055378cf5fafb56c711c674143f9b0ee82ab0ba2924f19b64f5ae7cdbfd'); '00000055378cf5fafb56c711c674143f9b0ee82ab0ba2924f19b64f5ae7cdbfd');
const child = key.derivePath('m/44\'/0\'/0\'/0/0\''); const child = key.derivePath('m/44\'/0\'/0\'/0/0\'');
assert.equal(child.privateKey.toString('hex'), assert.strictEqual(child.privateKey.toString('hex'),
'3348069561d2a0fb925e74bf198762acc47dce7db27372257d2d959a9e6f8aeb'); '3348069561d2a0fb925e74bf198762acc47dce7db27372257d2d959a9e6f8aeb');
}); });
@ -94,16 +95,20 @@ describe('HD', function() {
it('should deserialize and reserialize', () => { it('should deserialize and reserialize', () => {
const key = HD.generate(); const key = HD.generate();
assert.equal(HD.fromJSON(key.toJSON()).toBase58(), key.toBase58()); assert.strictEqual(HD.fromJSON(key.toJSON()).toBase58(), key.toBase58());
}); });
for (const vector of [vector1, vector2]) { for (const vector of [vector1, vector2]) {
let master; let master = null;
it('should create from a seed', () => { it('should create from a seed', () => {
master = HD.PrivateKey.fromSeed(Buffer.from(vector.seed, 'hex')); const key = HD.PrivateKey.fromSeed(Buffer.from(vector.seed, 'hex'));
equal(master.toBase58(), vector.m.prv); const pub = key.toPublic();
equal(master.toPublic().toBase58(), vector.m.pub);
base58Equal(key.toBase58(), vector.m.prv);
base58Equal(pub.toBase58(), vector.m.pub);
master = key;
}); });
for (const path of Object.keys(vector)) { for (const path of Object.keys(vector)) {
@ -114,8 +119,9 @@ describe('HD', function() {
it(`should derive ${path} from master`, () => { it(`should derive ${path} from master`, () => {
const key = master.derivePath(path); const key = master.derivePath(path);
equal(key.toBase58(), kp.prv); const pub = key.toPublic();
equal(key.toPublic().toBase58(), kp.pub); base58Equal(key.toBase58(), kp.prv);
base58Equal(pub.toBase58(), kp.pub);
}); });
} }
} }

View File

@ -7,69 +7,78 @@ const assert = require('assert');
const hkdf = require('../lib/crypto/hkdf'); const hkdf = require('../lib/crypto/hkdf');
describe('HKDF', function() { describe('HKDF', function() {
it('should do proper hkdf', () => { it('should do proper hkdf (1)', () => {
// https://tools.ietf.org/html/rfc5869 // https://tools.ietf.org/html/rfc5869
let alg = 'sha256'; const alg = 'sha256';
let ikm = '0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b'; const ikm = Buffer.from(
let salt = '000102030405060708090a0b0c'; '0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b', 'hex');
let info = 'f0f1f2f3f4f5f6f7f8f9'; const salt = Buffer.from('000102030405060708090a0b0c', 'hex');
let len = 42; const info = Buffer.from('f0f1f2f3f4f5f6f7f8f9', 'hex');
const len = 42;
let prkE = '077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec8' const prkE = Buffer.from(
+ '44ad7c2b3e5'; '077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec844ad7c2b3e5',
let okmE = '3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1' 'hex');
+ 'a5a4c5db02d56ecc4c5bf34007208d5b887185865';
ikm = Buffer.from(ikm, 'hex'); const okmE = Buffer.from(''
salt = Buffer.from(salt, 'hex'); + '3cb25f25faacd57a90434f64d0362f2a2d2d0a90'
info = Buffer.from(info, 'hex'); + 'cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865',
'hex');
let prk = hkdf.extract(ikm, salt, alg); const prk = hkdf.extract(ikm, salt, alg);
let okm = hkdf.expand(prk, info, len, alg); const okm = hkdf.expand(prk, info, len, alg);
assert.equal(prk.toString('hex'), prkE); assert.deepStrictEqual(prk, prkE);
assert.equal(okm.toString('hex'), okmE); assert.deepStrictEqual(okm, okmE);
});
alg = 'sha256'; it('should do proper hkdf (2)', () => {
const alg = 'sha256';
ikm = '000102030405060708090a0b0c0d0e0f' const ikm = Buffer.from(''
+ '000102030405060708090a0b0c0d0e0f'
+ '101112131415161718191a1b1c1d1e1f' + '101112131415161718191a1b1c1d1e1f'
+ '202122232425262728292a2b2c2d2e2f' + '202122232425262728292a2b2c2d2e2f'
+ '303132333435363738393a3b3c3d3e3f' + '303132333435363738393a3b3c3d3e3f'
+ '404142434445464748494a4b4c4d4e4f'; + '404142434445464748494a4b4c4d4e4f',
'hex');
salt = '606162636465666768696a6b6c6d6e6f' const salt = Buffer.from(''
+ '606162636465666768696a6b6c6d6e6f'
+ '707172737475767778797a7b7c7d7e7f' + '707172737475767778797a7b7c7d7e7f'
+ '808182838485868788898a8b8c8d8e8f' + '808182838485868788898a8b8c8d8e8f'
+ '909192939495969798999a9b9c9d9e9f' + '909192939495969798999a9b9c9d9e9f'
+ 'a0a1a2a3a4a5a6a7a8a9aaabacadaeaf'; + 'a0a1a2a3a4a5a6a7a8a9aaabacadaeaf',
'hex');
info = 'b0b1b2b3b4b5b6b7b8b9babbbcbdbebf' const info = Buffer.from(''
+ 'b0b1b2b3b4b5b6b7b8b9babbbcbdbebf'
+ 'c0c1c2c3c4c5c6c7c8c9cacbcccdcecf' + 'c0c1c2c3c4c5c6c7c8c9cacbcccdcecf'
+ 'd0d1d2d3d4d5d6d7d8d9dadbdcdddedf' + 'd0d1d2d3d4d5d6d7d8d9dadbdcdddedf'
+ 'e0e1e2e3e4e5e6e7e8e9eaebecedeeef' + 'e0e1e2e3e4e5e6e7e8e9eaebecedeeef'
+ 'f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff'; + 'f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff',
'hex');
len = 82; const len = 82;
prkE = '06a6b88c5853361a06104c9ceb35b45c' const prkE = Buffer.from(''
+ 'ef760014904671014a193f40c15fc244'; + '06a6b88c5853361a06104c9ceb35b45c'
+ 'ef760014904671014a193f40c15fc244',
'hex');
okmE = 'b11e398dc80327a1c8e7f78c596a4934' const okmE = Buffer.from(''
+ 'b11e398dc80327a1c8e7f78c596a4934'
+ '4f012eda2d4efad8a050cc4c19afa97c' + '4f012eda2d4efad8a050cc4c19afa97c'
+ '59045a99cac7827271cb41c65e590e09' + '59045a99cac7827271cb41c65e590e09'
+ 'da3275600c2f09b8367793a9aca3db71' + 'da3275600c2f09b8367793a9aca3db71'
+ 'cc30c58179ec3e87c14c01d5c1f3434f' + 'cc30c58179ec3e87c14c01d5c1f3434f'
+ '1d87'; + '1d87',
'hex');
ikm = Buffer.from(ikm, 'hex'); const prk = hkdf.extract(ikm, salt, alg);
salt = Buffer.from(salt, 'hex'); const okm = hkdf.expand(prk, info, len, alg);
info = Buffer.from(info, 'hex');
prk = hkdf.extract(ikm, salt, alg); assert.deepStrictEqual(prk, prkE);
okm = hkdf.expand(prk, info, len, alg); assert.deepStrictEqual(okm, okmE);
assert.equal(prk.toString('hex'), prkE);
assert.equal(okm.toString('hex'), okmE);
}); });
}); });

View File

@ -15,24 +15,25 @@ const HTTP = require('../lib/http');
const FullNode = require('../lib/node/fullnode'); const FullNode = require('../lib/node/fullnode');
const pkg = require('../lib/pkg'); const pkg = require('../lib/pkg');
const node = new FullNode({
network: 'regtest',
apiKey: 'foo',
walletAuth: true,
db: 'memory',
plugins: [require('../lib/wallet/plugin')]
});
const wallet = new HTTP.Wallet({
network: 'regtest',
apiKey: 'foo'
});
const wdb = node.require('walletdb');
let addr = null;
let hash = null;
describe('HTTP', function() { describe('HTTP', function() {
const node = new FullNode({
network: 'regtest',
apiKey: 'foo',
walletAuth: true,
db: 'memory',
plugins: [require('../lib/wallet/plugin')]
});
const wallet = new HTTP.Wallet({
network: 'regtest',
apiKey: 'foo'
});
const wdb = node.require('walletdb');
let addr, hash;
this.timeout(15000); this.timeout(15000);
it('should open node', async () => { it('should open node', async () => {
@ -42,46 +43,47 @@ describe('HTTP', function() {
it('should create wallet', async () => { it('should create wallet', async () => {
const info = await wallet.create({ id: 'test' }); const info = await wallet.create({ id: 'test' });
assert.equal(info.id, 'test'); assert.strictEqual(info.id, 'test');
}); });
it('should get info', async () => { it('should get info', async () => {
const info = await wallet.client.getInfo(); const info = await wallet.client.getInfo();
assert.equal(info.network, node.network.type); assert.strictEqual(info.network, node.network.type);
assert.equal(info.version, pkg.version); assert.strictEqual(info.version, pkg.version);
assert.equal(info.pool.agent, node.pool.options.agent); assert.strictEqual(info.pool.agent, node.pool.options.agent);
assert.equal(typeof info.chain, 'object'); assert.strictEqual(typeof info.chain, 'object');
assert.equal(info.chain.height, 0); assert.strictEqual(info.chain.height, 0);
}); });
it('should get wallet info', async () => { it('should get wallet info', async () => {
const info = await wallet.getInfo(); const info = await wallet.getInfo();
assert.equal(info.id, 'test'); assert.strictEqual(info.id, 'test');
addr = info.account.receiveAddress; addr = info.account.receiveAddress;
assert.equal(typeof addr, 'string'); assert.strictEqual(typeof addr, 'string');
addr = Address.fromString(addr); addr = Address.fromString(addr);
}); });
it('should fill with funds', async () => { it('should fill with funds', async () => {
let tx, balance, receive, details; const mtx = new MTX();
mtx.addOutpoint(new Outpoint(encoding.NULL_HASH, 0));
mtx.addOutput(addr, 50460);
mtx.addOutput(addr, 50460);
mtx.addOutput(addr, 50460);
mtx.addOutput(addr, 50460);
// Coinbase const tx = mtx.toTX();
tx = new MTX();
tx.addOutpoint(new Outpoint(encoding.NULL_HASH, 0));
tx.addOutput(addr, 50460);
tx.addOutput(addr, 50460);
tx.addOutput(addr, 50460);
tx.addOutput(addr, 50460);
tx = tx.toTX();
let balance = null;
wallet.once('balance', (b) => { wallet.once('balance', (b) => {
balance = b; balance = b;
}); });
let receive = null;
wallet.once('address', (r) => { wallet.once('address', (r) => {
receive = r[0]; receive = r[0];
}); });
let details = null;
wallet.once('tx', (d) => { wallet.once('tx', (d) => {
details = d; details = d;
}); });
@ -90,25 +92,23 @@ describe('HTTP', function() {
await co.timeout(300); await co.timeout(300);
assert(receive); assert(receive);
assert.equal(receive.id, 'test'); assert.strictEqual(receive.id, 'test');
assert.equal(receive.type, 'pubkeyhash'); assert.strictEqual(receive.type, 'pubkeyhash');
assert.equal(receive.branch, 0); assert.strictEqual(receive.branch, 0);
assert(balance); assert(balance);
assert.equal(balance.confirmed, 0); assert.strictEqual(balance.confirmed, 0);
assert.equal(balance.unconfirmed, 201840); assert.strictEqual(balance.unconfirmed, 201840);
assert(details); assert(details);
assert.equal(details.hash, tx.rhash()); assert.strictEqual(details.hash, tx.rhash());
}); });
it('should get balance', async () => { it('should get balance', async () => {
const balance = await wallet.getBalance(); const balance = await wallet.getBalance();
assert.equal(balance.confirmed, 0); assert.strictEqual(balance.confirmed, 0);
assert.equal(balance.unconfirmed, 201840); assert.strictEqual(balance.unconfirmed, 201840);
}); });
it('should send a tx', async () => { it('should send a tx', async () => {
let value = 0;
const options = { const options = {
rate: 10000, rate: 10000,
outputs: [{ outputs: [{
@ -120,12 +120,14 @@ describe('HTTP', function() {
const tx = await wallet.send(options); const tx = await wallet.send(options);
assert(tx); assert(tx);
assert.equal(tx.inputs.length, 1); assert.strictEqual(tx.inputs.length, 1);
assert.equal(tx.outputs.length, 2); assert.strictEqual(tx.outputs.length, 2);
let value = 0;
value += tx.outputs[0].value; value += tx.outputs[0].value;
value += tx.outputs[1].value; value += tx.outputs[1].value;
assert.equal(value, 48190);
assert.strictEqual(value, 48190);
hash = tx.hash; hash = tx.hash;
}); });
@ -133,24 +135,24 @@ describe('HTTP', function() {
it('should get a tx', async () => { it('should get a tx', async () => {
const tx = await wallet.getTX(hash); const tx = await wallet.getTX(hash);
assert(tx); assert(tx);
assert.equal(tx.hash, hash); assert.strictEqual(tx.hash, hash);
}); });
it('should generate new api key', async () => { it('should generate new api key', async () => {
const t = wallet.token.toString('hex'); const old = wallet.token.toString('hex');
const token = await wallet.retoken(null); const token = await wallet.retoken(null);
assert(token.length === 64); assert(token.length === 64);
assert.notEqual(token, t); assert.notStrictEqual(token, old);
}); });
it('should get balance', async () => { it('should get balance', async () => {
const balance = await wallet.getBalance(); const balance = await wallet.getBalance();
assert.equal(balance.unconfirmed, 199570); assert.strictEqual(balance.unconfirmed, 199570);
}); });
it('should execute an rpc call', async () => { it('should execute an rpc call', async () => {
const info = await wallet.client.rpc.execute('getblockchaininfo', []); const info = await wallet.client.rpc.execute('getblockchaininfo', []);
assert.equal(info.blocks, 0); assert.strictEqual(info.blocks, 0);
}); });
it('should execute an rpc call with bool parameter', async () => { it('should execute an rpc call with bool parameter', async () => {
@ -162,10 +164,10 @@ describe('HTTP', function() {
const info = await wallet.createAccount('foo1'); const info = await wallet.createAccount('foo1');
assert(info); assert(info);
assert(info.initialized); assert(info.initialized);
assert.equal(info.name, 'foo1'); assert.strictEqual(info.name, 'foo1');
assert.equal(info.accountIndex, 1); assert.strictEqual(info.accountIndex, 1);
assert.equal(info.m, 1); assert.strictEqual(info.m, 1);
assert.equal(info.n, 1); assert.strictEqual(info.n, 1);
}); });
it('should create account', async () => { it('should create account', async () => {
@ -176,10 +178,10 @@ describe('HTTP', function() {
}); });
assert(info); assert(info);
assert(!info.initialized); assert(!info.initialized);
assert.equal(info.name, 'foo2'); assert.strictEqual(info.name, 'foo2');
assert.equal(info.accountIndex, 2); assert.strictEqual(info.accountIndex, 2);
assert.equal(info.m, 1); assert.strictEqual(info.m, 1);
assert.equal(info.n, 2); assert.strictEqual(info.n, 2);
}); });
it('should get a block template', async () => { it('should get a block template', async () => {

View File

@ -4,48 +4,48 @@
'use strict'; 'use strict';
const assert = require('assert'); const assert = require('assert');
const keyring = require('../lib/primitives/keyring'); const KeyRing = require('../lib/primitives/keyring');
describe('Keyring Address', function() { describe('KeyRing', function() {
const ukey = keyring.fromSecret( const ukey = KeyRing.fromSecret(
'5KYZdUEo39z3FPrtuX2QbbwGnNP5zTd7yyr2SC1j299sBCnWjss'); '5KYZdUEo39z3FPrtuX2QbbwGnNP5zTd7yyr2SC1j299sBCnWjss');
const ckey = keyring.fromSecret( const ckey = KeyRing.fromSecret(
'L4rK1yDtCWekvXuE6oXD9jCYfFNV2cWRpVuPLBcCU2z8TrisoyY1'); 'L4rK1yDtCWekvXuE6oXD9jCYfFNV2cWRpVuPLBcCU2z8TrisoyY1');
it('check uncompressed public key', () => { it('check uncompressed public key', () => {
assert.equal( assert.strictEqual(
'04a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd5b' '04a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd5b'
+ '8dec5235a0fa8722476c7709c02559e3aa73aa03918ba2d492eea75abea235', + '8dec5235a0fa8722476c7709c02559e3aa73aa03918ba2d492eea75abea235',
ukey.getPublicKey('hex')); ukey.getPublicKey('hex'));
}); });
it('check uncompressed public key to address', () => { it('check uncompressed public key to address', () => {
assert.equal( assert.strictEqual(
'1HZwkjkeaoZfTSaJxDw6aKkxp45agDiEzN', '1HZwkjkeaoZfTSaJxDw6aKkxp45agDiEzN',
ukey.getKeyAddress('base58')); ukey.getKeyAddress('base58'));
}); });
it('check uncompressed secret', () => { it('check uncompressed secret', () => {
assert.equal( assert.strictEqual(
'5KYZdUEo39z3FPrtuX2QbbwGnNP5zTd7yyr2SC1j299sBCnWjss', '5KYZdUEo39z3FPrtuX2QbbwGnNP5zTd7yyr2SC1j299sBCnWjss',
ukey.toSecret()); ukey.toSecret());
}); });
it('check compressed public key', () => { it('check compressed public key', () => {
assert.equal( assert.strictEqual(
'03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd', '03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd',
ckey.getPublicKey('hex')); ckey.getPublicKey('hex'));
}); });
it('check compressed public key to address', () => { it('check compressed public key to address', () => {
assert.equal( assert.strictEqual(
'1F3sAm6ZtwLAUnj7d38pGFxtP3RVEvtsbV', '1F3sAm6ZtwLAUnj7d38pGFxtP3RVEvtsbV',
ckey.getKeyAddress('base58')); ckey.getKeyAddress('base58'));
}); });
it('check compressed secret', () => { it('check compressed secret', () => {
assert.equal( assert.strictEqual(
'L4rK1yDtCWekvXuE6oXD9jCYfFNV2cWRpVuPLBcCU2z8TrisoyY1', 'L4rK1yDtCWekvXuE6oXD9jCYfFNV2cWRpVuPLBcCU2z8TrisoyY1',
ckey.toSecret()); ckey.toSecret());
}); });

View File

@ -17,134 +17,147 @@ const Outpoint = require('../lib/primitives/outpoint');
const Script = require('../lib/script/script'); const Script = require('../lib/script/script');
const Witness = require('../lib/script/witness'); const Witness = require('../lib/script/witness');
const MemWallet = require('./util/memwallet'); const MemWallet = require('./util/memwallet');
const ALL = Script.hashType.ALL;
const chain = new Chain({
db: 'memory'
});
const mempool = new Mempool({
chain,
db: 'memory'
});
const wallet = new MemWallet();
let cachedTX = null;
function dummyInput(script, hash) {
const coin = new Coin();
coin.height = 0;
coin.value = 0;
coin.script = script;
coin.hash = hash;
coin.index = 0;
const fund = new MTX();
fund.addCoin(coin);
fund.addOutput(script, 70000);
const [tx, view] = fund.commit();
const entry = MempoolEntry.fromTX(tx, view, 0);
mempool.trackEntry(entry, view);
return Coin.fromTX(fund, 0, -1);
}
describe('Mempool', function() { describe('Mempool', function() {
const chain = new Chain({ db: 'memory' });
const mempool = new Mempool({ chain: chain, db: 'memory' });
const wallet = new MemWallet();
let cached;
this.timeout(5000); this.timeout(5000);
function dummy(prev, prevHash) {
if (!prevHash)
prevHash = encoding.ONE_HASH.toString('hex');
const coin = new Coin();
coin.height = 0;
coin.value = 0;
coin.script = prev;
coin.hash = prevHash;
coin.index = 0;
const fund = new MTX();
fund.addCoin(coin);
fund.addOutput(prev, 70000);
const entry = MempoolEntry.fromTX(fund.toTX(), fund.view, 0);
mempool.trackEntry(entry, fund.view);
return Coin.fromTX(fund, 0, -1);
}
it('should open mempool', async () => { it('should open mempool', async () => {
await mempool.open(); await mempool.open();
chain.state.flags |= Script.flags.VERIFY_WITNESS; chain.state.flags |= Script.flags.VERIFY_WITNESS;
}); });
it('should handle incoming orphans and TXs', async () => { it('should handle incoming orphans and TXs', async () => {
const kp = KeyRing.generate(); const key = KeyRing.generate();
const w = wallet;
let t1 = new MTX(); const t1 = new MTX();
t1.addOutput(w.getAddress(), 50000); t1.addOutput(wallet.getAddress(), 50000);
t1.addOutput(w.getAddress(), 10000); t1.addOutput(wallet.getAddress(), 10000);
const script = Script.fromPubkey(key.publicKey);
t1.addCoin(dummyInput(script, encoding.ONE_HASH.toString('hex')));
const sig = t1.signature(0, script, 70000, key.privateKey, ALL, 0);
const prev = Script.fromPubkey(kp.publicKey);
t1.addCoin(dummy(prev));
const sig = t1.signature(
0, prev, 70000, kp.privateKey, Script.hashType.ALL, 0);
t1.inputs[0].script = new Script([sig]); t1.inputs[0].script = new Script([sig]);
// balance: 51000 // balance: 51000
w.sign(t1); wallet.sign(t1);
t1 = t1.toTX();
let t2 = new MTX(); const t2 = new MTX();
t2.addTX(t1, 0); // 50000 t2.addTX(t1, 0); // 50000
t2.addOutput(w.getAddress(), 20000); t2.addOutput(wallet.getAddress(), 20000);
t2.addOutput(w.getAddress(), 20000); t2.addOutput(wallet.getAddress(), 20000);
// balance: 49000 // balance: 49000
w.sign(t2); wallet.sign(t2);
t2 = t2.toTX();
let t3 = new MTX(); const t3 = new MTX();
t3.addTX(t1, 1); // 10000 t3.addTX(t1, 1); // 10000
t3.addTX(t2, 0); // 20000 t3.addTX(t2, 0); // 20000
t3.addOutput(w.getAddress(), 23000); t3.addOutput(wallet.getAddress(), 23000);
// balance: 47000 // balance: 47000
w.sign(t3); wallet.sign(t3);
t3 = t3.toTX();
let t4 = new MTX(); const t4 = new MTX();
t4.addTX(t2, 1); // 24000 t4.addTX(t2, 1); // 24000
t4.addTX(t3, 0); // 23000 t4.addTX(t3, 0); // 23000
t4.addOutput(w.getAddress(), 11000); t4.addOutput(wallet.getAddress(), 11000);
t4.addOutput(w.getAddress(), 11000); t4.addOutput(wallet.getAddress(), 11000);
// balance: 22000 // balance: 22000
w.sign(t4); wallet.sign(t4);
t4 = t4.toTX();
let f1 = new MTX(); const f1 = new MTX();
f1.addTX(t4, 1); // 11000 f1.addTX(t4, 1); // 11000
f1.addOutput(new Address(), 9000); f1.addOutput(new Address(), 9000);
// balance: 11000 // balance: 11000
w.sign(f1); wallet.sign(f1);
f1 = f1.toTX();
let fake = new MTX(); const fake = new MTX();
fake.addTX(t1, 1); // 1000 (already redeemed) fake.addTX(t1, 1); // 1000 (already redeemed)
fake.addOutput(w.getAddress(), 6000); // 6000 instead of 500 fake.addOutput(wallet.getAddress(), 6000); // 6000 instead of 500
// Script inputs but do not sign // Script inputs but do not sign
w.template(fake); wallet.template(fake);
// Fake signature // Fake signature
fake.inputs[0].script.set(0, encoding.ZERO_SIG); fake.inputs[0].script.set(0, encoding.ZERO_SIG);
fake.inputs[0].script.compile(); fake.inputs[0].script.compile();
fake = fake.toTX();
// balance: 11000 // balance: 11000
await mempool.addTX(fake); {
await mempool.addTX(t4); await mempool.addTX(fake.toTX());
await mempool.addTX(t4.toTX());
let balance = mempool.getBalance(); const balance = mempool.getBalance();
assert.equal(balance, 70000); // note: funding balance assert.strictEqual(balance, 70000); // note: funding balance
}
await mempool.addTX(t1); {
await mempool.addTX(t1.toTX());
balance = mempool.getBalance(); const balance = mempool.getBalance();
assert.equal(balance, 60000); assert.strictEqual(balance, 60000);
}
await mempool.addTX(t2); {
await mempool.addTX(t2.toTX());
balance = mempool.getBalance(); const balance = mempool.getBalance();
assert.equal(balance, 50000); assert.strictEqual(balance, 50000);
}
await mempool.addTX(t3); {
await mempool.addTX(t3.toTX());
balance = mempool.getBalance(); const balance = mempool.getBalance();
assert.equal(balance, 22000); assert.strictEqual(balance, 22000);
}
await mempool.addTX(f1); {
await mempool.addTX(f1.toTX());
balance = mempool.getBalance(); const balance = mempool.getBalance();
assert.equal(balance, 20000); assert.strictEqual(balance, 20000);
}
const txs = mempool.getHistory(); const txs = mempool.getHistory();
assert(txs.some((tx) => { assert(txs.some((tx) => {
@ -153,54 +166,47 @@ describe('Mempool', function() {
}); });
it('should handle locktime', async () => { it('should handle locktime', async () => {
const w = wallet; const key = KeyRing.generate();
const kp = KeyRing.generate();
let tx = new MTX(); const tx = new MTX();
tx.addOutput(w.getAddress(), 50000); tx.addOutput(wallet.getAddress(), 50000);
tx.addOutput(w.getAddress(), 10000); tx.addOutput(wallet.getAddress(), 10000);
const prev = Script.fromPubkey(kp.publicKey); const prev = Script.fromPubkey(key.publicKey);
const prevHash = random.randomBytes(32).toString('hex'); const prevHash = random.randomBytes(32).toString('hex');
tx.addCoin(dummy(prev, prevHash)); tx.addCoin(dummyInput(prev, prevHash));
tx.setLocktime(200); tx.setLocktime(200);
chain.tip.height = 200; chain.tip.height = 200;
const sig = tx.signature( const sig = tx.signature(0, prev, 70000, key.privateKey, ALL, 0);
0, prev, 70000, kp.privateKey, Script.hashType.ALL, 0);
tx.inputs[0].script = new Script([sig]); tx.inputs[0].script = new Script([sig]);
tx = tx.toTX(); await mempool.addTX(tx.toTX());
await mempool.addTX(tx);
chain.tip.height = 0; chain.tip.height = 0;
}); });
it('should handle invalid locktime', async () => { it('should handle invalid locktime', async () => {
const w = wallet; const key = KeyRing.generate();
const kp = KeyRing.generate();
let tx = new MTX(); const tx = new MTX();
tx.addOutput(w.getAddress(), 50000); tx.addOutput(wallet.getAddress(), 50000);
tx.addOutput(w.getAddress(), 10000); tx.addOutput(wallet.getAddress(), 10000);
const prev = Script.fromPubkey(kp.publicKey); const prev = Script.fromPubkey(key.publicKey);
const prevHash = random.randomBytes(32).toString('hex'); const prevHash = random.randomBytes(32).toString('hex');
tx.addCoin(dummy(prev, prevHash)); tx.addCoin(dummyInput(prev, prevHash));
tx.setLocktime(200); tx.setLocktime(200);
chain.tip.height = 200 - 1; chain.tip.height = 200 - 1;
const sig = tx.signature( const sig = tx.signature(0, prev, 70000, key.privateKey, ALL, 0);
0, prev, 70000, kp.privateKey, Script.hashType.ALL, 0);
tx.inputs[0].script = new Script([sig]); tx.inputs[0].script = new Script([sig]);
tx = tx.toTX();
let err; let err;
try { try {
await mempool.addTX(tx); await mempool.addTX(tx.toTX());
} catch (e) { } catch (e) {
err = e; err = e;
} }
@ -211,32 +217,29 @@ describe('Mempool', function() {
}); });
it('should not cache a malleated wtx with mutated sig', async () => { it('should not cache a malleated wtx with mutated sig', async () => {
const w = wallet; const key = KeyRing.generate();
const kp = KeyRing.generate();
kp.witness = true; key.witness = true;
let tx = new MTX(); const tx = new MTX();
tx.addOutput(w.getAddress(), 50000); tx.addOutput(wallet.getAddress(), 50000);
tx.addOutput(w.getAddress(), 10000); tx.addOutput(wallet.getAddress(), 10000);
const prev = Script.fromProgram(0, kp.getKeyHash()); const prev = Script.fromProgram(0, key.getKeyHash());
const prevHash = random.randomBytes(32).toString('hex'); const prevHash = random.randomBytes(32).toString('hex');
tx.addCoin(dummy(prev, prevHash)); tx.addCoin(dummyInput(prev, prevHash));
const prevs = Script.fromPubkeyhash(kp.getKeyHash()); const prevs = Script.fromPubkeyhash(key.getKeyHash());
const sig = tx.signature( const sig = tx.signature(0, prevs, 70000, key.privateKey, ALL, 1);
0, prevs, 70000, kp.privateKey, Script.hashType.ALL, 1);
sig[sig.length - 1] = 0; sig[sig.length - 1] = 0;
tx.inputs[0].witness = new Witness([sig, kp.publicKey]); tx.inputs[0].witness = new Witness([sig, key.publicKey]);
tx = tx.toTX();
let err; let err;
try { try {
await mempool.addTX(tx); await mempool.addTX(tx.toTX());
} catch (e) { } catch (e) {
err = e; err = e;
} }
@ -246,27 +249,24 @@ describe('Mempool', function() {
}); });
it('should not cache a malleated tx with unnecessary witness', async () => { it('should not cache a malleated tx with unnecessary witness', async () => {
const w = wallet; const key = KeyRing.generate();
const kp = KeyRing.generate();
let tx = new MTX(); const tx = new MTX();
tx.addOutput(w.getAddress(), 50000); tx.addOutput(wallet.getAddress(), 50000);
tx.addOutput(w.getAddress(), 10000); tx.addOutput(wallet.getAddress(), 10000);
const prev = Script.fromPubkey(kp.publicKey); const prev = Script.fromPubkey(key.publicKey);
const prevHash = random.randomBytes(32).toString('hex'); const prevHash = random.randomBytes(32).toString('hex');
tx.addCoin(dummy(prev, prevHash)); tx.addCoin(dummyInput(prev, prevHash));
const sig = tx.signature( const sig = tx.signature(0, prev, 70000, key.privateKey, ALL, 0);
0, prev, 70000, kp.privateKey, Script.hashType.ALL, 0);
tx.inputs[0].script = new Script([sig]); tx.inputs[0].script = new Script([sig]);
tx.inputs[0].witness.push(Buffer.alloc(0)); tx.inputs[0].witness.push(Buffer.alloc(0));
tx = tx.toTX();
let err; let err;
try { try {
await mempool.addTX(tx); await mempool.addTX(tx.toTX());
} catch (e) { } catch (e) {
err = e; err = e;
} }
@ -276,25 +276,22 @@ describe('Mempool', function() {
}); });
it('should not cache a malleated wtx with wit removed', async () => { it('should not cache a malleated wtx with wit removed', async () => {
const w = wallet; const key = KeyRing.generate();
const kp = KeyRing.generate();
kp.witness = true; key.witness = true;
let tx = new MTX(); const tx = new MTX();
tx.addOutput(w.getAddress(), 50000); tx.addOutput(wallet.getAddress(), 50000);
tx.addOutput(w.getAddress(), 10000); tx.addOutput(wallet.getAddress(), 10000);
const prev = Script.fromProgram(0, kp.getKeyHash()); const prev = Script.fromProgram(0, key.getKeyHash());
const prevHash = random.randomBytes(32).toString('hex'); const prevHash = random.randomBytes(32).toString('hex');
tx.addCoin(dummy(prev, prevHash)); tx.addCoin(dummyInput(prev, prevHash));
tx = tx.toTX();
let err; let err;
try { try {
await mempool.addTX(tx); await mempool.addTX(tx.toTX());
} catch (e) { } catch (e) {
err = e; err = e;
} }
@ -305,23 +302,20 @@ describe('Mempool', function() {
}); });
it('should cache non-malleated tx without sig', async () => { it('should cache non-malleated tx without sig', async () => {
const w = wallet; const key = KeyRing.generate();
const kp = KeyRing.generate();
let tx = new MTX(); const tx = new MTX();
tx.addOutput(w.getAddress(), 50000); tx.addOutput(wallet.getAddress(), 50000);
tx.addOutput(w.getAddress(), 10000); tx.addOutput(wallet.getAddress(), 10000);
const prev = Script.fromPubkey(kp.publicKey); const prev = Script.fromPubkey(key.publicKey);
const prevHash = random.randomBytes(32).toString('hex'); const prevHash = random.randomBytes(32).toString('hex');
tx.addCoin(dummy(prev, prevHash)); tx.addCoin(dummyInput(prev, prevHash));
tx = tx.toTX();
let err; let err;
try { try {
await mempool.addTX(tx); await mempool.addTX(tx.toTX());
} catch (e) { } catch (e) {
err = e; err = e;
} }
@ -329,20 +323,20 @@ describe('Mempool', function() {
assert(err); assert(err);
assert(!err.malleated); assert(!err.malleated);
assert(mempool.hasReject(tx.hash())); assert(mempool.hasReject(tx.hash()));
cached = tx;
cachedTX = tx;
}); });
it('should clear reject cache', async () => { it('should clear reject cache', async () => {
const w = wallet; const tx = new MTX();
let tx = new MTX();
tx.addOutpoint(new Outpoint()); tx.addOutpoint(new Outpoint());
tx.addOutput(w.getAddress(), 50000); tx.addOutput(wallet.getAddress(), 50000);
tx = tx.toTX();
assert(mempool.hasReject(cached.hash())); assert(mempool.hasReject(cachedTX.hash()));
await mempool.addBlock({ height: 1 }, [tx]);
assert(!mempool.hasReject(cached.hash())); await mempool.addBlock({ height: 1 }, [tx.toTX()]);
assert(!mempool.hasReject(cachedTX.hash()));
}); });
it('should destroy mempool', async () => { it('should destroy mempool', async () => {

View File

@ -30,11 +30,11 @@ describe('Mnemonic', function() {
passphrase: passphrase passphrase: passphrase
}); });
assert.equal(mnemonic.getPhrase(), phrase); assert.strictEqual(mnemonic.getPhrase(), phrase);
assert.equal(mnemonic.toSeed().toString('hex'), seed.toString('hex')); assert.deepStrictEqual(mnemonic.toSeed(), seed);
const key = HDPrivateKey.fromMnemonic(mnemonic); const key = HDPrivateKey.fromMnemonic(mnemonic);
assert.equal(key.toBase58(), xpriv); assert.strictEqual(key.toBase58(), xpriv);
}); });
} }
} }
@ -42,9 +42,9 @@ describe('Mnemonic', function() {
it('should verify phrase', () => { it('should verify phrase', () => {
const m1 = new Mnemonic(); const m1 = new Mnemonic();
const m2 = Mnemonic.fromPhrase(m1.getPhrase()); const m2 = Mnemonic.fromPhrase(m1.getPhrase());
assert.deepEqual(m2.getEntropy(), m1.getEntropy()); assert.deepStrictEqual(m2.getEntropy(), m1.getEntropy());
assert.equal(m2.bits, m1.bits); assert.strictEqual(m2.bits, m1.bits);
assert.equal(m2.language, m1.language); assert.strictEqual(m2.language, m1.language);
assert.deepEqual(m2.toSeed(), m1.toSeed()); assert.deepStrictEqual(m2.toSeed(), m1.toSeed());
}); });
}); });

View File

@ -14,47 +14,77 @@ const MTX = require('../lib/primitives/mtx');
const TX = require('../lib/primitives/tx'); const TX = require('../lib/primitives/tx');
const Address = require('../lib/primitives/address'); const Address = require('../lib/primitives/address');
describe('Node', function() { const node = new FullNode({
const node = new FullNode({ db: 'memory',
db: 'memory', apiKey: 'foo',
apiKey: 'foo', network: 'regtest',
network: 'regtest', workers: true,
workers: true, plugins: [require('../lib/wallet/plugin')]
plugins: [require('../lib/wallet/plugin')] });
const chain = node.chain;
const miner = node.miner;
const wdb = node.require('walletdb');
let wallet = null;
let tip1 = null;
let tip2 = null;
let cb1 = null;
let cb2 = null;
let tx1 = null;
let tx2 = null;
async function mineBlock(tip, tx) {
const job = await miner.createJob(tip);
if (!tx)
return await job.mineAsync();
const spend = new MTX();
spend.addTX(tx, 0);
spend.addOutput(wallet.getReceive(), 25 * 1e8);
spend.addOutput(wallet.getChange(), 5 * 1e8);
spend.setLocktime(chain.height);
await wallet.sign(spend);
job.addTX(spend.toTX(), spend.view);
job.refresh();
return await job.mineAsync();
}
async function mineCSV(fund) {
const job = await miner.createJob();
const spend = new MTX();
spend.addOutput({
script: [
Script.array(new BN(1)),
Script.opcodes.OP_CHECKSEQUENCEVERIFY
],
value: 10 * 1e8
}); });
const chain = node.chain; spend.addTX(fund, 0);
const miner = node.miner; spend.setLocktime(chain.height);
const wdb = node.require('walletdb');
let wallet, tip1, tip2, cb1, cb2; await wallet.sign(spend);
let tx1, tx2;
const [tx, view] = spend.commit();
job.addTX(tx, view);
job.refresh();
return await job.mineAsync();
}
describe('Node', function() {
this.timeout(5000); this.timeout(5000);
async function mineBlock(tip, tx) {
const job = await miner.createJob(tip);
if (!tx)
return await job.mineAsync();
const rtx = new MTX();
rtx.addTX(tx, 0);
rtx.addOutput(wallet.getReceive(), 25 * 1e8);
rtx.addOutput(wallet.getChange(), 5 * 1e8);
rtx.setLocktime(chain.height);
await wallet.sign(rtx);
job.addTX(rtx.toTX(), rtx.view);
job.refresh();
return await job.mineAsync();
}
it('should open chain and miner', async () => { it('should open chain and miner', async () => {
miner.mempool = null; miner.mempool = null;
consensus.COINBASE_MATURITY = 0; consensus.COINBASE_MATURITY = 0;
@ -100,22 +130,22 @@ describe('Node', function() {
}); });
it('should have correct chain value', () => { it('should have correct chain value', () => {
assert.equal(chain.db.state.value, 55000000000); assert.strictEqual(chain.db.state.value, 55000000000);
assert.equal(chain.db.state.coin, 20); assert.strictEqual(chain.db.state.coin, 20);
assert.equal(chain.db.state.tx, 21); assert.strictEqual(chain.db.state.tx, 21);
}); });
it('should have correct balance', async () => { it('should have correct balance', async () => {
await co.timeout(100); await co.timeout(100);
const balance = await wallet.getBalance(); const balance = await wallet.getBalance();
assert.equal(balance.unconfirmed, 550 * 1e8); assert.strictEqual(balance.unconfirmed, 550 * 1e8);
assert.equal(balance.confirmed, 550 * 1e8); assert.strictEqual(balance.confirmed, 550 * 1e8);
}); });
it('should handle a reorg', async () => { it('should handle a reorg', async () => {
assert.equal(wdb.state.height, chain.height); assert.strictEqual(wdb.state.height, chain.height);
assert.equal(chain.height, 11); assert.strictEqual(chain.height, 11);
const entry = await chain.db.getEntry(tip2.hash); const entry = await chain.db.getEntry(tip2.hash);
assert(entry); assert(entry);
@ -137,17 +167,17 @@ describe('Node', function() {
}); });
it('should have correct chain value', () => { it('should have correct chain value', () => {
assert.equal(chain.db.state.value, 60000000000); assert.strictEqual(chain.db.state.value, 60000000000);
assert.equal(chain.db.state.coin, 21); assert.strictEqual(chain.db.state.coin, 21);
assert.equal(chain.db.state.tx, 22); assert.strictEqual(chain.db.state.tx, 22);
}); });
it('should have correct balance', async () => { it('should have correct balance', async () => {
await co.timeout(100); await co.timeout(100);
const balance = await wallet.getBalance(); const balance = await wallet.getBalance();
assert.equal(balance.unconfirmed, 1100 * 1e8); assert.strictEqual(balance.unconfirmed, 1100 * 1e8);
assert.equal(balance.confirmed, 600 * 1e8); assert.strictEqual(balance.confirmed, 600 * 1e8);
}); });
it('should check main chain', async () => { it('should check main chain', async () => {
@ -171,8 +201,8 @@ describe('Node', function() {
it('should prevent double spend on new chain', async () => { it('should prevent double spend on new chain', async () => {
const block = await mineBlock(null, cb2); const block = await mineBlock(null, cb2);
const tip = chain.tip; const tip = chain.tip;
let err;
let err;
try { try {
await chain.add(block); await chain.add(block);
} catch (e) { } catch (e) {
@ -180,15 +210,15 @@ describe('Node', function() {
} }
assert(err); assert(err);
assert.equal(err.reason, 'bad-txns-inputs-missingorspent'); assert.strictEqual(err.reason, 'bad-txns-inputs-missingorspent');
assert(chain.tip === tip); assert(chain.tip === tip);
}); });
it('should fail to mine block with coins on an alternate chain', async () => { it('should fail to mine block with coins on an alternate chain', async () => {
const block = await mineBlock(null, cb1); const block = await mineBlock(null, cb1);
const tip = chain.tip; const tip = chain.tip;
let err;
let err;
try { try {
await chain.add(block); await chain.add(block);
} catch (e) { } catch (e) {
@ -196,59 +226,63 @@ describe('Node', function() {
} }
assert(err); assert(err);
assert.equal(err.reason, 'bad-txns-inputs-missingorspent'); assert.strictEqual(err.reason, 'bad-txns-inputs-missingorspent');
assert(chain.tip === tip); assert(chain.tip === tip);
}); });
it('should have correct chain value', () => { it('should have correct chain value', () => {
assert.equal(chain.db.state.value, 65000000000); assert.strictEqual(chain.db.state.value, 65000000000);
assert.equal(chain.db.state.coin, 23); assert.strictEqual(chain.db.state.coin, 23);
assert.equal(chain.db.state.tx, 24); assert.strictEqual(chain.db.state.tx, 24);
}); });
it('should get coin', async () => { it('should get coin', async () => {
let block = await mineBlock(); const block1 = await mineBlock();
await chain.add(block); await chain.add(block1);
block = await mineBlock(null, block.txs[0]); const block2 = await mineBlock(null, block1.txs[0]);
await chain.add(block); await chain.add(block2);
const tx = block.txs[1]; const tx = block2.txs[1];
const output = Coin.fromTX(tx, 1, chain.height); const output = Coin.fromTX(tx, 1, chain.height);
const coin = await chain.db.getCoin(tx.hash('hex'), 1); const coin = await chain.db.getCoin(tx.hash('hex'), 1);
assert.deepEqual(coin.toRaw(), output.toRaw()); assert.deepStrictEqual(coin.toRaw(), output.toRaw());
}); });
it('should get balance', async () => { it('should get balance', async () => {
await co.timeout(100); await co.timeout(100);
const balance = await wallet.getBalance(); const balance = await wallet.getBalance();
assert.equal(balance.unconfirmed, 1250 * 1e8); assert.strictEqual(balance.unconfirmed, 1250 * 1e8);
assert.equal(balance.confirmed, 750 * 1e8); assert.strictEqual(balance.confirmed, 750 * 1e8);
assert(wallet.account.receiveDepth >= 7); assert(wallet.account.receiveDepth >= 7);
assert(wallet.account.changeDepth >= 6); assert(wallet.account.changeDepth >= 6);
assert.equal(wdb.state.height, chain.height); assert.strictEqual(wdb.state.height, chain.height);
const txs = await wallet.getHistory(); const txs = await wallet.getHistory();
assert.equal(txs.length, 45); assert.strictEqual(txs.length, 45);
}); });
it('should get tips and remove chains', async () => { it('should get tips and remove chains', async () => {
let tips = await chain.db.getTips(); {
const tips = await chain.db.getTips();
assert.notEqual(tips.indexOf(chain.tip.hash), -1); assert.notStrictEqual(tips.indexOf(chain.tip.hash), -1);
assert.equal(tips.length, 2); assert.strictEqual(tips.length, 2);
}
await chain.db.removeChains(); await chain.db.removeChains();
tips = await chain.db.getTips(); {
const tips = await chain.db.getTips();
assert.notEqual(tips.indexOf(chain.tip.hash), -1); assert.notStrictEqual(tips.indexOf(chain.tip.hash), -1);
assert.equal(tips.length, 1); assert.strictEqual(tips.length, 1);
}
}); });
it('should rescan for transactions', async () => { it('should rescan for transactions', async () => {
@ -258,7 +292,7 @@ describe('Node', function() {
total += txs.length; total += txs.length;
}); });
assert.equal(total, 26); assert.strictEqual(total, 26);
}); });
it('should activate csv', async () => { it('should activate csv', async () => {
@ -297,46 +331,22 @@ describe('Node', function() {
assert(chain.state.hasCSV()); assert(chain.state.hasCSV());
const cache = await chain.db.getStateCache(); const cache = await chain.db.getStateCache();
assert.deepEqual(cache, chain.db.stateCache); assert.deepStrictEqual(cache, chain.db.stateCache);
assert.equal(chain.db.stateCache.updates.length, 0); assert.strictEqual(chain.db.stateCache.updates.length, 0);
assert(await chain.db.verifyDeployments()); assert(await chain.db.verifyDeployments());
}); });
async function mineCSV(tx) {
const job = await miner.createJob();
const redeemer = new MTX();
redeemer.addOutput({
script: [
Script.array(new BN(1)),
Script.opcodes.OP_CHECKSEQUENCEVERIFY
],
value: 10 * 1e8
});
redeemer.addTX(tx, 0);
redeemer.setLocktime(chain.height);
await wallet.sign(redeemer);
job.addTX(redeemer.toTX(), redeemer.view);
job.refresh();
return await job.mineAsync();
}
it('should test csv', async () => { it('should test csv', async () => {
const tx = (await chain.db.getBlock(chain.height)).txs[0]; const tx = (await chain.db.getBlock(chain.height)).txs[0];
let block = await mineCSV(tx); const csvBlock = await mineCSV(tx);
await chain.add(block); await chain.add(csvBlock);
const csv = block.txs[1]; const csv = csvBlock.txs[1];
const redeemer = new MTX(); const spend = new MTX();
redeemer.addOutput({ spend.addOutput({
script: [ script: [
Script.array(new BN(2)), Script.array(new BN(2)),
Script.opcodes.OP_CHECKSEQUENCEVERIFY Script.opcodes.OP_CHECKSEQUENCEVERIFY
@ -344,24 +354,24 @@ describe('Node', function() {
value: 10 * 1e8 value: 10 * 1e8
}); });
redeemer.addTX(csv, 0); spend.addTX(csv, 0);
redeemer.setSequence(0, 1, false); spend.setSequence(0, 1, false);
const job = await miner.createJob(); const job = await miner.createJob();
job.addTX(redeemer.toTX(), redeemer.view); job.addTX(spend.toTX(), spend.view);
job.refresh(); job.refresh();
block = await job.mineAsync(); const block = await job.mineAsync();
await chain.add(block); await chain.add(block);
}); });
it('should fail csv with bad sequence', async () => { it('should fail csv with bad sequence', async () => {
const csv = (await chain.db.getBlock(chain.height)).txs[1]; const csv = (await chain.db.getBlock(chain.height)).txs[1];
const redeemer = new MTX(); const spend = new MTX();
redeemer.addOutput({ spend.addOutput({
script: [ script: [
Script.array(new BN(1)), Script.array(new BN(1)),
Script.opcodes.OP_CHECKSEQUENCEVERIFY Script.opcodes.OP_CHECKSEQUENCEVERIFY
@ -369,12 +379,12 @@ describe('Node', function() {
value: 10 * 1e8 value: 10 * 1e8
}); });
redeemer.addTX(csv, 0); spend.addTX(csv, 0);
redeemer.setSequence(0, 1, false); spend.setSequence(0, 1, false);
const job = await miner.createJob(); const job = await miner.createJob();
job.addTX(redeemer.toTX(), redeemer.view); job.addTX(spend.toTX(), spend.view);
job.refresh(); job.refresh();
const block = await job.mineAsync(); const block = await job.mineAsync();
@ -398,15 +408,15 @@ describe('Node', function() {
it('should fail csv lock checks', async () => { it('should fail csv lock checks', async () => {
const tx = (await chain.db.getBlock(chain.height)).txs[0]; const tx = (await chain.db.getBlock(chain.height)).txs[0];
let block = await mineCSV(tx); const csvBlock = await mineCSV(tx);
await chain.add(block); await chain.add(csvBlock);
const csv = block.txs[1]; const csv = csvBlock.txs[1];
const redeemer = new MTX(); const spend = new MTX();
redeemer.addOutput({ spend.addOutput({
script: [ script: [
Script.array(new BN(2)), Script.array(new BN(2)),
Script.opcodes.OP_CHECKSEQUENCEVERIFY Script.opcodes.OP_CHECKSEQUENCEVERIFY
@ -414,15 +424,15 @@ describe('Node', function() {
value: 10 * 1e8 value: 10 * 1e8
}); });
redeemer.addTX(csv, 0); spend.addTX(csv, 0);
redeemer.setSequence(0, 2, false); spend.setSequence(0, 2, false);
const job = await miner.createJob(); const job = await miner.createJob();
job.addTX(redeemer.toTX(), redeemer.view); job.addTX(spend.toTX(), spend.view);
job.refresh(); job.refresh();
block = await job.mineAsync(); const block = await job.mineAsync();
let err; let err;
try { try {
@ -432,12 +442,12 @@ describe('Node', function() {
} }
assert(err); assert(err);
assert.equal(err.reason, 'bad-txns-nonfinal'); assert.strictEqual(err.reason, 'bad-txns-nonfinal');
}); });
it('should rescan for transactions', async () => { it('should rescan for transactions', async () => {
await wdb.rescan(0); await wdb.rescan(0);
assert.equal(wallet.txdb.state.confirmed, 1289250000000); assert.strictEqual(wallet.txdb.state.confirmed, 1289250000000);
}); });
it('should reset miner mempool', async () => { it('should reset miner mempool', async () => {
@ -449,7 +459,7 @@ describe('Node', function() {
method: 'getblocktemplate' method: 'getblocktemplate'
}, {}); }, {});
assert(json.error); assert(json.error);
assert.equal(json.error.code, -8); assert.strictEqual(json.error.code, -8);
}); });
it('should get a block template', async () => { it('should get a block template', async () => {
@ -534,7 +544,7 @@ describe('Node', function() {
assert(!json.error); assert(!json.error);
assert(json.result === null); assert(json.result === null);
assert.equal(node.chain.tip.hash, block.hash('hex')); assert.strictEqual(node.chain.tip.hash, block.hash('hex'));
}); });
it('should validate an address', async () => { it('should validate an address', async () => {
@ -569,7 +579,6 @@ describe('Node', function() {
assert(mtx.isSigned()); assert(mtx.isSigned());
tx1 = mtx;
const tx = mtx.toTX(); const tx = mtx.toTX();
await wallet.db.addTX(tx); await wallet.db.addTX(tx);
@ -577,7 +586,9 @@ describe('Node', function() {
const missing = await node.mempool.addTX(tx); const missing = await node.mempool.addTX(tx);
assert(!missing || missing.length === 0); assert(!missing || missing.length === 0);
assert.equal(node.mempool.map.size, 1); assert.strictEqual(node.mempool.map.size, 1);
tx1 = mtx;
}); });
it('should add lesser transaction to mempool', async () => { it('should add lesser transaction to mempool', async () => {
@ -593,7 +604,6 @@ describe('Node', function() {
assert(mtx.isSigned()); assert(mtx.isSigned());
tx2 = mtx;
const tx = mtx.toTX(); const tx = mtx.toTX();
await wallet.db.addTX(tx); await wallet.db.addTX(tx);
@ -601,7 +611,9 @@ describe('Node', function() {
const missing = await node.mempool.addTX(tx); const missing = await node.mempool.addTX(tx);
assert(!missing || missing.length === 0); assert(!missing || missing.length === 0);
assert.equal(node.mempool.map.size, 2); assert.strictEqual(node.mempool.map.size, 2);
tx2 = mtx;
}); });
it('should get a block template', async () => { it('should get a block template', async () => {
@ -628,12 +640,12 @@ describe('Node', function() {
weight += item.weight; weight += item.weight;
} }
assert.equal(result.transactions.length, 2); assert.strictEqual(result.transactions.length, 2);
assert.equal(fees, tx1.getFee() + tx2.getFee()); assert.strictEqual(fees, tx1.getFee() + tx2.getFee());
assert.equal(weight, tx1.getWeight() + tx2.getWeight()); assert.strictEqual(weight, tx1.getWeight() + tx2.getWeight());
assert.equal(result.transactions[0].hash, tx1.txid()); assert.strictEqual(result.transactions[0].hash, tx1.txid());
assert.equal(result.transactions[1].hash, tx2.txid()); assert.strictEqual(result.transactions[1].hash, tx2.txid());
assert.equal(result.coinbasevalue, 125e7 + fees); assert.strictEqual(result.coinbasevalue, 125e7 + fees);
}); });
it('should get raw transaction', async () => { it('should get raw transaction', async () => {
@ -645,7 +657,7 @@ describe('Node', function() {
assert(!json.error); assert(!json.error);
const tx = TX.fromRaw(json.result, 'hex'); const tx = TX.fromRaw(json.result, 'hex');
assert.equal(tx.txid(), tx2.txid()); assert.strictEqual(tx.txid(), tx2.txid());
}); });
it('should prioritise transaction', async () => { it('should prioritise transaction', async () => {
@ -683,12 +695,12 @@ describe('Node', function() {
weight += item.weight; weight += item.weight;
} }
assert.equal(result.transactions.length, 2); assert.strictEqual(result.transactions.length, 2);
assert.equal(fees, tx1.getFee() + tx2.getFee()); assert.strictEqual(fees, tx1.getFee() + tx2.getFee());
assert.equal(weight, tx1.getWeight() + tx2.getWeight()); assert.strictEqual(weight, tx1.getWeight() + tx2.getWeight());
assert.equal(result.transactions[0].hash, tx2.txid()); assert.strictEqual(result.transactions[0].hash, tx2.txid());
assert.equal(result.transactions[1].hash, tx1.txid()); assert.strictEqual(result.transactions[1].hash, tx1.txid());
assert.equal(result.coinbasevalue, 125e7 + fees); assert.strictEqual(result.coinbasevalue, 125e7 + fees);
}); });
it('should cleanup', async () => { it('should cleanup', async () => {

View File

@ -32,7 +32,7 @@ describe('Protocol', function() {
it(`should encode/decode ${command}`, (cb) => { it(`should encode/decode ${command}`, (cb) => {
const ver = Buffer.from(framer.packet(command, payload.toRaw())); const ver = Buffer.from(framer.packet(command, payload.toRaw()));
parser.once('packet', (packet) => { parser.once('packet', (packet) => {
assert.equal(packet.cmd, command); assert.strictEqual(packet.cmd, command);
test(packet); test(packet);
cb(); cb();
}); });
@ -53,10 +53,10 @@ describe('Protocol', function() {
}); });
packetTest('version', v1, (payload) => { packetTest('version', v1, (payload) => {
assert.equal(payload.version, 300); assert.strictEqual(payload.version, 300);
assert.equal(payload.agent, agent); assert.strictEqual(payload.agent, agent);
assert.equal(payload.height, 0); assert.strictEqual(payload.height, 0);
assert.equal(payload.noRelay, false); assert.strictEqual(payload.noRelay, false);
}); });
const v2 = packets.VersionPacket.fromOptions({ const v2 = packets.VersionPacket.fromOptions({
@ -72,10 +72,10 @@ describe('Protocol', function() {
}); });
packetTest('version', v2, (payload) => { packetTest('version', v2, (payload) => {
assert.equal(payload.version, 300); assert.strictEqual(payload.version, 300);
assert.equal(payload.agent, agent); assert.strictEqual(payload.agent, agent);
assert.equal(payload.height, 10); assert.strictEqual(payload.height, 10);
assert.equal(payload.noRelay, true); assert.strictEqual(payload.noRelay, true);
}); });
packetTest('verack', new packets.VerackPacket(), (payload) => { packetTest('verack', new packets.VerackPacket(), (payload) => {
@ -97,18 +97,18 @@ describe('Protocol', function() {
]; ];
packetTest('addr', new packets.AddrPacket(hosts), (payload) => { packetTest('addr', new packets.AddrPacket(hosts), (payload) => {
assert.equal(typeof payload.items.length, 'number'); assert.strictEqual(typeof payload.items.length, 'number');
assert.equal(payload.items.length, 2); assert.strictEqual(payload.items.length, 2);
assert.equal(typeof payload.items[0].time, 'number'); assert.strictEqual(typeof payload.items[0].time, 'number');
assert.equal(payload.items[0].services, 1); assert.strictEqual(payload.items[0].services, 1);
assert.equal(payload.items[0].host, hosts[0].host); assert.strictEqual(payload.items[0].host, hosts[0].host);
assert.equal(payload.items[0].port, hosts[0].port); assert.strictEqual(payload.items[0].port, hosts[0].port);
assert.equal(typeof payload.items[1].time, 'number'); assert.strictEqual(typeof payload.items[1].time, 'number');
assert.equal(payload.items[1].services, 1); assert.strictEqual(payload.items[1].services, 1);
assert.equal(payload.items[1].host, hosts[1].host); assert.strictEqual(payload.items[1].host, hosts[1].host);
assert.equal(payload.items[1].port, hosts[1].port); assert.strictEqual(payload.items[1].port, hosts[1].port);
}); });
it('should include the raw data of only one transaction', () => { it('should include the raw data of only one transaction', () => {
@ -117,6 +117,6 @@ describe('Protocol', function() {
const tx = TX.fromRaw(raw); const tx = TX.fromRaw(raw);
tx.refresh(); tx.refresh();
assert.deepEqual(tx.toRaw(), tx8.tx.toRaw()); assert.deepStrictEqual(tx.toRaw(), tx8.tx.toRaw());
}); });
}); });

View File

@ -15,6 +15,6 @@ describe('Schnorr', function() {
const msg = digest.hash256(Buffer.from('foo', 'ascii')); const msg = digest.hash256(Buffer.from('foo', 'ascii'));
const sig = schnorr.sign(msg, key); const sig = schnorr.sign(msg, key);
assert(schnorr.verify(msg, sig, pub)); assert(schnorr.verify(msg, sig, pub));
assert.deepEqual(schnorr.recover(sig, msg), pub); assert.deepStrictEqual(schnorr.recover(sig, msg), pub);
}); });
}); });

View File

@ -13,7 +13,7 @@ const opcodes = Script.opcodes;
const scripts = require('./data/script-tests.json'); const scripts = require('./data/script-tests.json');
function success(res, stack) { function isSuccess(res, stack) {
if (!res) if (!res)
return false; return false;
@ -27,7 +27,7 @@ function success(res, stack) {
} }
function parseScriptTest(data) { function parseScriptTest(data) {
const witHex = Array.isArray(data[0]) ? data.shift() : []; const witArr = Array.isArray(data[0]) ? data.shift() : [];
const inpHex = data[0] ? data[0].trim() : data[0] || ''; const inpHex = data[0] ? data[0].trim() : data[0] || '';
const outHex = data[1] ? data[1].trim() : data[1] || ''; const outHex = data[1] ? data[1].trim() : data[1] || '';
const names = data[2] ? data[2].trim().split(/,\s*/) : []; const names = data[2] ? data[2].trim().split(/,\s*/) : [];
@ -40,10 +40,10 @@ function parseScriptTest(data) {
comments += ` (${expected})`; comments += ` (${expected})`;
let amount = 0; let amount = 0;
if (witHex.length !== 0) if (witArr.length !== 0)
amount = witHex.pop() * 1e8; amount = witArr.pop() * 1e8;
const witness = Witness.fromString(witHex); const witness = Witness.fromString(witArr);
const input = Script.fromString(inpHex); const input = Script.fromString(inpHex);
const output = Script.fromString(outHex); const output = Script.fromString(outHex);
@ -67,29 +67,31 @@ function parseScriptTest(data) {
describe('Script', function() { describe('Script', function() {
it('should encode/decode script', () => { it('should encode/decode script', () => {
const src = '20' const src = Buffer.from(''
+ '20'
+ '000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f' + '000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f'
+ '20' + '20'
+ '101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f' + '101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f'
+ 'ac'; + 'ac',
'hex');
const decoded = Script.fromRaw(src, 'hex'); const decoded = Script.fromRaw(src);
assert.equal(decoded.code.length, 3); assert.strictEqual(decoded.code.length, 3);
assert.equal(decoded.code[0].data.toString('hex'), assert.strictEqual(decoded.code[0].data.toString('hex'),
'000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f'); '000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f');
assert.equal(decoded.code[1].data.toString('hex'), assert.strictEqual(decoded.code[1].data.toString('hex'),
'101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f'); '101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f');
assert.equal(decoded.code[2].value, opcodes.OP_CHECKSIG); assert.strictEqual(decoded.code[2].value, opcodes.OP_CHECKSIG);
const dst = decoded.toRaw(); const dst = decoded.toRaw();
assert.equal(dst.toString('hex'), src); assert.deepStrictEqual(dst, src);
}); });
it('should encode/decode numbers', () => { it('should encode/decode numbers', () => {
const script = [0, 0x51, 0x52, 0x60]; const script = [0, 0x51, 0x52, 0x60];
const encoded = Script.fromArray(script).raw; const encoded = Script.fromArray(script).raw;
const decoded = Script(encoded).toArray(); const decoded = Script(encoded).toArray();
assert.deepEqual(decoded, script); assert.deepStrictEqual(decoded, script);
}); });
it('should recognize a P2SH output', () => { it('should recognize a P2SH output', () => {
@ -226,7 +228,7 @@ describe('Script', function() {
const stack = new Stack(); const stack = new Stack();
assert(input.execute(stack)); assert(input.execute(stack));
assert(success(output.execute(stack), stack)); assert(isSuccess(output.execute(stack), stack));
}); });
it('should handle CScriptNums correctly', () => { it('should handle CScriptNums correctly', () => {
@ -245,7 +247,7 @@ describe('Script', function() {
const stack = new Stack(); const stack = new Stack();
assert(input.execute(stack)); assert(input.execute(stack));
assert(success(output.execute(stack), stack)); assert(isSuccess(output.execute(stack), stack));
}); });
it('should handle OP_ROLL correctly', () => { it('should handle OP_ROLL correctly', () => {
@ -268,7 +270,7 @@ describe('Script', function() {
const stack = new Stack(); const stack = new Stack();
assert(input.execute(stack)); assert(input.execute(stack));
assert(success(output.execute(stack), stack)); assert(isSuccess(output.execute(stack), stack));
}); });
for (const data of scripts) { for (const data of scripts) {
@ -337,7 +339,7 @@ describe('Script', function() {
if (expected !== 'OK') { if (expected !== 'OK') {
assert(!res); assert(!res);
assert(err); assert(err);
assert.equal(err.code, expected); assert.strictEqual(err.code, expected);
return; return;
} }

View File

@ -13,7 +13,7 @@ describe('Scrypt', function() {
const pass = Buffer.from(''); const pass = Buffer.from('');
const salt = Buffer.from(''); const salt = Buffer.from('');
const result = scrypt.derive(pass, salt, 16, 1, 1, 64); const result = scrypt.derive(pass, salt, 16, 1, 1, 64);
assert.equal(result.toString('hex'), '' assert.strictEqual(result.toString('hex'), ''
+ '77d6576238657b203b19ca42c18a0497f16b4844e3074ae8dfdffa3f' + '77d6576238657b203b19ca42c18a0497f16b4844e3074ae8dfdffa3f'
+ 'ede21442fcd0069ded0948f8326a753a0fc81f17e8d3e0fb2e0d3628' + 'ede21442fcd0069ded0948f8326a753a0fc81f17e8d3e0fb2e0d3628'
+ 'cf35e20c38d18906'); + 'cf35e20c38d18906');
@ -23,7 +23,7 @@ describe('Scrypt', function() {
const pass = Buffer.from('password'); const pass = Buffer.from('password');
const salt = Buffer.from('NaCl'); const salt = Buffer.from('NaCl');
const result = scrypt.derive(pass, salt, 1024, 8, 16, 64); const result = scrypt.derive(pass, salt, 1024, 8, 16, 64);
assert.equal(result.toString('hex'), '' assert.strictEqual(result.toString('hex'), ''
+ 'fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e773' + 'fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e773'
+ '76634b3731622eaf30d92e22a3886ff109279d9830dac727afb9' + '76634b3731622eaf30d92e22a3886ff109279d9830dac727afb9'
+ '4a83ee6d8360cbdfa2cc0640'); + '4a83ee6d8360cbdfa2cc0640');
@ -33,7 +33,7 @@ describe('Scrypt', function() {
const pass = Buffer.from('pleaseletmein'); const pass = Buffer.from('pleaseletmein');
const salt = Buffer.from('SodiumChloride'); const salt = Buffer.from('SodiumChloride');
const result = scrypt.derive(pass, salt, 16384, 8, 1, 64); const result = scrypt.derive(pass, salt, 16384, 8, 1, 64);
assert.equal(result.toString('hex'), '' assert.strictEqual(result.toString('hex'), ''
+ '7023bdcb3afd7348461c06cd81fd38ebfda8fbba904f8e3ea9b54' + '7023bdcb3afd7348461c06cd81fd38ebfda8fbba904f8e3ea9b54'
+ '3f6545da1f2d5432955613f0fcf62d49705242a9af9e61e85dc0d' + '3f6545da1f2d5432955613f0fcf62d49705242a9af9e61e85dc0d'
+ '651e40dfcf017b45575887'); + '651e40dfcf017b45575887');
@ -44,7 +44,7 @@ describe('Scrypt', function() {
// let pass = Buffer.from('pleaseletmein'); // let pass = Buffer.from('pleaseletmein');
// let salt = Buffer.from('SodiumChloride'); // let salt = Buffer.from('SodiumChloride');
// let result = scrypt.derive(pass, salt, 1048576, 8, 1, 64); // let result = scrypt.derive(pass, salt, 1048576, 8, 1, 64);
// assert.equal(result.toString('hex'), '' // assert.strictEqual(result.toString('hex'), ''
// + '2101cb9b6a511aaeaddbbe09cf70f881ec568d574a2ffd4dabe5' // + '2101cb9b6a511aaeaddbbe09cf70f881ec568d574a2ffd4dabe5'
// + 'ee9820adaa478e56fd8f4ba5d09ffa1c6d927c40f4c337304049' // + 'ee9820adaa478e56fd8f4ba5d09ffa1c6d927c40f4c337304049'
// + 'e8a952fbcbf45c6fa77a41a4'); // + 'e8a952fbcbf45c6fa77a41a4');
@ -54,7 +54,7 @@ describe('Scrypt', function() {
const pass = Buffer.from(''); const pass = Buffer.from('');
const salt = Buffer.from(''); const salt = Buffer.from('');
const result = await scrypt.deriveAsync(pass, salt, 16, 1, 1, 64); const result = await scrypt.deriveAsync(pass, salt, 16, 1, 1, 64);
assert.equal(result.toString('hex'), '' assert.strictEqual(result.toString('hex'), ''
+ '77d6576238657b203b19ca42c18a0497f16b4844e3074ae8dfdffa3f' + '77d6576238657b203b19ca42c18a0497f16b4844e3074ae8dfdffa3f'
+ 'ede21442fcd0069ded0948f8326a753a0fc81f17e8d3e0fb2e0d3628' + 'ede21442fcd0069ded0948f8326a753a0fc81f17e8d3e0fb2e0d3628'
+ 'cf35e20c38d18906'); + 'cf35e20c38d18906');
@ -64,7 +64,7 @@ describe('Scrypt', function() {
const pass = Buffer.from('password'); const pass = Buffer.from('password');
const salt = Buffer.from('NaCl'); const salt = Buffer.from('NaCl');
const result = await scrypt.deriveAsync(pass, salt, 1024, 8, 16, 64); const result = await scrypt.deriveAsync(pass, salt, 1024, 8, 16, 64);
assert.equal(result.toString('hex'), '' assert.strictEqual(result.toString('hex'), ''
+ 'fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e773' + 'fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e773'
+ '76634b3731622eaf30d92e22a3886ff109279d9830dac727afb9' + '76634b3731622eaf30d92e22a3886ff109279d9830dac727afb9'
+ '4a83ee6d8360cbdfa2cc0640'); + '4a83ee6d8360cbdfa2cc0640');
@ -74,7 +74,7 @@ describe('Scrypt', function() {
const pass = Buffer.from('pleaseletmein'); const pass = Buffer.from('pleaseletmein');
const salt = Buffer.from('SodiumChloride'); const salt = Buffer.from('SodiumChloride');
const result = await scrypt.deriveAsync(pass, salt, 16384, 8, 1, 64); const result = await scrypt.deriveAsync(pass, salt, 16384, 8, 1, 64);
assert.equal(result.toString('hex'), '' assert.strictEqual(result.toString('hex'), ''
+ '7023bdcb3afd7348461c06cd81fd38ebfda8fbba904f8e3ea9b54' + '7023bdcb3afd7348461c06cd81fd38ebfda8fbba904f8e3ea9b54'
+ '3f6545da1f2d5432955613f0fcf62d49705242a9af9e61e85dc0d' + '3f6545da1f2d5432955613f0fcf62d49705242a9af9e61e85dc0d'
+ '651e40dfcf017b45575887'); + '651e40dfcf017b45575887');
@ -85,7 +85,7 @@ describe('Scrypt', function() {
// let pass = Buffer.from('pleaseletmein'); // let pass = Buffer.from('pleaseletmein');
// let salt = Buffer.from('SodiumChloride'); // let salt = Buffer.from('SodiumChloride');
// let result = await scrypt.deriveAsync(pass, salt, 1048576, 8, 1, 64); // let result = await scrypt.deriveAsync(pass, salt, 1048576, 8, 1, 64);
// assert.equal(result.toString('hex'), '' // assert.strictEqual(result.toString('hex'), ''
// + '2101cb9b6a511aaeaddbbe09cf70f881ec568d574a2ffd4dabe5' // + '2101cb9b6a511aaeaddbbe09cf70f881ec568d574a2ffd4dabe5'
// + 'ee9820adaa478e56fd8f4ba5d09ffa1c6d927c40f4c337304049' // + 'ee9820adaa478e56fd8f4ba5d09ffa1c6d927c40f4c337304049'
// + 'e8a952fbcbf45c6fa77a41a4'); // + 'e8a952fbcbf45c6fa77a41a4');

View File

@ -11,13 +11,13 @@ describe('SipHash', function() {
it('should perform siphash with no data', () => { it('should perform siphash with no data', () => {
const data = Buffer.alloc(0); const data = Buffer.alloc(0);
const key = Buffer.from('000102030405060708090a0b0c0d0e0f', 'hex'); const key = Buffer.from('000102030405060708090a0b0c0d0e0f', 'hex');
assert.deepEqual(siphash256(data, key), [1919933255, -586281423]); assert.deepStrictEqual(siphash256(data, key), [1919933255, -586281423]);
}); });
it('should perform siphash with data', () => { it('should perform siphash with data', () => {
const data = Buffer.from('0001020304050607', 'hex'); const data = Buffer.from('0001020304050607', 'hex');
const key = Buffer.from('000102030405060708090a0b0c0d0e0f', 'hex'); const key = Buffer.from('000102030405060708090a0b0c0d0e0f', 'hex');
assert.deepEqual(siphash256(data, key), [-1812597383, -1701632926]); assert.deepStrictEqual(siphash256(data, key), [-1812597383, -1701632926]);
}); });
it('should perform siphash with uint256', () => { it('should perform siphash with uint256', () => {
@ -25,6 +25,6 @@ describe('SipHash', function() {
'000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f', '000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f',
'hex'); 'hex');
const key = Buffer.from('000102030405060708090a0b0c0d0e0f', 'hex'); const key = Buffer.from('000102030405060708090a0b0c0d0e0f', 'hex');
assert.deepEqual(siphash256(data, key), [1898402095, 1928494286]); assert.deepStrictEqual(siphash256(data, key), [1898402095, 1928494286]);
}); });
}); });

View File

@ -37,7 +37,7 @@ const MAX_SAFE_ADDITION = 0xfffffffffffff;
function clearCache(tx, noCache) { function clearCache(tx, noCache) {
if (!noCache) { if (!noCache) {
assert.equal(tx.hash('hex'), tx.clone().hash('hex')); assert.strictEqual(tx.hash('hex'), tx.clone().hash('hex'));
return; return;
} }
tx.refresh(); tx.refresh();
@ -224,27 +224,27 @@ describe('TX', function() {
const {tx} = tx5; const {tx} = tx5;
clearCache(tx, noCache); clearCache(tx, noCache);
assert.equal(tx.inputs.length, 5); assert.strictEqual(tx.inputs.length, 5);
assert.equal(tx.outputs.length, 1980); assert.strictEqual(tx.outputs.length, 1980);
assert(tx.hasWitness()); assert(tx.hasWitness());
assert.notEqual(tx.hash('hex'), tx.witnessHash('hex')); assert.notStrictEqual(tx.hash('hex'), tx.witnessHash('hex'));
assert.equal(tx.witnessHash('hex'), assert.strictEqual(tx.witnessHash('hex'),
'088c919cd8408005f255c411f786928385688a9e8fdb2db4c9bc3578ce8c94cf'); '088c919cd8408005f255c411f786928385688a9e8fdb2db4c9bc3578ce8c94cf');
assert.equal(tx.getSize(), 62138); assert.strictEqual(tx.getSize(), 62138);
assert.equal(tx.getVirtualSize(), 61813); assert.strictEqual(tx.getVirtualSize(), 61813);
assert.equal(tx.getWeight(), 247250); assert.strictEqual(tx.getWeight(), 247250);
const raw1 = tx.toRaw(); const raw1 = tx.toRaw();
clearCache(tx, true); clearCache(tx, true);
const raw2 = tx.toRaw(); const raw2 = tx.toRaw();
assert.deepEqual(raw1, raw2); assert.deepStrictEqual(raw1, raw2);
const tx2 = TX.fromRaw(raw2); const tx2 = TX.fromRaw(raw2);
clearCache(tx2, noCache); clearCache(tx2, noCache);
assert.equal(tx.hash('hex'), tx2.hash('hex')); assert.strictEqual(tx.hash('hex'), tx2.hash('hex'));
assert.equal(tx.witnessHash('hex'), tx2.witnessHash('hex')); assert.strictEqual(tx.witnessHash('hex'), tx2.witnessHash('hex'));
}); });
it(`should verify the coolest tx ever sent ${suffix}`, () => { it(`should verify the coolest tx ever sent ${suffix}`, () => {
@ -331,7 +331,7 @@ describe('TX', function() {
it(`should get sighash of ${hash} (${hex}) ${suffix}`, () => { it(`should get sighash of ${hash} (${hex}) ${suffix}`, () => {
const subscript = script.getSubscript(0).removeSeparators(); const subscript = script.getSubscript(0).removeSeparators();
const hash = tx.signatureHash(index, subscript, 0, type, 0); const hash = tx.signatureHash(index, subscript, 0, type, 0);
assert.equal(hash.toString('hex'), expected); assert.strictEqual(hash.toString('hex'), expected);
}); });
} }
} }
@ -628,8 +628,8 @@ describe('TX', function() {
const ctx = sigopContext(input, witness, output); const ctx = sigopContext(input, witness, output);
assert.equal(ctx.spend.getSigopsCost(ctx.view, flags), 0); assert.strictEqual(ctx.spend.getSigopsCost(ctx.view, flags), 0);
assert.equal(ctx.fund.getSigopsCost(ctx.view, flags), assert.strictEqual(ctx.fund.getSigopsCost(ctx.view, flags),
consensus.MAX_MULTISIG_PUBKEYS * consensus.WITNESS_SCALE_FACTOR); consensus.MAX_MULTISIG_PUBKEYS * consensus.WITNESS_SCALE_FACTOR);
}); });
@ -651,7 +651,7 @@ describe('TX', function() {
const ctx = sigopContext(input, witness, output); const ctx = sigopContext(input, witness, output);
assert.equal(ctx.spend.getSigopsCost(ctx.view, flags), assert.strictEqual(ctx.spend.getSigopsCost(ctx.view, flags),
2 * consensus.WITNESS_SCALE_FACTOR); 2 * consensus.WITNESS_SCALE_FACTOR);
}); });
@ -670,8 +670,8 @@ describe('TX', function() {
const output = Script.fromProgram(0, key.getKeyHash()); const output = Script.fromProgram(0, key.getKeyHash());
const ctx = sigopContext(input, witness, output); const ctx = sigopContext(input, witness, output);
assert.equal(ctx.spend.getSigopsCost(ctx.view, flags), 1); assert.strictEqual(ctx.spend.getSigopsCost(ctx.view, flags), 1);
assert.equal( assert.strictEqual(
ctx.spend.getSigopsCost(ctx.view, flags & ~Script.flags.VERIFY_WITNESS), ctx.spend.getSigopsCost(ctx.view, flags & ~Script.flags.VERIFY_WITNESS),
0); 0);
} }
@ -680,7 +680,7 @@ describe('TX', function() {
const output = Script.fromProgram(1, key.getKeyHash()); const output = Script.fromProgram(1, key.getKeyHash());
const ctx = sigopContext(input, witness, output); const ctx = sigopContext(input, witness, output);
assert.equal(ctx.spend.getSigopsCost(ctx.view, flags), 0); assert.strictEqual(ctx.spend.getSigopsCost(ctx.view, flags), 0);
} }
{ {
@ -691,7 +691,7 @@ describe('TX', function() {
ctx.spend.inputs[0].prevout.index = 0xffffffff; ctx.spend.inputs[0].prevout.index = 0xffffffff;
ctx.spend.refresh(); ctx.spend.refresh();
assert.equal(ctx.spend.getSigopsCost(ctx.view, flags), 0); assert.strictEqual(ctx.spend.getSigopsCost(ctx.view, flags), 0);
} }
}); });
@ -713,7 +713,7 @@ describe('TX', function() {
const ctx = sigopContext(input, witness, output); const ctx = sigopContext(input, witness, output);
assert.equal(ctx.spend.getSigopsCost(ctx.view, flags), 1); assert.strictEqual(ctx.spend.getSigopsCost(ctx.view, flags), 1);
}); });
it('should count sigops for p2wsh', () => { it('should count sigops for p2wsh', () => {
@ -734,8 +734,8 @@ describe('TX', function() {
const ctx = sigopContext(input, witness, output); const ctx = sigopContext(input, witness, output);
assert.equal(ctx.spend.getSigopsCost(ctx.view, flags), 2); assert.strictEqual(ctx.spend.getSigopsCost(ctx.view, flags), 2);
assert.equal( assert.strictEqual(
ctx.spend.getSigopsCost(ctx.view, flags & ~Script.flags.VERIFY_WITNESS), ctx.spend.getSigopsCost(ctx.view, flags & ~Script.flags.VERIFY_WITNESS),
0); 0);
}); });
@ -761,6 +761,6 @@ describe('TX', function() {
const ctx = sigopContext(input, witness, output); const ctx = sigopContext(input, witness, output);
assert.equal(ctx.spend.getSigopsCost(ctx.view, flags), 2); assert.strictEqual(ctx.spend.getSigopsCost(ctx.view, flags), 2);
}); });
}); });

View File

@ -1,7 +1,7 @@
'use strict'; 'use strict';
const assert = require('assert'); const assert = require('assert');
const fs = require('fs'); const fs = require('../../lib/utils/fs');
const TX = require('../../lib/primitives/tx'); const TX = require('../../lib/primitives/tx');
const Output = require('../../lib/primitives/output'); const Output = require('../../lib/primitives/output');
const CoinView = require('../../lib/coins/coinview'); const CoinView = require('../../lib/coins/coinview');

View File

@ -38,13 +38,13 @@ describe('Utils', function() {
const buf = Buffer.from('000000deadbeef', 'hex'); const buf = Buffer.from('000000deadbeef', 'hex');
const str = base58.encode(buf); const str = base58.encode(buf);
assert.equal(str, '1116h8cQN'); assert.strictEqual(str, '1116h8cQN');
assert.deepEqual(base58.decode(str), buf); assert.deepStrictEqual(base58.decode(str), buf);
for (const [hex, b58] of base58Tests) { for (const [hex, b58] of base58Tests) {
const data = Buffer.from(hex, 'hex'); const data = Buffer.from(hex, 'hex');
assert.equal(base58.encode(data), b58); assert.strictEqual(base58.encode(data), b58);
assert.deepEqual(base58.decode(b58), data); assert.deepStrictEqual(base58.decode(b58), data);
} }
}); });
@ -61,11 +61,11 @@ describe('Utils', function() {
it('should convert satoshi to btc', () => { it('should convert satoshi to btc', () => {
let btc = Amount.btc(5460); let btc = Amount.btc(5460);
assert.equal(btc, '0.0000546'); assert.strictEqual(btc, '0.0000546');
btc = Amount.btc(54678 * 1000000); btc = Amount.btc(54678 * 1000000);
assert.equal(btc, '546.78'); assert.strictEqual(btc, '546.78');
btc = Amount.btc(5460 * 10000000); btc = Amount.btc(5460 * 10000000);
assert.equal(btc, '546.0'); assert.strictEqual(btc, '546.0');
}); });
it('should convert btc to satoshi', () => { it('should convert btc to satoshi', () => {
@ -122,63 +122,63 @@ describe('Utils', function() {
let b = Buffer.allocUnsafe(1); let b = Buffer.allocUnsafe(1);
b.fill(0x00); b.fill(0x00);
encoding.writeVarint2(b, 0, 0); encoding.writeVarint2(b, 0, 0);
assert.equal(encoding.readVarint2(b, 0).value, 0); assert.strictEqual(encoding.readVarint2(b, 0).value, 0);
assert.deepEqual(b, [0]); assert.deepEqual(b, [0]);
b = Buffer.allocUnsafe(1); b = Buffer.allocUnsafe(1);
b.fill(0x00); b.fill(0x00);
encoding.writeVarint2(b, 1, 0); encoding.writeVarint2(b, 1, 0);
assert.equal(encoding.readVarint2(b, 0).value, 1); assert.strictEqual(encoding.readVarint2(b, 0).value, 1);
assert.deepEqual(b, [1]); assert.deepEqual(b, [1]);
b = Buffer.allocUnsafe(1); b = Buffer.allocUnsafe(1);
b.fill(0x00); b.fill(0x00);
encoding.writeVarint2(b, 127, 0); encoding.writeVarint2(b, 127, 0);
assert.equal(encoding.readVarint2(b, 0).value, 127); assert.strictEqual(encoding.readVarint2(b, 0).value, 127);
assert.deepEqual(b, [0x7f]); assert.deepEqual(b, [0x7f]);
b = Buffer.allocUnsafe(2); b = Buffer.allocUnsafe(2);
b.fill(0x00); b.fill(0x00);
encoding.writeVarint2(b, 128, 0); encoding.writeVarint2(b, 128, 0);
assert.equal(encoding.readVarint2(b, 0).value, 128); assert.strictEqual(encoding.readVarint2(b, 0).value, 128);
assert.deepEqual(b, [0x80, 0x00]); assert.deepEqual(b, [0x80, 0x00]);
b = Buffer.allocUnsafe(2); b = Buffer.allocUnsafe(2);
b.fill(0x00); b.fill(0x00);
encoding.writeVarint2(b, 255, 0); encoding.writeVarint2(b, 255, 0);
assert.equal(encoding.readVarint2(b, 0).value, 255); assert.strictEqual(encoding.readVarint2(b, 0).value, 255);
assert.deepEqual(b, [0x80, 0x7f]); assert.deepEqual(b, [0x80, 0x7f]);
b = Buffer.allocUnsafe(2); b = Buffer.allocUnsafe(2);
b.fill(0x00); b.fill(0x00);
encoding.writeVarint2(b, 16383, 0); encoding.writeVarint2(b, 16383, 0);
assert.equal(encoding.readVarint2(b, 0).value, 16383); assert.strictEqual(encoding.readVarint2(b, 0).value, 16383);
assert.deepEqual(b, [0xfe, 0x7f]); assert.deepEqual(b, [0xfe, 0x7f]);
b = Buffer.allocUnsafe(2); b = Buffer.allocUnsafe(2);
b.fill(0x00); b.fill(0x00);
encoding.writeVarint2(b, 16384, 0); encoding.writeVarint2(b, 16384, 0);
assert.equal(encoding.readVarint2(b, 0).value, 16384); assert.strictEqual(encoding.readVarint2(b, 0).value, 16384);
assert.deepEqual(b, [0xff, 0x00]); assert.deepEqual(b, [0xff, 0x00]);
b = Buffer.allocUnsafe(3); b = Buffer.allocUnsafe(3);
b.fill(0x00); b.fill(0x00);
encoding.writeVarint2(b, 16511, 0); encoding.writeVarint2(b, 16511, 0);
assert.equal(encoding.readVarint2(b, 0).value, 16511); assert.strictEqual(encoding.readVarint2(b, 0).value, 16511);
// assert.deepEqual(b, [0x80, 0xff, 0x7f]); // assert.deepEqual(b, [0x80, 0xff, 0x7f]);
assert.deepEqual(b, [0xff, 0x7f, 0x00]); assert.deepEqual(b, [0xff, 0x7f, 0x00]);
b = Buffer.allocUnsafe(3); b = Buffer.allocUnsafe(3);
b.fill(0x00); b.fill(0x00);
encoding.writeVarint2(b, 65535, 0); encoding.writeVarint2(b, 65535, 0);
assert.equal(encoding.readVarint2(b, 0).value, 65535); assert.strictEqual(encoding.readVarint2(b, 0).value, 65535);
// assert.deepEqual(b, [0x82, 0xfd, 0x7f]); // assert.deepEqual(b, [0x82, 0xfd, 0x7f]);
assert.deepEqual(b, [0x82, 0xfe, 0x7f]); assert.deepEqual(b, [0x82, 0xfe, 0x7f]);
b = Buffer.allocUnsafe(5); b = Buffer.allocUnsafe(5);
b.fill(0x00); b.fill(0x00);
encoding.writeVarint2(b, Math.pow(2, 32), 0); encoding.writeVarint2(b, Math.pow(2, 32), 0);
assert.equal(encoding.readVarint2(b, 0).value, Math.pow(2, 32)); assert.strictEqual(encoding.readVarint2(b, 0).value, Math.pow(2, 32));
assert.deepEqual(b, [0x8e, 0xfe, 0xfe, 0xff, 0x00]); assert.deepEqual(b, [0x8e, 0xfe, 0xfe, 0xff, 0x00]);
}); });
@ -214,11 +214,11 @@ describe('Utils', function() {
const buf2 = Buffer.allocUnsafe(8); const buf2 = Buffer.allocUnsafe(8);
encoding.writeU64BN(buf1, num, 0); encoding.writeU64BN(buf1, num, 0);
encoding.writeU64(buf2, num.toNumber(), 0); encoding.writeU64(buf2, num.toNumber(), 0);
assert.deepEqual(buf1, buf2); assert.deepStrictEqual(buf1, buf2);
const n1 = encoding.readU64BN(buf1, 0); const n1 = encoding.readU64BN(buf1, 0);
const n2 = encoding.readU64(buf2, 0); const n2 = encoding.readU64(buf2, 0);
assert.equal(n1.toNumber(), n2); assert.strictEqual(n1.toNumber(), n2);
}); });
} }
@ -231,11 +231,11 @@ describe('Utils', function() {
const buf2 = Buffer.allocUnsafe(8); const buf2 = Buffer.allocUnsafe(8);
encoding.writeI64BN(buf1, num, 0); encoding.writeI64BN(buf1, num, 0);
encoding.writeI64(buf2, num.toNumber(), 0); encoding.writeI64(buf2, num.toNumber(), 0);
assert.deepEqual(buf1, buf2); assert.deepStrictEqual(buf1, buf2);
const n1 = encoding.readI64BN(buf1, 0); const n1 = encoding.readI64BN(buf1, 0);
const n2 = encoding.readI64(buf2, 0); const n2 = encoding.readI64(buf2, 0);
assert.equal(n1.toNumber(), n2); assert.strictEqual(n1.toNumber(), n2);
}); });
it(`should write+read a ${bits} bit ${sign} int as unsigned`, () => { it(`should write+read a ${bits} bit ${sign} int as unsigned`, () => {
@ -243,14 +243,14 @@ describe('Utils', function() {
const buf2 = Buffer.allocUnsafe(8); const buf2 = Buffer.allocUnsafe(8);
encoding.writeU64BN(buf1, num, 0); encoding.writeU64BN(buf1, num, 0);
encoding.writeU64(buf2, num.toNumber(), 0); encoding.writeU64(buf2, num.toNumber(), 0);
assert.deepEqual(buf1, buf2); assert.deepStrictEqual(buf1, buf2);
const n1 = encoding.readU64BN(buf1, 0); const n1 = encoding.readU64BN(buf1, 0);
if (num.isNeg()) { if (num.isNeg()) {
assert.throws(() => encoding.readU64(buf2, 0)); assert.throws(() => encoding.readU64(buf2, 0));
} else { } else {
const n2 = encoding.readU64(buf2, 0); const n2 = encoding.readU64(buf2, 0);
assert.equal(n1.toNumber(), n2); assert.strictEqual(n1.toNumber(), n2);
} }
}); });
} }

File diff suppressed because it is too large Load Diff