-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock_test.go
58 lines (50 loc) · 878 Bytes
/
block_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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"testing"
"crypto/sha256"
"github.com/google/go-cmp/cmp"
)
func createTx() *Tx {
acc, _ := NewAccount()
return NewTx(
[]TxI{
{
From: acc.Id,
Output: &TxOPath{
BlockHash: sha256.Sum256([]byte("Some hash")),
TxIdx: 1,
OutputIdx: 5,
},
},
},
[]TxO{
{
Value: 123,
To: sha256.Sum256([]byte("Someone else")),
},
},
map[AccountId]Signature{
AccountId(emptyHash): []byte{0xFF},
},
)
}
func createBlock() *Block {
return NewBlock()
}
func TestSerialization(t *testing.T) {
org_block := &Block{
Transactions: []*Tx{
createTx(),
},
PoW: &PoW{
Nonce: 123,
Hash: sha256.Sum256([]byte("Something")),
},
}
ser := org_block.Serialize()
des_block := BlockDeserialize(ser)
if !cmp.Equal(org_block, des_block) {
t.Log(cmp.Diff(org_block, des_block))
t.Fail()
}
}