-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaddress_test.go
82 lines (69 loc) · 1.77 KB
/
address_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
package blockchain_test
import (
"net/http"
"testing"
"github.com/qedus/blockchain"
)
const (
largeAddress = "1dice8EMZmqKvrGE4Qc9bUFf9PX3xaYDp"
largeAddressTxHashOne = "598af2a2f8eada73ed7262dfb6d6f99970096a4193fdd8043729d01b03423091"
largeAddressTxHashFiftyOne = "bc6a0683001e38a3c78e3493c5447ff4a21e26367836034aeb9b9910e3cd437e"
smallAddress = "1416ArzSr5HGzaTbfQHjkLE5RVBBGw3W13"
)
func TestRequestLargeAddress(t *testing.T) {
bc := blockchain.New(http.DefaultClient)
address := &blockchain.Address{Address: largeAddress,
TxSortDescending: false}
if err := bc.Request(address); err != nil {
t.Fatal(err)
}
if len(address.Transactions) != 50 {
t.Fatalf("tx count not 50")
}
tx, err := address.NextTransaction()
if err != nil {
t.Fatal(err)
}
if tx.Hash != largeAddressTxHashOne {
t.Fatalf("tx hash incorrect %s but should be %s",
tx.Hash, largeAddressTxHashOne)
}
for i := 0; i < 49; i++ {
tx, err = address.NextTransaction()
if err != nil {
t.Fatal(err)
}
}
// Check the address iterator goes to the server again.
tx, err = address.NextTransaction()
if err != nil {
t.Fatal(err)
}
if tx.Hash != largeAddressTxHashFiftyOne {
t.Fatalf("tx hash incorrect %s but should be %s",
tx.Hash, largeAddressTxHashFiftyOne)
}
if len(address.Transactions) != 50 {
t.Fatalf("tx count not 50")
}
}
func TestRequestSmallAddress(t *testing.T) {
bc := blockchain.New(http.DefaultClient)
address := &blockchain.Address{Address: smallAddress}
if err := bc.Request(address); err != nil {
t.Fatal(err)
}
count := 0
for {
_, err := address.NextTransaction()
if err == blockchain.IterDone {
break
} else if err != nil {
t.Fatal(err)
}
count++
}
if count != 6 {
t.Fatalf("expected 6 iterations but got %d", count)
}
}