-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblockchain_test.go
35 lines (28 loc) · 1.01 KB
/
blockchain_test.go
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
package main
import (
"testing"
)
// Testing adding and mining for new blocks
func TestAddNewBlock(t *testing.T){
addNewBlock("Genesis block")
addNewBlock("2nd block")
addNewBlock("3rd block")
if len(blockChain) != 3 {
t.Errorf("Only added 3 blocks to block chain got %v blocks", len(blockChain))
}
}
// Testing the block chain validation algorithm works as expected
func TestIsBlockChainValid(t *testing.T){
// Block chain has 3 exisiting blocks already from TestAddNewBlock
if !isBlockChainValid() {
t.Errorf("Block chain hasn't been tampered with, expected true upon validation but got false")
}
blockChain[1].Data = "I've messed with the blockchain"
if isBlockChainValid() {
t.Errorf("Block chain data has been tampered with, expected false upon validation but got true")
}
blockChain[0].Index = 10000
if isBlockChainValid() {
t.Errorf("Block chain order has been tampered with, expected false upon validation but got true")
}
}