-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnanorpc_test.go
117 lines (103 loc) · 2.02 KB
/
nanorpc_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
105
106
107
108
109
110
111
112
113
114
115
116
117
package nanorpc
import (
"encoding/json"
"io/ioutil"
"os"
"testing"
)
const SERVER = "http://[::1]:7076"
var wallet string
func loadConfig() {
b, err := ioutil.ReadFile(os.Getenv("HOME") + "/RaiBlocks/config.json")
if err != nil {
panic(err)
}
m := make(map[string]interface{})
if err = json.Unmarshal(b, &m); err != nil {
panic(err)
}
wallet = m["wallet"].(string)
}
func TestMain(m *testing.M) {
loadConfig()
os.Exit(m.Run())
}
func TestAccounts(t *testing.T) {
v, err := Accounts(SERVER, wallet)
if err != nil {
t.Fatal(err)
}
t.Log("accounts:")
for _, acc := range v {
t.Log(acc)
}
}
func TestAccountInfo(t *testing.T) {
accounts, err := Accounts(SERVER, wallet)
if err != nil {
t.Fatal(err)
}
a, err := AccountInfo(SERVER, accounts[0])
if err != nil {
t.Fatal(err)
}
t.Logf("account info:")
t.Logf("%+v", a)
}
func TestBalance(t *testing.T) {
accounts, err := Accounts(SERVER, wallet)
if err != nil {
t.Fatal(err)
}
b, p, err := Balance(SERVER, accounts[0])
if err != nil {
t.Fatal(err)
}
t.Logf("account balance:")
t.Logf("%s (%s)", b, p)
}
func getBlockHash(t *testing.T) string {
accounts, err := Accounts(SERVER, wallet)
if err != nil {
t.Fatal(err)
}
a, err := AccountInfo(SERVER, accounts[0])
if err != nil {
t.Fatal(err)
}
return a.Frontier
}
func TestBlockAccount(t *testing.T) {
acc, err := BlockAccount(SERVER, getBlockHash(t))
if err != nil {
t.Fatal(err)
}
t.Logf("block account:")
t.Logf(acc)
}
func TestBlockInfo(t *testing.T) {
b, err := BlockInfo(SERVER, getBlockHash(t))
if err != nil {
t.Fatal(err)
}
t.Logf("block info:")
t.Logf("%+v", b)
}
func TestSend(t *testing.T) {
accounts, err := Accounts(SERVER, wallet)
if err != nil {
t.Fatal(err)
}
src, dst, amount := accounts[0], accounts[1], "1"
hash, err := Send(SERVER, wallet, src, dst, amount)
if err != nil {
t.Fatal(err)
}
block, err := BlockInfo(SERVER, hash)
if err != nil {
t.Fatal(err)
}
if block.Type != "send" || block.Destination != dst {
t.Fatal("invalid block/hash")
}
}