/
blockchain_abstracthelper.go
87 lines (80 loc) · 1.87 KB
/
blockchain_abstracthelper.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package jsonblock
import (
"github.com/KitchenMishap/pudding-shed/chainreadinterface"
"testing"
)
func TestJustFiveCoinbaseBlocks_helper(blockchain chainreadinterface.IBlockChain, t *testing.T) {
// Block handle
blockHandle := blockchain.GenesisBlock()
for i := 0; i < 5; i++ {
if blockHandle.IsInvalid() {
t.Error("block handle cannot be invalid")
}
// Block interface
block, err := blockchain.BlockInterface(blockHandle)
if err != nil {
t.Error("could not get BlockInterface from blockchain")
}
if block == nil {
t.Error("block cannot be nil")
}
if block.IsInvalid() {
t.Error("block cannot be invalid")
}
// One transaction
count, err := block.TransactionCount()
if count != 1 {
t.Error("block should have exactly one transaction")
}
transHandle, err := block.NthTransaction(0)
if err != nil {
t.Error(err)
}
trans, err := blockchain.TransInterface(transHandle)
if err != nil {
t.Error(err)
}
if trans == nil {
t.Error("transaction cannot be nil")
}
// 0 Txis
count, err = trans.TxiCount()
if count != 0 {
t.Error("coinbase transaction should have zero inputs")
}
// 1 Txo
count, err = trans.TxoCount()
if count != 1 {
t.Error("transaction should have one output")
}
txohandle, err := trans.NthTxo(0)
if err != nil {
t.Error(err)
}
if txohandle == nil {
t.Error("txohandle cannot be nil")
}
txo, err := blockchain.TxoInterface(txohandle)
if err != nil {
t.Error(err)
}
if txo == nil {
t.Error("txo cannot be nil")
}
sats, err := txo.Satoshis()
if err != nil {
t.Error(err)
}
if sats != int64(50*100_000_000) {
t.Error("satoshis should be 50 bitcoins")
}
// next block
blockHandle, err = blockchain.NextBlock(blockHandle)
if err != nil {
t.Error(err)
}
}
if !blockHandle.IsInvalid() {
t.Error("next block handle after last should be invalid")
}
}