-
Notifications
You must be signed in to change notification settings - Fork 4
/
transaction_test.go
98 lines (78 loc) · 1.83 KB
/
transaction_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
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
88
89
90
91
92
93
94
95
96
97
98
package blockchain_test
import (
"net/http"
"testing"
"github.com/qedus/blockchain"
)
func TestUnconfirmedTransactions(t *testing.T) {
bc := blockchain.New(http.DefaultClient)
ut := &blockchain.UnconfirmedTransactions{}
if err := bc.Request(ut); err != nil {
t.Fatal(err)
}
if len(ut.Transactions) == 0 {
t.Fatal("no transactions")
}
count := 0
for {
tx, err := ut.NextTransaction()
if err == blockchain.IterDone {
break
} else if err != nil {
t.Fatal(err)
}
if tx.Hash == "" {
t.Fatal("no transaction hash")
}
count++
}
t.Logf("%d unconfirmed transactions", count)
}
func TestTransactionFee(t *testing.T) {
bc := blockchain.New(http.DefaultClient)
b := &blockchain.Block{Index: 312373}
if err := bc.Request(b); err != nil {
t.Fatal(err)
}
feeSum := int64(0)
for _, tx := range b.Transactions {
feeSum = feeSum + tx.Fee()
}
if feeSum != b.Fee {
t.Fatalf("fees do not tally feeSum (%d) vs b.Fee (%d)",
feeSum, b.Fee)
}
}
func TestTransactionHash(t *testing.T) {
bc := blockchain.New(http.DefaultClient)
tx := &blockchain.Transaction{
Hash: "2355913fc1a3d71efbc228c69dc5d74340e07b9012377b4b9f6d5522116d0509"}
if err := bc.Request(tx); err != nil {
t.Fatal(err)
}
if len(tx.Inputs) != 14 {
t.Fatal("should be 14 inputs")
}
if len(tx.Outputs) != 1 {
t.Fatal("should be 1 output")
}
if tx.Index != 30187542 {
t.Fatalf("incorrect index for transaction (%d)", tx.Index)
}
}
func TestTransactionIndex(t *testing.T) {
bc := blockchain.New(http.DefaultClient)
tx := &blockchain.Transaction{Index: 30187542}
if err := bc.Request(tx); err != nil {
t.Fatal(err)
}
if len(tx.Inputs) != 14 {
t.Fatal("should be 14 inputs")
}
if len(tx.Outputs) != 1 {
t.Fatal("should be 1 output")
}
if tx.Index != 30187542 {
t.Fatalf("incorrect index for transaction (%d)", tx.Index)
}
}