v6 initial commit, maybe more to follow
This commit is contained in:
parent
7f91be86c0
commit
d6a32870bc
34 changed files with 16875 additions and 0 deletions
34
blockchain/block.test.js
Normal file
34
blockchain/block.test.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
const Block = require('./block');
|
||||
|
||||
describe('Block', () => {
|
||||
let data, lastBlock, block;
|
||||
|
||||
beforeEach(() => {
|
||||
data = 'bar';
|
||||
lastBlock = Block.genesis();
|
||||
block = Block.mineBlock(lastBlock, data);
|
||||
});
|
||||
|
||||
it('sets the `data` to match the input', () => {
|
||||
expect(block.data).toEqual(data);
|
||||
});
|
||||
|
||||
it('sets the `lastHash` to match the hash of the last block', () => {
|
||||
expect(block.lastHash).toEqual(lastBlock.hash);
|
||||
});
|
||||
|
||||
it('generates a hash that matches the difficulty', () => {
|
||||
expect(block.hash.substring(0, block.difficulty))
|
||||
.toEqual('0'.repeat(block.difficulty));
|
||||
});
|
||||
|
||||
it('lowers the difficulty for slowly mined blocks', () => {
|
||||
expect(Block.adjustDifficulty(block, block.timestamp+360000))
|
||||
.toEqual(block.difficulty-1);
|
||||
});
|
||||
|
||||
it('raises the difficulty for quickly mined blocks', () => {
|
||||
expect(Block.adjustDifficulty(block, block.timestamp+1))
|
||||
.toEqual(block.difficulty+1);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue