Skip to content

Commit

Permalink
Improve Test Coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
guerrerocarlos committed Feb 5, 2018
1 parent f2d2b7c commit 03a65a4
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions test.js
Expand Up @@ -2,27 +2,29 @@ const test = require('ava');
const BTCMiner = require('.');

const block = {
hash: '0000000000000000e067a478024addfecdc93628978aa52d91fabd4292982a50',
version: 2,
merkleroot: '871714dcbae6c8193a2bb9b2a69fe1c0440399f38d94b3a0f1b447275a29978a',
time: 1392872245,
bits: '19015f53',
previousblockhash: '000000000000000117c80378b8da0e33559b5997f2ad55e2f7d18ec1975b9717',
nextblockhash: '0000000000000000b0f08ec6a3d1e84994498ecf993a9981f57982cfdb66c443'
version: 536870912,
previousblockhash: '00000000000000000061abcd4f51d81ddba5498cff67fed44b287de0990b7266',
merkleroot: '871148c57dad60c0cde483233b099daa3e6492a91c13b337a5413a4c4f842978',
time: 1515252561,
bits: '180091c1'
};

const miner = new BTCMiner(block);

const nonce = 856192328;
const nonce = 45291998;

test('Get Block Difficulty Target', t => {
t.deepEqual(miner.getTarget().toString('hex'), '00000000000000015f5300000000000000000000000000000000000000000000');
t.deepEqual(miner.getTarget().toString('hex'), '00000000000000000091c1000000000000000000000000000000000000000000');
});

test('Get block hash', t => {
t.deepEqual(miner.getHash(nonce).toString('hex'), '0000000000000000e067a478024addfecdc93628978aa52d91fabd4292982a50');
t.deepEqual(miner.getHash(nonce).toString('hex'), '00000000000000000020cf2bdc6563fb25c424af588d5fb7223461e72715e4a9');
});

test('Verify that hash is less than target', t => {
t.true(miner.checkHash(Buffer.from('0000000000000000e067a478024addfecdc93628978aa52d91fabd4292982a50', 'hex')));
t.true(miner.checkHash(Buffer.from('00000000000000000020cf2bdc6563fb25c424af588d5fb7223461e72715e4a9', 'hex')));
});

test('Check nonce validity', t => {
t.true(miner.verifyNonce(block, nonce));
});

0 comments on commit 03a65a4

Please sign in to comment.