-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbigbang_testnet_test.go
104 lines (90 loc) · 2.14 KB
/
bigbang_testnet_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
99
100
101
102
103
104
package bbrpc
import (
"fmt"
"testing"
"time"
)
// 测试链上的出块间隔
func TestTestnetBockPeriod(t *testing.T) {
t.Skip("需要的话自行搭建节点测试")
client, err := NewClient(&ConnConfig{
Host: "127.0.0.1:9904",
DisableTLS: true,
})
tShouldNil(t, err, "failed to new rpc client!")
defer client.Shutdown()
var (
maxHeight int
)
{
maxHeight, err = client.Getforkheight(nil)
tShouldNil(t, err)
fmt.Println("forkHeight", maxHeight)
}
{ //listransaction
txs, err := client.Listtransaction(nil, nil)
tShouldNil(t, err)
fmt.Println("list tx...", toJSONIndent(txs))
}
var blocks []*BlockInfo
{ //recent n blocks
for i := maxHeight; i > maxHeight-100; i-- {
hash, err := client.Getblockhash(int(i), nil)
tShouldNil(t, err)
blk, err := client.Getblock(hash[0])
tShouldNil(t, err)
blocks = append(blocks, blk)
}
}
for i, block := range blocks {
t := time.Unix(int64(block.Time), 0)
var du time.Duration
if i > 0 {
lastTime := time.Unix(int64(blocks[i-1].Time), 0)
du = t.Sub(lastTime)
}
fmt.Println(block.Height, t, du)
}
}
func TestViewTestnet(t *testing.T) {
t.Skip("自行测试")
client, err := NewClient(&ConnConfig{
Host: "127.0.0.1:9904",
DisableTLS: true,
})
tShouldNil(t, err, "failed to new rpc client!")
defer client.Shutdown()
var (
maxHeight int
)
{
maxHeight, err = client.Getforkheight(nil)
tShouldNil(t, err)
fmt.Println("forkHeight", maxHeight)
}
{ //listransaction
txs, err := client.Listtransaction(nil, nil)
tShouldNil(t, err)
fmt.Println("list tx...", toJSONIndent(txs))
}
{ //recent 10 blocks
for i := maxHeight; i > maxHeight-10; i-- {
hash, err := client.Getblockhash(int(i), nil)
tShouldNil(t, err)
blk, err := client.Getblock(hash[0])
tShouldNil(t, err)
fmt.Println("----------------height", i)
fmt.Println("block", toJSONIndent(blk))
if len(blk.Tx) == 0 {
fmt.Println("::no tx this block")
} else {
fmt.Println("tx...")
for _, txid := range blk.Tx {
tx, err := client.Gettransaction(txid, pbool(false))
tShouldNil(t, err)
fmt.Println(toJSONIndent(tx))
}
}
}
}
}