-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathchain_test.go
242 lines (223 loc) · 4.76 KB
/
chain_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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
package fio
import (
"encoding/json"
"fmt"
"github.com/fioprotocol/fio-go/eos"
"math"
"reflect"
"testing"
)
func TestAPI_GetCurrentBlock(t *testing.T) {
_, api, _, err := newApi()
if err != nil {
t.Error(err)
return
}
b := api.GetCurrentBlock()
if b == 0 {
t.Error("could not fetch latest block")
}
}
func TestAPI_AllABIs(t *testing.T) {
_, api, _, err := newApi()
if err != nil {
t.Error(err)
return
}
a, err := api.AllABIs()
if err != nil {
t.Error(err)
return
}
if len(a) == 0 {
t.Error("did not get abis")
return
}
if a[eos.AccountName("eosio")] == nil {
t.Error("did not get abi for eosio")
return
}
}
func TestAPI_GetTableRowsOrder(t *testing.T) {
_, api, _, err := newApi()
if err != nil {
t.Error(err)
return
}
if api.BaseURL != "http://dev:8889" {
// this will only work on a dev machine with known producer list
return
}
gtr, err := api.GetTableRows(eos.GetTableRowsRequest{
Code: "eosio",
Scope: "eosio",
Table: "producers",
LowerBound: "2",
UpperBound: fmt.Sprintf("%d", math.MaxUint32),
Limit: 1,
JSON: true,
})
if err != nil {
t.Error(err)
return
}
prodsAsc := make([]*Producer, 0)
err = json.Unmarshal(gtr.Rows, &prodsAsc)
if err != nil {
t.Error(err)
return
}
gtro, err := api.GetTableRowsOrder(GetTableRowsOrderRequest{
Code: "eosio",
Scope: "eosio",
Table: "producers",
LowerBound: "2",
UpperBound: fmt.Sprintf("%d", math.MaxUint32),
Limit: 1,
JSON: true,
Reverse: true,
})
if err != nil {
t.Error(err)
return
}
prods := make([]*Producer, 0)
err = json.Unmarshal(gtro.Rows, &prods)
if err != nil {
t.Error(err)
return
}
if prods == nil || len(prods) == 0 {
t.Error("did not get a query result")
return
}
if prods[0].FioAddress == prodsAsc[0].FioAddress {
t.Error("did not get expected result")
fmt.Println(prods[0].FioAddress, prodsAsc[0].FioAddress)
}
}
func TestAPI_GetRefBlockFor(t *testing.T) {
rbn, rbp, err := GetRefBlockFor(27309, "00006aadc588b4c4d14cb0a0f677b7741746ae0dd3bb68e42a21c36c6d94ecb4")
if err != nil {
t.Error(err)
return
}
if rbn != 27309 || rbp != 2695908561 {
t.Error("did not get expected prefix or id")
}
}
func TestAPI_GetBlockHeaderState(t *testing.T) {
_, api, _, err := newApi()
if err != nil {
t.Error(err)
return
}
info, err := api.GetInfo()
if err != nil {
t.Error(err)
return
}
bhs, err := api.GetBlockHeaderState(info.HeadBlockNum)
if err != nil {
t.Error(err)
return
}
if bhs == nil {
t.Error("got nil result")
return
}
if bhs.BlockNum != info.HeadBlockNum {
t.Error("did not get expected result")
}
ok, last := bhs.ProducerToLast(ProducerToLastImplied)
if !ok {
t.Error("last implied not found")
}
if len(last) < 3 {
t.Error("last implied was missing producers")
}
ok, last = bhs.ProducerToLast(ProducerToLastProduced)
if !ok {
t.Error("last produced not found")
}
if len(last) < 3 {
t.Error("last produced was missing producers")
}
}
func TestAPI_PushEndpointRaw(t *testing.T) {
account, api, opts, err := newApi()
if err != nil {
t.Error(err)
return
}
randAccount, _ := NewRandomAccount()
_, tx, err := api.SignTransaction(
NewTransaction(
[]*Action{
NewTransferTokensPubKey(account.Actor, randAccount.PubKey, Tokens(0.0001))},
opts),
opts.ChainID, CompressionNone,
)
_, err = api.PushEndpointRaw("/v1/chain/transfer_tokens_pub_key", tx)
if err != nil {
t.Error(err)
}
}
func TestAction_ToEos(t *testing.T) {
account, _, _, err := newApi()
if err != nil {
t.Error(err)
return
}
act := NewTransferTokensPubKey(account.Actor, account.PubKey, Tokens(0.0001)).ToEos()
if reflect.TypeOf(*act).String() != "eos.Action" {
t.Error("ToEos gave wrong type")
fmt.Println(reflect.TypeOf(*act).String())
}
}
func TestNewAction(t *testing.T) {
a := eos.AccountName("test")
actPerm := NewActionWithPermission(
"fio.token", "trnsfiopubky", a, "owner",
TransferTokensPubKey{
PayeePublicKey: "",
Amount: 1,
MaxFee: Tokens(GetMaxFee(FeeTransferTokensPubKey)),
Actor: a,
Tpid: CurrentTpid(),
},
)
if actPerm.Authorization[0].Permission != eos.PermissionName("owner") {
t.Error("NewActionWitherPermission did not set permission")
}
}
func TestAPI_GetRefBlock(t *testing.T) {
_, api, _, err := newApi()
if err != nil {
t.Error(err)
return
}
_, _, err = api.GetRefBlock()
if err != nil {
t.Error(err)
}
}
func TestAPI_GetTableByScopeMore(t *testing.T) {
_, api, _, err := newApi()
if err != nil {
t.Error(err)
return
}
res, err := api.GetTableByScopeMore(eos.GetTableByScopeRequest{
Code: "eosio",
Table: "producers",
Limit: 1,
})
if err != nil {
t.Error(err)
return
}
if res.More != true {
t.Error("expected more records")
}
}