generated from khaosdoctor/template-node-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blockchain.spec.ts
41 lines (33 loc) · 1.27 KB
/
blockchain.spec.ts
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
import { Blockchain } from "../src/blockchain"
import { chance } from "./globals"
describe('Blockchain', () => {
const blockchain: Blockchain = new Blockchain(4)
const blocksQuantity: number = chance.integer({ min: 2, max: 10 })
const difficulty = chance.integer({ min: 1, max: 5 })
it('generate a valid instance', () => {
expect(blockchain).toBeDefined()
expect(blockchain).toBeInstanceOf(Blockchain)
})
describe('should be defined', () => {
it('createBlock', () => {
expect(blockchain.createBlock).toBeDefined()
expect(blockchain.createBlock).toBeInstanceOf(Function)
})
it('mineBlock', () => {
expect(blockchain.mineBlock).toBeDefined()
expect(blockchain.mineBlock).toBeInstanceOf(Function)
})
it('appendBlock', () => {
expect(blockchain.appendBlock).toBeDefined()
expect(blockchain.appendBlock).toBeInstanceOf(Function)
})
it('generate', () => {
expect(Blockchain.generate).toBeDefined()
expect(Blockchain.generate).toBeInstanceOf(Function)
})
})
it(`should create a blockchain with ${blocksQuantity} blocks`, () => {
const chain = Blockchain.generate({ difficulty, blocksQuantity })
expect(chain.length).toBe(blocksQuantity)
})
})