-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock.test.js
More file actions
50 lines (47 loc) · 1.71 KB
/
Copy pathblock.test.js
File metadata and controls
50 lines (47 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const Block = require('./block');
const {GENESIS_DATA} = require("./config");
const cryptoHash = require("./crypto-hash");
describe("Block", () => {
const timestamp = "122"
const lastHash = "b"
const hash = "c"
const data = "d"
const block = new Block({
timestamp, lastHash, hash, data,
});
it("It has timestamp, lastHash, hash and data property.", () => {
expect(block.timestamp).toEqual(timestamp);
expect(block.lastHash).toEqual(lastHash);
expect(block.hash).toEqual(hash);
expect(block.data).toEqual(data);
});
describe("genesis()", () => {
const genesisBlock = Block.genesis();
it("Returns a block instance.", () => {
expect(genesisBlock).toBeInstanceOf(Block);
});
it("Returns the genesis data.", () => {
expect(genesisBlock).toEqual(GENESIS_DATA);
});
});
describe('mineBlock()', () => {
lastBlock = Block.genesis();
const data = "mined data"
const minedBlock = Block.mineBlock({lastBlock, data})
it("Returns a block instance.", () => {
expect(minedBlock).toBeInstanceOf(Block);
});
it("Sets the `lastHash` to the `hash` of lastBlock.", () => {
expect(minedBlock.lastHash).toEqual(lastBlock.hash);
});
it("Sets the `data`", () => {
expect(minedBlock.data).toEqual(data);
});
it("Sets the `timestamp`", () => {
expect(minedBlock.timestamp).toBeDefined();
});
it("Creates a SHA-256 `hash` based on the proper inputs", () => {
expect(minedBlock.hash).toEqual(cryptoHash(minedBlock.timestamp, lastBlock.hash, data));
});
});
});