test: use better asserts.
This commit is contained in:
parent
853ef18ad9
commit
8146fb28f0
@ -51,7 +51,7 @@ async function addBlock(block, flags) {
|
||||
try {
|
||||
entry = await chain.add(block, flags);
|
||||
} catch (e) {
|
||||
assert(e.type === 'VerifyError');
|
||||
assert.strictEqual(e.type, 'VerifyError');
|
||||
return e.reason;
|
||||
}
|
||||
|
||||
@ -149,7 +149,7 @@ describe('Chain', function() {
|
||||
assert(await chain.add(blk1));
|
||||
assert(await chain.add(blk2));
|
||||
|
||||
assert(chain.tip.hash === hash1);
|
||||
assert.strictEqual(chain.tip.hash, hash1);
|
||||
|
||||
tip1 = await chain.db.getEntry(hash1);
|
||||
tip2 = await chain.db.getEntry(hash2);
|
||||
@ -176,7 +176,7 @@ describe('Chain', function() {
|
||||
|
||||
const entry = await chain.db.getEntry(tip2.hash);
|
||||
assert(entry);
|
||||
assert(chain.height === entry.height);
|
||||
assert.strictEqual(chain.height, entry.height);
|
||||
|
||||
const block = await cpu.mineBlock(entry);
|
||||
assert(block);
|
||||
@ -189,7 +189,7 @@ describe('Chain', function() {
|
||||
assert(await chain.add(block));
|
||||
|
||||
assert(forked);
|
||||
assert(chain.tip.hash === block.hash('hex'));
|
||||
assert.strictEqual(chain.tip.hash, block.hash('hex'));
|
||||
assert(chain.tip.chainwork.cmp(tip1.chainwork) > 0);
|
||||
});
|
||||
|
||||
@ -217,7 +217,7 @@ describe('Chain', function() {
|
||||
const entry = await chain.db.getEntry(hash);
|
||||
|
||||
assert(entry);
|
||||
assert(chain.tip.hash === entry.hash);
|
||||
assert.strictEqual(chain.tip.hash, entry.hash);
|
||||
|
||||
const result = await entry.isMainChain();
|
||||
assert(result);
|
||||
|
||||
@ -72,7 +72,7 @@ describe('Coins', function() {
|
||||
|
||||
view.spendEntry(new Outpoint(hash, 0));
|
||||
|
||||
assert(view.get(hash) === coins);
|
||||
assert.strictEqual(view.get(hash), coins);
|
||||
|
||||
const entry = coins.get(0);
|
||||
assert(entry);
|
||||
|
||||
@ -141,7 +141,7 @@ describe('HTTP', function() {
|
||||
it('should generate new api key', async () => {
|
||||
const old = wallet.token.toString('hex');
|
||||
const token = await wallet.retoken(null);
|
||||
assert(token.length === 64);
|
||||
assert.strictEqual(token.length, 64);
|
||||
assert.notStrictEqual(token, old);
|
||||
});
|
||||
|
||||
|
||||
@ -115,7 +115,7 @@ describe('Node', function() {
|
||||
|
||||
await chain.add(block2);
|
||||
|
||||
assert(chain.tip.hash === block1.hash('hex'));
|
||||
assert.strictEqual(chain.tip.hash, block1.hash('hex'));
|
||||
|
||||
tip1 = await chain.db.getEntry(block1.hash('hex'));
|
||||
tip2 = await chain.db.getEntry(block2.hash('hex'));
|
||||
@ -149,7 +149,7 @@ describe('Node', function() {
|
||||
|
||||
const entry = await chain.db.getEntry(tip2.hash);
|
||||
assert(entry);
|
||||
assert(chain.height === entry.height);
|
||||
assert.strictEqual(chain.height, entry.height);
|
||||
|
||||
const block = await miner.mineBlock(entry);
|
||||
assert(block);
|
||||
@ -162,7 +162,7 @@ describe('Node', function() {
|
||||
await chain.add(block);
|
||||
|
||||
assert(forked);
|
||||
assert(chain.tip.hash === block.hash('hex'));
|
||||
assert.strictEqual(chain.tip.hash, block.hash('hex'));
|
||||
assert(chain.tip.chainwork.cmp(tip1.chainwork) > 0);
|
||||
});
|
||||
|
||||
@ -192,7 +192,7 @@ describe('Node', function() {
|
||||
|
||||
const entry = await chain.db.getEntry(block.hash('hex'));
|
||||
assert(entry);
|
||||
assert(chain.tip.hash === entry.hash);
|
||||
assert.strictEqual(chain.tip.hash, entry.hash);
|
||||
|
||||
const result = await entry.isMainChain();
|
||||
assert(result);
|
||||
@ -211,7 +211,7 @@ describe('Node', function() {
|
||||
|
||||
assert(err);
|
||||
assert.strictEqual(err.reason, 'bad-txns-inputs-missingorspent');
|
||||
assert(chain.tip === tip);
|
||||
assert.strictEqual(chain.tip, tip);
|
||||
});
|
||||
|
||||
it('should fail to mine block with coins on an alternate chain', async () => {
|
||||
@ -227,7 +227,7 @@ describe('Node', function() {
|
||||
|
||||
assert(err);
|
||||
assert.strictEqual(err.reason, 'bad-txns-inputs-missingorspent');
|
||||
assert(chain.tip === tip);
|
||||
assert.strictEqual(chain.tip, tip);
|
||||
});
|
||||
|
||||
it('should have correct chain value', () => {
|
||||
@ -300,7 +300,7 @@ describe('Node', function() {
|
||||
|
||||
const prev = await chain.tip.getPrevious();
|
||||
const state = await chain.getState(prev, deployments.csv);
|
||||
assert(state === 0);
|
||||
assert.strictEqual(state, 0);
|
||||
|
||||
for (let i = 0; i < 417; i++) {
|
||||
const block = await miner.mineBlock();
|
||||
@ -309,25 +309,25 @@ describe('Node', function() {
|
||||
case 144: {
|
||||
const prev = await chain.tip.getPrevious();
|
||||
const state = await chain.getState(prev, deployments.csv);
|
||||
assert(state === 1);
|
||||
assert.strictEqual(state, 1);
|
||||
break;
|
||||
}
|
||||
case 288: {
|
||||
const prev = await chain.tip.getPrevious();
|
||||
const state = await chain.getState(prev, deployments.csv);
|
||||
assert(state === 2);
|
||||
assert.strictEqual(state, 2);
|
||||
break;
|
||||
}
|
||||
case 432: {
|
||||
const prev = await chain.tip.getPrevious();
|
||||
const state = await chain.getState(prev, deployments.csv);
|
||||
assert(state === 3);
|
||||
assert.strictEqual(state, 3);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert(chain.height === 432);
|
||||
assert.strictEqual(chain.height, 432);
|
||||
assert(chain.state.hasCSV());
|
||||
|
||||
const cache = await chain.db.getStateCache();
|
||||
@ -471,10 +471,10 @@ describe('Node', function() {
|
||||
id: '1'
|
||||
}, {});
|
||||
|
||||
assert(typeof json.result.curtime === 'number');
|
||||
assert(typeof json.result.mintime === 'number');
|
||||
assert(typeof json.result.maxtime === 'number');
|
||||
assert(typeof json.result.expires === 'number');
|
||||
assert.strictEqual(typeof json.result.curtime, 'number');
|
||||
assert.strictEqual(typeof json.result.mintime, 'number');
|
||||
assert.strictEqual(typeof json.result.maxtime, 'number');
|
||||
assert.strictEqual(typeof json.result.expires, 'number');
|
||||
|
||||
assert.deepStrictEqual(json, {
|
||||
result: {
|
||||
@ -530,7 +530,7 @@ describe('Node', function() {
|
||||
}, {});
|
||||
|
||||
assert(!json.error);
|
||||
assert(json.result === null);
|
||||
assert.strictEqual(json.result, null);
|
||||
});
|
||||
|
||||
it('should submit a block', async () => {
|
||||
@ -543,7 +543,7 @@ describe('Node', function() {
|
||||
}, {});
|
||||
|
||||
assert(!json.error);
|
||||
assert(json.result === null);
|
||||
assert.strictEqual(json.result, null);
|
||||
assert.strictEqual(node.chain.tip.hash, block.hash('hex'));
|
||||
});
|
||||
|
||||
@ -668,7 +668,7 @@ describe('Node', function() {
|
||||
}, {});
|
||||
|
||||
assert(!json.error);
|
||||
assert(json.result === true);
|
||||
assert.strictEqual(json.result, true);
|
||||
});
|
||||
|
||||
it('should get a block template', async () => {
|
||||
|
||||
@ -488,7 +488,7 @@ describe('TX', function() {
|
||||
});
|
||||
|
||||
let raw = tx.toRaw();
|
||||
assert(encoding.readU64(raw, 47) === 0xdeadbeef);
|
||||
assert.strictEqual(encoding.readU64(raw, 47), 0xdeadbeef);
|
||||
raw[54] = 0x7f;
|
||||
|
||||
assert.throws(() => TX.fromRaw(raw));
|
||||
@ -497,7 +497,7 @@ describe('TX', function() {
|
||||
tx.refresh();
|
||||
|
||||
raw = tx.toRaw();
|
||||
assert(encoding.readU64(raw, 47) === 0x00);
|
||||
assert.strictEqual(encoding.readU64(raw, 47), 0x00);
|
||||
raw[54] = 0x80;
|
||||
assert.throws(() => TX.fromRaw(raw));
|
||||
});
|
||||
|
||||
@ -70,15 +70,15 @@ describe('Utils', function() {
|
||||
|
||||
it('should convert btc to satoshi', () => {
|
||||
let btc = Amount.value('0.0000546');
|
||||
assert(btc === 5460);
|
||||
assert.strictEqual(btc, 5460);
|
||||
btc = Amount.value('546.78');
|
||||
assert(btc === 54678 * 1000000);
|
||||
assert.strictEqual(btc, 54678 * 1000000);
|
||||
btc = Amount.value('546');
|
||||
assert(btc === 5460 * 10000000);
|
||||
assert.strictEqual(btc, 5460 * 10000000);
|
||||
btc = Amount.value('546.0');
|
||||
assert(btc === 5460 * 10000000);
|
||||
assert.strictEqual(btc, 5460 * 10000000);
|
||||
btc = Amount.value('546.0000');
|
||||
assert(btc === 5460 * 10000000);
|
||||
assert.strictEqual(btc, 5460 * 10000000);
|
||||
|
||||
assert.doesNotThrow(() => {
|
||||
Amount.value('546.00000000000000000');
|
||||
@ -257,7 +257,7 @@ describe('Utils', function() {
|
||||
|
||||
it('should validate integers 0 and 1 as booleans', () => {
|
||||
const validator = new Validator({shouldBeTrue: 1, shouldBeFalse: 0});
|
||||
assert(validator.bool('shouldBeTrue') === true);
|
||||
assert(validator.bool('shouldBeFalse') === false);
|
||||
assert.strictEqual(validator.bool('shouldBeTrue'), true);
|
||||
assert.strictEqual(validator.bool('shouldBeFalse'), false);
|
||||
});
|
||||
});
|
||||
|
||||
@ -698,7 +698,7 @@ describe('Wallet', function() {
|
||||
|
||||
assert(err);
|
||||
assert(balance);
|
||||
assert(balance.unconfirmed === 5460);
|
||||
assert.strictEqual(balance.unconfirmed, 5460);
|
||||
});
|
||||
|
||||
it('should sign multiple inputs using different keys', async () => {
|
||||
@ -846,7 +846,7 @@ describe('Wallet', function() {
|
||||
const account = await wallet.getAccount('foo');
|
||||
assert.strictEqual(account.name, 'foo');
|
||||
assert.strictEqual(account.accountIndex, 1);
|
||||
assert(wallet.account.accountIndex === 0);
|
||||
assert.strictEqual(wallet.account.accountIndex, 0);
|
||||
|
||||
assert(!account.receive.getAddress().equals(
|
||||
wallet.account.receive.getAddress()));
|
||||
@ -1226,7 +1226,7 @@ describe('Wallet', function() {
|
||||
const t2 = await wallet.createTX(options);
|
||||
await wallet.sign(t2);
|
||||
assert(t2.verify());
|
||||
assert(t2.inputs[0].prevout.hash === wtx.hash);
|
||||
assert.strictEqual(t2.inputs[0].prevout.hash, wtx.hash);
|
||||
|
||||
importedWallet = wallet;
|
||||
importedKey = key;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user