forked from eoscanada/eos-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
abi_test.go
337 lines (305 loc) · 18.7 KB
/
abi_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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
package eos
import (
"encoding/hex"
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
var systemABIGenerated = "0014056e6f6e636500010576616c756506737472696e67087472616e7366657200040466726f6d0c6163636f756e745f6e616d6502746f0c6163636f756e745f6e616d65087175616e74697479056173736574046d656d6f06737472696e67056973737565000202746f0c6163636f756e745f6e616d65087175616e74697479056173736574076163636f756e7400020863757272656e63790675696e7436340762616c616e63650675696e7436340e63757272656e63795f737461747300020863757272656e63790675696e74363406737570706c790675696e7436340a64656c6567617465627700050466726f6d0c6163636f756e745f6e616d650872656365697665720c6163636f756e745f6e616d65097374616b655f6e6574056173736574097374616b655f6370750561737365740d7374616b655f73746f726167650561737365740c756e64656c6567617465627700050466726f6d0c6163636f756e745f6e616d650872656365697665720c6163636f756e745f6e616d650b756e7374616b655f6e65740561737365740b756e7374616b655f6370750561737365740d756e7374616b655f62797465730675696e74363406726566756e640001056f776e65720c6163636f756e745f6e616d651364656c6567617465645f62616e64776964746800060466726f6d0c6163636f756e745f6e616d6502746f0c6163636f756e745f6e616d650a6e65745f7765696768740561737365740a6370755f7765696768740561737365740d73746f726167655f7374616b650561737365740d73746f726167655f62797465730675696e7436340f746f74616c5f7265736f75726365730005056f776e65720c6163636f756e745f6e616d650a6e65745f7765696768740675696e7436340a6370755f7765696768740675696e7436340d73746f726167655f7374616b650675696e7436340d73746f726167655f62797465730675696e74363410656f73696f5f706172616d6574657273000f117461726765745f626c6f636b5f73697a650675696e7433320e6d61785f626c6f636b5f73697a650675696e7433321b7461726765745f626c6f636b5f616374735f7065725f73636f70650675696e743332186d61785f626c6f636b5f616374735f7065725f73636f70650675696e743332117461726765745f626c6f636b5f616374730675696e7433320e6d61785f626c6f636b5f616374730675696e743332106d61785f73746f726167655f73697a650675696e743634186d61785f7472616e73616374696f6e5f6c69666574696d650675696e743332196d61785f7472616e73616374696f6e5f657865635f74696d650675696e743332136d61785f617574686f726974795f64657074680675696e743136106d61785f696e6c696e655f64657074680675696e743136166d61785f696e6c696e655f616374696f6e5f73697a650675696e7433321e6d61785f67656e6572617465645f7472616e73616374696f6e5f73697a650675696e7433321d70657263656e745f6f665f6d61785f696e666c6174696f6e5f726174650675696e7433321573746f726167655f726573657276655f726174696f0675696e74333212656f73696f5f676c6f62616c5f737461746510656f73696f5f706172616d6574657273031c746f74616c5f73746f726167655f62797465735f72657365727665640675696e74363413746f74616c5f73746f726167655f7374616b650675696e743634117061796d656e745f7065725f626c6f636b0675696e7436340d70726f64756365725f696e666f0006056f776e65720c6163636f756e745f6e616d650b746f74616c5f766f7465730775696e7431323805707265667310656f73696f5f706172616d65746572730a7061636b65645f6b65790775696e74385b5d127065725f626c6f636b5f7061796d656e74730675696e7436340f6c6173745f636c61696d5f74696d650675696e7433320b72656770726f647563657200030870726f64756365720c6163636f756e745f6e616d650c70726f64756365725f6b657905627974657305707265667310656f73696f5f706172616d657465727309756e72656770726f6400010870726f64756365720c6163636f756e745f6e616d650872656770726f787900010570726f78790c6163636f756e745f6e616d650a756e72656770726f787900010570726f78790c6163636f756e745f6e616d650c766f746570726f6475636572000305766f7465720c6163636f756e745f6e616d650570726f78790c6163636f756e745f6e616d650970726f6475636572730e6163636f756e745f6e616d655b5d0a766f7465725f696e666f000b056f776e65720c6163636f756e745f6e616d650570726f78790c6163636f756e745f6e616d650b6c6173745f7570646174650675696e7433320869735f70726f78790675696e743332067374616b65640675696e74363409756e7374616b696e670675696e74363410756e7374616b655f7065725f7765656b0675696e7436340d70726f786965645f766f7465730775696e743132380970726f6475636572730e6163636f756e745f6e616d655b5d0f64656665727265645f7472785f69640675696e7433320c6c6173745f756e7374616b650675696e7433320c636c61696d726577617264730001056f776e65720c6163636f756e745f6e616d650c000000572d3ccdcd087472616e73666572000000000000a531760569737375650000003f2a1ba6a24a0a64656c6567617465627700c08fca86a9a8d2d40c756e64656c656761746562770000000000a4a997ba06726566756e640000ae423ad15b99ba0b72656770726f647563657200000048f456a6eed409756e72656770726f6400000000bed35b99ba0872656770726f7879000080eff456a6eed40a756e72656770726f7879007015d289deaa32dd0c766f746570726f64756365720080d3355c5de94c440c636c61696d7265776172647300000000000085269d056e6f6e6365000000"
func TestABISerialization(t *testing.T) {
systemABI := []byte(`
{
"types": [],
"structs": [{
"name": "nonce",
"base": "",
"fields": [
{"name":"value", "type":"string"}
]
},{
"name": "transfer",
"base": "",
"fields": [
{"name":"from", "type":"account_name"},
{"name":"to", "type":"account_name"},
{"name":"quantity", "type":"asset"},
{"name":"memo", "type":"string"}
]
},{
"name": "issue",
"base": "",
"fields": [
{"name":"to", "type":"account_name"},
{"name":"quantity", "type":"asset"}
]
},{
"name": "account",
"base": "",
"fields": [
{"name":"currency", "type":"uint64"},
{"name":"balance", "type":"uint64"}
]
},{
"name": "currency_stats",
"base": "",
"fields": [
{"name":"currency", "type":"uint64"},
{"name":"supply", "type":"uint64"}
]
},{
"name": "delegatebw",
"base": "",
"fields": [
{"name":"from", "type":"account_name"},
{"name":"receiver", "type":"account_name"},
{"name":"stake_net", "type":"asset"},
{"name":"stake_cpu", "type":"asset"},
{"name":"stake_storage", "type":"asset"}
]
},{
"name": "undelegatebw",
"base": "",
"fields": [
{"name":"from", "type":"account_name"},
{"name":"receiver", "type":"account_name"},
{"name":"unstake_net", "type":"asset"},
{"name":"unstake_cpu", "type":"asset"},
{"name":"unstake_bytes", "type":"uint64"}
]
},{
"name": "refund",
"base": "",
"fields": [
{"name":"owner", "type":"account_name"}
]
},{
"name": "delegated_bandwidth",
"base": "",
"fields": [
{"name":"from", "type":"account_name"},
{"name":"to", "type":"account_name"},
{"name":"net_weight", "type":"asset"},
{"name":"cpu_weight", "type":"asset"},
{"name":"storage_stake", "type":"asset"},
{"name":"storage_bytes", "type":"uint64"}
]
},{
"name": "total_resources",
"base": "",
"fields": [
{"name":"owner", "type":"account_name"},
{"name":"net_weight", "type":"uint64"},
{"name":"cpu_weight", "type":"uint64"},
{"name":"storage_stake", "type":"uint64"},
{"name":"storage_bytes", "type":"uint64"}
]
},{
"name": "eosio_parameters",
"base": "",
"fields": [
{"name":"target_block_size", "type":"uint32"},
{"name":"max_block_size", "type":"uint32"},
{"name":"target_block_acts_per_scope", "type":"uint32"},
{"name":"max_block_acts_per_scope", "type":"uint32"},
{"name":"target_block_acts", "type":"uint32"},
{"name":"max_block_acts", "type":"uint32"},
{"name":"max_storage_size", "type":"uint64"},
{"name":"max_transaction_lifetime", "type":"uint32"},
{"name":"max_transaction_exec_time", "type":"uint32"},
{"name":"max_authority_depth", "type":"uint16"},
{"name":"max_inline_depth", "type":"uint16"},
{"name":"max_inline_action_size", "type":"uint32"},
{"name":"max_generated_transaction_size", "type":"uint32"},
{"name":"percent_of_max_inflation_rate", "type":"uint32"},
{"name":"storage_reserve_ratio", "type":"uint32"}
]
},{
"name": "eosio_global_state",
"base": "eosio_parameters",
"fields": [
{"name":"total_storage_bytes_reserved", "type":"uint64"},
{"name":"total_storage_stake", "type":"uint64"},
{"name":"payment_per_block", "type":"uint64"}
]
},{
"name": "producer_info",
"base": "",
"fields": [
{"name":"owner", "type":"account_name"},
{"name":"total_votes", "type":"uint128"},
{"name":"prefs", "type":"eosio_parameters"},
{"name":"packed_key", "type":"uint8[]"},
{"name":"per_block_payments", "type":"uint64"},
{"name":"last_claim_time", "type":"uint32"}
]
},{
"name": "regproducer",
"base": "",
"fields": [
{"name":"producer", "type":"account_name"},
{"name":"producer_key", "type":"bytes"},
{"name":"prefs", "type":"eosio_parameters"}
]
},{
"name": "unregprod",
"base": "",
"fields": [
{"name":"producer", "type":"account_name"}
]
},{
"name": "regproxy",
"base": "",
"fields": [
{"name":"proxy", "type":"account_name"}
]
},{
"name": "unregproxy",
"base": "",
"fields": [
{"name":"proxy", "type":"account_name"}
]
},{
"name": "voteproducer",
"base": "",
"fields": [
{"name":"voter", "type":"account_name"},
{"name":"proxy", "type":"account_name"},
{"name":"producers", "type":"account_name[]"}
]
},{
"name": "voter_info",
"base": "",
"fields": [
{"name":"owner", "type":"account_name"},
{"name":"proxy", "type":"account_name"},
{"name":"last_update", "type":"uint32"},
{"name":"is_proxy", "type":"uint32"},
{"name":"staked", "type":"uint64"},
{"name":"unstaking", "type":"uint64"},
{"name":"unstake_per_week", "type":"uint64"},
{"name":"proxied_votes", "type":"uint128"},
{"name":"producers", "type":"account_name[]"},
{"name":"deferred_trx_id", "type":"uint32"},
{"name":"last_unstake", "type":"uint32"}
]
},{
"name": "claimrewards",
"base": "",
"fields": [
{"name":"owner", "type":"account_name"}
]
}
],
"actions": [{
"name": "transfer",
"type": "transfer"
},{
"name": "issue",
"type": "issue"
},{
"name": "delegatebw",
"type": "delegatebw"
},{
"name": "undelegatebw",
"type": "undelegatebw"
},{
"name": "refund",
"type": "refund"
},{
"name": "regproducer",
"type": "regproducer"
},{
"name": "unregprod",
"type": "unregprod"
},{
"name": "regproxy",
"type": "regproxy"
},{
"name": "unregproxy",
"type": "unregproxy"
},{
"name": "voteproducer",
"type": "voteproducer"
},{
"name": "claimrewards",
"type": "claimrewards"
},{
"name": "nonce",
"type": "nonce"
}
],
"tables": [
]
}
`)
var abiDef ABI
require.NoError(t, json.Unmarshal(systemABI, &abiDef))
_, err := json.MarshalIndent(abiDef, "", " ")
require.NoError(t, err)
//fmt.Println("Output", string(out))
bin, err := MarshalBinary(abiDef)
require.NoError(t, err)
assert.Equal(t, systemABIGenerated, hex.EncodeToString(bin))
//spew.Dump(bin)
}
/*
`setabi` action data:
account: 0000000000ea3055 eosio
abi:
00 types[]
14 structs[]
056e6f6e6365 "nonce"
00 base = ""
01 fields[]
0576616c7565 "value" (name)
06737472696e67 "string" (type)
087472616e73666572 "transfer"
00 base = ""
04 fields[]
0466726f6d "from"
0c6163636f756e745f6e616d65 "account_name"
02746f "to"
0c6163636f756e745f6e616d65 "account_name"
087175616e74697479 "quantity"
056173736574 "asset"
046d656d6f "memo"
06737472696e67 "string"
056973737565 "issue"
00 base = ""
02 fields[]
02746f
0c6163636f756e745f6e616d65087175616e74697479056173736574076163636f756e7400020863757272656e63790675696e7436340762616c616e63650675696e7436340e63757272656e63795f737461747300020863757272656e63790675696e74363406737570706c790675696e7436340a64656c6567617465627700050466726f6d0c6163636f756e745f6e616d650872656365697665720c6163636f756e745f6e616d65097374616b655f6e6574056173736574097374616b655f6370750561737365740d7374616b655f73746f726167650561737365740c756e64656c6567617465627700050466726f6d0c6163636f756e745f6e616d650872656365697665720c6163636f756e745f6e616d650b756e7374616b655f6e65740561737365740b756e7374616b655f6370750561737365740d756e7374616b655f62797465730675696e74363406726566756e640001056f776e65720c6163636f756e745f6e616d651364656c6567617465645f62616e64776964746800060466726f6d0c6163636f756e745f6e616d6502746f0c6163636f756e745f6e616d650a6e65745f7765696768740561737365740a6370755f7765696768740561737365740d73746f726167655f7374616b650561737365740d73746f726167655f62797465730675696e7436340f746f74616c5f7265736f75726365730005056f776e65720c6163636f756e745f6e616d650a6e65745f7765696768740675696e7436340a6370755f7765696768740675696e7436340d73746f726167655f7374616b650675696e7436340d73746f726167655f62797465730675696e74363410656f73696f5f706172616d6574657273000f117461726765745f626c6f636b5f73697a650675696e7433320e6d61785f626c6f636b5f73697a650675696e7433321b7461726765745f626c6f636b5f616374735f7065725f73636f70650675696e743332186d61785f626c6f636b5f616374735f7065725f73636f70650675696e743332117461726765745f626c6f636b5f616374730675696e7433320e6d61785f626c6f636b5f616374730675696e743332106d61785f73746f726167655f73697a650675696e743634186d61785f7472616e73616374696f6e5f6c69666574696d650675696e743332196d61785f7472616e73616374696f6e5f657865635f74696d650675696e743332136d61785f617574686f726974795f64657074680675696e743136106d61785f696e6c696e655f64657074680675696e743136166d61785f696e6c696e655f616374696f6e5f73697a650675696e7433321e6d61785f67656e6572617465645f7472616e73616374696f6e5f73697a650675696e7433321d70657263656e745f6f665f6d61785f696e666c6174696f6e5f726174650675696e7433321573746f726167655f726573657276655f726174696f0675696e74333212656f73696f5f676c6f62616c5f737461746510656f73696f5f706172616d6574657273031c746f74616c5f73746f726167655f62797465735f72657365727665640675696e74363413746f74616c5f73746f726167655f7374616b650675696e743634117061796d656e745f7065725f626c6f636b0675696e7436340d70726f64756365725f696e666f0006056f776e65720c6163636f756e745f6e616d650b746f74616c5f766f7465730775696e7431323805707265667310656f73696f5f706172616d65746572730a7061636b65645f6b65790775696e74385b5d127065725f626c6f636b5f7061796d656e74730675696e7436340f6c6173745f636c61696d5f74696d650675696e7433320b72656770726f647563657200030870726f64756365720c6163636f756e745f6e616d650c70726f64756365725f6b657905627974657305707265667310656f73696f5f706172616d657465727309756e72656770726f6400010870726f64756365720c6163636f756e745f6e616d650872656770726f787900010570726f78790c6163636f756e745f6e616d650a756e72656770726f787900010570726f78790c6163636f756e745f6e616d650c766f746570726f6475636572000305766f7465720c6163636f756e745f6e616d650570726f78790c6163636f756e745f6e616d650970726f6475636572730e6163636f756e745f6e616d655b5d0a766f7465725f696e666f000b056f776e65720c6163636f756e745f6e616d650570726f78790c6163636f756e745f6e616d650b6c6173745f7570646174650675696e7433320869735f70726f78790675696e743332067374616b65640675696e74363409756e7374616b696e670675696e74363410756e7374616b655f7065725f7765656b0675696e7436340d70726f786965645f766f7465730775696e743132380970726f6475636572730e6163636f756e745f6e616d655b5d0f64656665727265645f7472785f69640675696e7433320c6c6173745f756e7374616b650675696e7433320c636c61696d726577617264730001056f776e65720c6163636f756e745f6e616d650c
000000572d3ccdcd N(transfer)
087472616e73666572 "transfer"
0000000000a53176 N(issue)
056973737565
00003f2a1ba6a24a N(delegatebw)
0a64656c65676174656277
c08fca86a9a8d2d4 N(undelegatebw)
0c756e64656c65676174656277 "undelegatebw"
00000000a4a997ba N(refund)
06726566756e64
00ae423ad15b99ba N(regproducer)
0b72656770726f6475636572
000048f456a6eed4 N(unregprod)
09756e72656770726f64
000000bed35b99ba N(regproxy)
0872656770726f7879
0080eff456a6eed4 N(unregproxy)
0a756e72656770726f7879
7015d289deaa32dd N(voteproducer)
0c766f746570726f6475636572
80d3355c5de94c44 N(claimrewards)
0c636c61696d72657761726473
000000000085269d N(nonce)
056e6f6e6365
00 tables[]
*/
/* setcode by `cleos`:
0000000000ea3055
0000f58d050061736d0100000001ac022c60000060057e7e7e7e7f017f60037f7e7f0060057e7e7e7f7e017f60057e7e7e7f7f017f60067e7e7e7e7f7f017f60047f7e7f7f0060067e7e7e7f7f7e017f60067e7e7e7f7f7f017f60047f7f7f7f017f60027f7f0060037f7f7f017f60017f0060017e0060047e7e7e7e0060047e7e7e7e017f6000017f60047e7f7f7f0060027f7f017f6000017e60037e7e7e017f60057f7e7e7e7e0060057e7e7e7e7c017f60037f7e7c0060057e7e7e7c7f017f60037f7f7f0060037e7e7e0060027e7e017f60027e7f0060027f7e017f60027f7e0060037f7e7e0060047f7f7e7f0060057f7f7f7f7f0060027e7e0060047f7f7f7f0060057f7f7e7e7f017f60017f017f60017e017f60047e7e7e7f0060017e017e60067f7f7f7f7f7f017f60077f7f7f7f7f7f7f0060017c017c02de093603656e76085f5f6d756c746933001503656e76095f5f75646976746933001503656e760561626f7274000003656e7610616374696f6e5f646174615f73697a65001003656e760e63757272656e745f73656e646572001303656e760b64625f66696e645f693634000f03656e760a64625f6765745f693634000b03656e760d64625f6964783132385f656e64001403656e761664625f6964783132385f66696e645f7072696d617279000303656e761864625f6964783132385f66696e645f7365636f6e64617279000403656e761464625f6964783132385f6c6f776572626f756e64000403656e761264625f6964783132385f70726576696f7573001203656e760f64625f6964783132385f73746f7265000103656e761064625f69...20616c6c6f636174656400
SetCode by us:
0000000000ea3055
0000f58d050061736d0100000001ac022c60000060057e7e7e7e7f017f60037f7e7f0060057e7e7e7f7e017f60057e7e7e7f7f017f60067e7e7e7e7f7f017f60047f7e7f7f0060067e7e7e7f7f7e017f60067e7e7e7f7f7f017f60047f7f7f7f017f60027f7f0060037f7f7f017f60017f0060017e0060047e7e7e7e0060047e7e7e7e017f6000017f60047e7f7f7f0060027f7f017f6000017e60037e7e7e017f60057f7e7e7e7e0060057e7e7e7e7c017f60037f7e7c0060057e7e7e7c7f017f60037f7f7f0060037e7e7e0060027e7e017f60027e7f0060027f7e017f60027f7e0060037f7e7e0060047f7f7e7f0060057f7f7f7f7f0060027e7e0060047f7f7f7f0060057f7f7e7e7f017f60017f017f60017e017f60047e7e7e7f0060017e017e60067f7f7f7f7f7f017f60077f7f7f7f7f7f7f0060017c017c02de093603656e76085f5f6d756c746933001503656e76095f5f75646976746933001503656e760561626f7274000003656e7610616374696f6e5f646174615f73697a65001003656e760e63757272656e745f73656e646572001303656e760b64625f66696e645f693634000f03656e760a64625f6765745f693634000b03656e760d64625f6964783132385f656e64001403656e761664625f6964783132385f66696e645f7072696d617279000303656e761864625f6964783132385f66696e645f7365636f6e64617279000403656e761464625f6964783132385f6c6f776572626f756e64000403656e761264625f6964783132385f70726576696f7573001203656e760f64625f6964783132385f73746f7265000103656e761064625f6964783132385f757064617465000203656e761464625f6964783132385f7570706572626f756e64000403656e761664625f6964783235365f66696e645f7072696d61...c7920616c6c6f636174656400
*/