0xs34n / coin-cli

💸A minimal cryptocurrency CLI implementation in TypeScript & Immutable.js
https://coindemo.io
Apache License 2.0
188 stars 37 forks source link

Error when mine and difficulty changes #4

Closed ivanhuay closed 6 years ago

ivanhuay commented 6 years ago

Just creating a wallet and mining for 24 times the difficulty increase.

adding a new block executes the function shouldReplaceChain that fails validating with this.chain.size instead of the index of each previous block

Ecample Error

Failed to add block: Invalid Chain Error: Invalid Block Error: Hash 00052b8539c6ff8891f2239db140a4a136d40019bfc7fae7174aa2a52cecb0ec does not meet difficulty 4
ivanhuay commented 6 years ago

to reproduce it you can add this test to test/e2e.test.ts or mine 25 times with the same wallet

Test

tape(('change complexity test'), function (t: tape.Test) {
  const node1 = new Node();

  node1.newWallet('pw1');

  t.comment('node1 mines 25 to increase the difficulty');
  for(let i = 0; i < 25; i++){
    node1.mine();
  }
  t.equal(node1.getBalance(), 2500, 'should have balance 2500');
  t.end();
});