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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
|
import * as chai from 'chai';
import 'mocha';
import ethUtil = require('ethereumjs-util');
var _ = require('lodash');
// import { assert } from '@0x/order-utils/src/assert';
import { chaiSetup } from './utils/chai_setup';
import { MethodAbi, DataItem } from 'ethereum-types';
import { BigNumber } from '@0x/utils';
import { assert } from '@0x/order-utils/src/assert';
//import * as AbiEncoder from './abi_encoder';
import * as AbiEncoder from './abi/abi_encoder';
import * as AbiSamples from './abi_samples';
AbiEncoder.DataTypeFactory.setImpl(new AbiEncoder.EvmDataTypeFactoryImpl());
chaiSetup.configure();
const expect = chai.expect;
describe.only('ABI Encoder', () => {
describe.only('ABI Tests at Method Level', () => {
it.skip('Crazy ABI', async () => {
const method = new AbiEncoder.Method(AbiSamples.crazyAbi);
console.log(method.getSignature());
const someStaticArray = [new BigNumber(127), new BigNumber(14), new BigNumber(54)];
const someStaticArrayWithDynamicMembers = [
'the little piping piper piped a piping pipper papper',
'the kid knows how to write poems, what can I say -- I guess theres a lot I could say to try to fill this line with a lot of text.',
];
const someDynamicArrayWithDynamicMembers = [
'0x38745637834987324827439287423897238947239847',
'0x7283472398237423984723984729847248927498748974284728947239487498749847874329423743492347329847239842374892374892374892347238947289478947489374289472894738942749823743298742389472389473289472389437249823749823742893472398',
'0x283473298473248923749238742398742398472894729843278942374982374892374892743982',
];
const some2DArray = [
[
'some string',
'some another string',
'there are just too many stringsup in',
'here',
'yall ghonna make me lose my mind',
],
[
'the little piping piper piped a piping pipper papper',
'the kid knows how to write poems, what can I say -- I guess theres a lot I could say to try to fill this line with a lot of text.',
],
[],
];
const someTuple = {
someUint32: new BigNumber(4037824789),
someStr: 'the kid knows how to write poems, what can I say -- I guess theres a lot I could say to try to fill this line with a lot of text.'
};
const someTupleWithDynamicTypes = {
someUint: new BigNumber(4024789),
someStr: 'akdhjasjkdhasjkldshdjahdkjsahdajksdhsajkdhsajkdhadjkashdjksadhajkdhsajkdhsadjk',
someBytes: '0x29384723894723843743289742389472398473289472348927489274894738427428947389facdea',
someAddress: '0xe41d2489571d322189246dafa5ebde1f4699f498',
};
const someTupleWithDynamicTypes2 = {
someUint: new BigNumber(9024789),
someStr: 'ksdhsajkdhsajkdhadjkashdjksadhajkdhsajkdhsadjkakdhjasjkdhasjkldshdjahdkjsahdaj',
someBytes: '0x29384723894398473289472348927489272384374328974238947274894738427428947389facde1',
someAddress: '0x746dafa5ebde1f4699f4981d3221892e41d24895',
};
const someTupleWithDynamicTypes3 = {
someUint: new BigNumber(1024789),
someStr: 'sdhsajkdhsajkdhadjkashdjakdhjasjkdhasjkldshdjahdkjsahdajkksadhajkdhsajkdhsadjk',
someBytes: '0x38947238437432829384729742389472398473289472348927489274894738427428947389facdef',
someAddress: '0x89571d322189e415ebde1f4699f498d24246dafa',
};
const someArrayOfTuplesWithDynamicTypes = [someTupleWithDynamicTypes2, someTupleWithDynamicTypes3];
const args = [someStaticArray, someStaticArrayWithDynamicMembers, someDynamicArrayWithDynamicMembers, some2DArray, someTuple, someTupleWithDynamicTypes, someArrayOfTuplesWithDynamicTypes];
const calldata = method.encode(args);
console.log(calldata);
console.log('*'.repeat(40));
console.log(JSON.stringify(args));
console.log(method.getSignature());
const expectedCalldata = '0x4b49031c000000000000000000000000000000000000000000000000000000000000007f000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000036000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000440000000000000000000000000000000000000000000000000000000000000088000000000000000000000000000000000000000000000000000000000000009800000000000000000000000000000000000000000000000000000000000000ae0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000034746865206c6974746c6520706970696e67207069706572207069706564206120706970696e6720706970706572207061707065720000000000000000000000000000000000000000000000000000000000000000000000000000000000000081746865206b6964206b6e6f777320686f7720746f20777269746520706f656d732c20776861742063616e204920736179202d2d2049206775657373207468657265732061206c6f74204920636f756c642073617920746f2074727920746f2066696c6c2074686973206c696e6520776974682061206c6f74206f6620746578742e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000163874563783498732482743928742389723894723984700000000000000000000000000000000000000000000000000000000000000000000000000000000006e72834723982374239847239847298472489274987489742847289472394874987498478743294237434923473298472398423748923748923748923472389472894789474893742894728947389427498237432987423894723894732894723894372498237498237428934723980000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000027283473298473248923749238742398742398472894729843278942374982374892374892743982000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c0000000000000000000000000000000000000000000000000000000000000000b736f6d6520737472696e670000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000013736f6d6520616e6f7468657220737472696e67000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024746865726520617265206a75737420746f6f206d616e7920737472696e6773757020696e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000046865726500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002079616c6c2067686f6e6e61206d616b65206d65206c6f7365206d79206d696e640000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000034746865206c6974746c6520706970696e67207069706572207069706564206120706970696e6720706970706572207061707065720000000000000000000000000000000000000000000000000000000000000000000000000000000000000081746865206b6964206b6e6f777320686f7720746f20777269746520706f656d732c20776861742063616e204920736179202d2d2049206775657373207468657265732061206c6f74204920636f756c642073617920746f2074727920746f2066696c6c2074686973206c696e6520776974682061206c6f74206f6620746578742e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f0ac511500000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000081746865206b6964206b6e6f777320686f7720746f20777269746520706f656d732c20776861742063616e204920736179202d2d2049206775657373207468657265732061206c6f74204920636f756c642073617920746f2074727920746f2066696c6c2074686973206c696e6520776974682061206c6f74206f6620746578742e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003d69d500000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000100000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f498000000000000000000000000000000000000000000000000000000000000004e616b64686a61736a6b646861736a6b6c647368646a6168646b6a73616864616a6b73646873616a6b646873616a6b646861646a6b617368646a6b73616468616a6b646873616a6b64687361646a6b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002829384723894723843743289742389472398473289472348927489274894738427428947389facdea0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000000000000000000000000000000089b51500000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000100000000000000000000000000746dafa5ebde1f4699f4981d3221892e41d24895000000000000000000000000000000000000000000000000000000000000004e6b73646873616a6b646873616a6b646861646a6b617368646a6b73616468616a6b646873616a6b64687361646a6b616b64686a61736a6b646861736a6b6c647368646a6168646b6a73616864616a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002829384723894398473289472348927489272384374328974238947274894738427428947389facde100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000fa3150000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000010000000000000000000000000089571d322189e415ebde1f4699f498d24246dafa000000000000000000000000000000000000000000000000000000000000004e73646873616a6b646873616a6b646861646a6b617368646a616b64686a61736a6b646861736a6b6c647368646a6168646b6a73616864616a6b6b73616468616a6b646873616a6b64687361646a6b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002838947238437432829384729742389472398473289472348927489274894738427428947389facdef000000000000000000000000000000000000000000000000';
//const expectedCalldata = '0x30e1f844000000000000000000000000000000000000000000000000000000000000007f000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000003600000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000260000000000000000000000000000000000000000000000000000000000000042000000000000000000000000000000000000000000000000000000000000008600000000000000000000000000000000000000000000000000000000000000960000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000034746865206c6974746c6520706970696e67207069706572207069706564206120706970696e6720706970706572207061707065720000000000000000000000000000000000000000000000000000000000000000000000000000000000000081746865206b6964206b6e6f777320686f7720746f20777269746520706f656d732c20776861742063616e204920736179202d2d2049206775657373207468657265732061206c6f74204920636f756c642073617920746f2074727920746f2066696c6c2074686973206c696e6520776974682061206c6f74206f6620746578742e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000163874563783498732482743928742389723894723984700000000000000000000000000000000000000000000000000000000000000000000000000000000006e72834723982374239847239847298472489274987489742847289472394874987498478743294237434923473298472398423748923748923748923472389472894789474893742894728947389427498237432987423894723894732894723894372498237498237428934723980000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000027283473298473248923749238742398742398472894729843278942374982374892374892743982000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c0000000000000000000000000000000000000000000000000000000000000000b736f6d6520737472696e670000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000013736f6d6520616e6f7468657220737472696e67000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024746865726520617265206a75737420746f6f206d616e7920737472696e6773757020696e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000046865726500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002079616c6c2067686f6e6e61206d616b65206d65206c6f7365206d79206d696e640000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000034746865206c6974746c6520706970696e67207069706572207069706564206120706970696e6720706970706572207061707065720000000000000000000000000000000000000000000000000000000000000000000000000000000000000081746865206b6964206b6e6f777320686f7720746f20777269746520706f656d732c20776861742063616e204920736179202d2d2049206775657373207468657265732061206c6f74204920636f756c642073617920746f2074727920746f2066696c6c2074686973206c696e6520776974682061206c6f74206f6620746578742e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f0ac511500000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000081746865206b6964206b6e6f777320686f7720746f20777269746520706f656d732c20776861742063616e204920736179202d2d2049206775657373207468657265732061206c6f74204920636f756c642073617920746f2074727920746f2066696c6c2074686973206c696e6520776974682061206c6f74206f6620746578742e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000cf5763d5ec63d500600000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000100000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f498000000000000000000000000000000000000000000000000000000000000004e616b64686a61736a6b646861736a6b6c647368646a6168646b6a73616864616a6b73646873616a6b646873616a6b646861646a6b617368646a6b73616468616a6b646873616a6b64687361646a6b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024f7484848484848484848484848484848484848384757687980943399445858584893209100000000000000000000000000000000000000000000000000000000';
expect(calldata).to.be.equal(expectedCalldata);
});
it.skip('Crazy ABI #1', async () => {
const method = new AbiEncoder.Method(AbiSamples.crazyAbi1);
const args = [
new BigNumber(256745454),
new BigNumber(-256745454),
new BigNumber(434244),
'0x43',
'0x0001020304050607080911121314151617181920212223242526272829303132',
'0x0001020304050607080911121314151617181920212223242526272829303132080911121314151617181920212223242526272829303132',
'Little peter piper piped a piping pepper pot',
'0xe41d2489571d322189246dafa5ebde1f4699f498',
true
];
const calldata = method.encode(args);
console.log(calldata);
console.log('*'.repeat(40));
console.log(method.getSignature());
console.log(JSON.stringify(args));
const expectedCalldata = '0x312d4d42000000000000000000000000000000000000000000000000000000000f4d9feefffffffffffffffffffffffffffffffffffffffffffffffffffffffff0b26012000000000000000000000000000000000000000000000000000000000006a0444300000000000000000000000000000000000000000000000000000000000000000102030405060708091112131415161718192021222324252627282930313200000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000180000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f4980000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000003800010203040506070809111213141516171819202122232425262728293031320809111213141516171819202122232425262728293031320000000000000000000000000000000000000000000000000000000000000000000000000000002c4c6974746c65207065746572207069706572207069706564206120706970696e672070657070657220706f740000000000000000000000000000000000000000';
expect(calldata).to.be.equal(expectedCalldata);
});
it('Types with default widths', async () => {
const method = new AbiEncoder.Method(AbiSamples.typesWithDefaultWidthsAbi);
console.log(method);
const args = [new BigNumber(1), new BigNumber(-1), '0x56', [new BigNumber(1)], [new BigNumber(-1)], ['0x56']];
const calldata = method.encode(args);
console.log(calldata);
console.log('*'.repeat(40));
console.log(method.getSignature());
console.log(JSON.stringify(args));
const expectedCalldata = '0x09f2b0c30000000000000000000000000000000000000000000000000000000000000001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff560000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000000000015600000000000000000000000000000000000000000000000000000000000000';
expect(calldata).to.be.equal(expectedCalldata);
});
it('Array of Static Tuples (Array has defined length)', async () => {
const method = new AbiEncoder.Method(AbiSamples.arrayOfStaticTuplesWithDefinedLengthAbi);
let value = 0;
const arrayOfTuples = [];
for (let i = 0; i < 8; ++i) {
arrayOfTuples.push([new BigNumber(++value), new BigNumber(++value)]);
}
const args = [arrayOfTuples];
const calldata = method.encode(args);
console.log(calldata);
console.log('*'.repeat(40));
console.log(method.getSignature());
console.log(JSON.stringify(args));
const expectedCalldata = '0x9eb20969000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000b000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000d000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000f0000000000000000000000000000000000000000000000000000000000000010';
expect(calldata).to.be.equal(expectedCalldata);
});
it('Array of Static Tuples (Array has dynamic length)', async () => {
const method = new AbiEncoder.Method(AbiSamples.arrayOfStaticTuplesWithDynamicLengthAbi);
let value = 0;
const arrayOfTuples = [];
for (let i = 0; i < 8; ++i) {
arrayOfTuples.push([new BigNumber(++value), new BigNumber(++value)]);
}
const args = [arrayOfTuples];
const calldata = method.encode(args);
console.log(calldata);
console.log('*'.repeat(40));
console.log(method.getSignature());
console.log(JSON.stringify(args));
const expectedCalldata = '0x63275d6e00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000b000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000d000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000f0000000000000000000000000000000000000000000000000000000000000010';
expect(calldata).to.be.equal(expectedCalldata);
});
it('Array of Dynamic Tuples (Array has defined length)', async () => {
const method = new AbiEncoder.Method(AbiSamples.arrayOfDynamicTuplesWithDefinedLengthAbi);
let value = 0;
const arrayOfTuples = [];
for (let i = 0; i < 8; ++i) {
arrayOfTuples.push([new BigNumber(++value), (new BigNumber(++value)).toString()]);
}
const args = [arrayOfTuples];
const calldata = method.encode(args);
console.log(calldata);
console.log('*'.repeat(40));
console.log(method.getSignature());
console.log(JSON.stringify(args));
const expectedCalldata = '0xdeedb00f00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000280000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000003800000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000048000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000132000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000013400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001360000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000138000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000023130000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000023132000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000023134000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000023136000000000000000000000000000000000000000000000000000000000000';
expect(calldata).to.be.equal(expectedCalldata);
});
it('Array of Dynamic Tuples (Array has dynamic length)', async () => {
const method = new AbiEncoder.Method(AbiSamples.arrayOfDynamicTuplesWithUndefinedLengthAbi);
let value = 0;
const arrayOfTuples = [];
for (let i = 0; i < 8; ++i) {
arrayOfTuples.push([new BigNumber(++value), (new BigNumber(++value)).toString()]);
}
const args = [arrayOfTuples];
const calldata = method.encode(args);
console.log(calldata);
console.log('*'.repeat(40));
console.log(method.getSignature());
console.log(JSON.stringify(args));
const expectedCalldata = '0x60c847fb000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000280000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000003800000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000048000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000132000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000013400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001360000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000138000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000023130000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000023132000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000023134000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000023136000000000000000000000000000000000000000000000000000000000000';
expect(calldata).to.be.equal(expectedCalldata);
});
it('Multidimensional Arrays / Static Members', async () => {
const method = new AbiEncoder.Method(AbiSamples.multiDimensionalArraysStaticTypeAbi);
// Eight 3-dimensional arrays of uint8[2][2][2]
let value = 0;
const args = [];
for (let i = 0; i < 8; ++i) {
args.push(
[
[
[new BigNumber(++value), new BigNumber(++value)],
[new BigNumber(++value), new BigNumber(++value)],
],
[
[new BigNumber(++value), new BigNumber(++value)],
[new BigNumber(++value), new BigNumber(++value)],
]
]
);
}
const calldata = method.encode(args);
console.log(calldata);
console.log('*'.repeat(40));
console.log(method.getSignature());
console.log(JSON.stringify(args));
const expectedCalldata = '0xc2f47d6f00000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000480000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000009600000000000000000000000000000000000000000000000000000000000000b000000000000000000000000000000000000000000000000000000000000000d400000000000000000000000000000000000000000000000000000000000000e600000000000000000000000000000000000000000000000000000000000000039000000000000000000000000000000000000000000000000000000000000003a000000000000000000000000000000000000000000000000000000000000003b000000000000000000000000000000000000000000000000000000000000003c000000000000000000000000000000000000000000000000000000000000003d000000000000000000000000000000000000000000000000000000000000003e000000000000000000000000000000000000000000000000000000000000003f00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000b000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000d000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000f0000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000110000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000130000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001500000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001700000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000019000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000001b000000000000000000000000000000000000000000000000000000000000001c0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001d000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000001f000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000210000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000230000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000025000000000000000000000000000000000000000000000000000000000000002600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000027000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000029000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000002b000000000000000000000000000000000000000000000000000000000000002c000000000000000000000000000000000000000000000000000000000000002d000000000000000000000000000000000000000000000000000000000000002e000000000000000000000000000000000000000000000000000000000000002f0000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000003100000000000000000000000000000000000000000000000000000000000000320000000000000000000000000000000000000000000000000000000000000033000000000000000000000000000000000000000000000000000000000000003400000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000035000000000000000000000000000000000000000000000000000000000000003600000000000000000000000000000000000000000000000000000000000000370000000000000000000000000000000000000000000000000000000000000038'; expect(calldata).to.be.equal(expectedCalldata);
expect(calldata).to.be.equal(expectedCalldata);
});
it('Multidimensional Arrays / Dynamic Members', async () => {
const method = new AbiEncoder.Method(AbiSamples.multiDimensionalArraysDynamicTypeAbi);
// Eight 3-dimensional arrays of string[2][2][2]
let value = 0;
const args = [];
for (let i = 0; i < 4; ++i) {
args.push(
[
[
[new BigNumber(++value).toString(), new BigNumber(++value).toString()],
[new BigNumber(++value).toString(), new BigNumber(++value).toString()],
],
[
[new BigNumber(++value).toString(), new BigNumber(++value).toString()],
[new BigNumber(++value).toString(), new BigNumber(++value).toString()],
]
]
);
}
const calldata = method.encode(args);
console.log(calldata);
console.log('*'.repeat(40));
console.log(method.getSignature());
console.log(JSON.stringify(args));
const expectedCalldata = '0x81534ebd0000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000052000000000000000000000000000000000000000000000000000000000000009a00000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000260000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000131000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001320000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000013300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000134000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000001350000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000013600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000137000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001380000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000260000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000139000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002313000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000023131000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000231320000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000002313300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000023134000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000231350000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002313600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000231370000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002313800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000023139000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000232300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000023231000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000232320000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000002323300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000023234000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000232350000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002323600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000232370000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002323800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000002323900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000023330000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000002333100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000023332000000000000000000000000000000000000000000000000000000000000';
expect(calldata).to.be.equal(expectedCalldata);
});
it('Fixed Lenfgth Array / Dynamic Members', async () => {
const method = new AbiEncoder.Method(AbiSamples.staticArrayDynamicMembersAbi);
const args = [["Brave", "New", "World"]];
const calldata = method.encode(args);
console.log(calldata);
console.log('*'.repeat(40));
console.log(JSON.stringify(args));
const expectedCalldata =
'0x243a6e6e0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000005427261766500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034e657700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005576f726c64000000000000000000000000000000000000000000000000000000';
expect(calldata).to.be.equal(expectedCalldata);
});
it('Fixed Lenfgth Array / Dynamic Members', async () => {
const method = new AbiEncoder.Method(AbiSamples.staticArrayDynamicMembersAbi);
const args = [["Brave", "New", "World"]];
const calldata = method.encode(args);
console.log(calldata);
console.log('*'.repeat(40));
console.log(JSON.stringify(args));
const expectedCalldata =
'0x243a6e6e0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000005427261766500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034e657700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005576f726c64000000000000000000000000000000000000000000000000000000';
expect(calldata).to.be.equal(expectedCalldata);
});
it('Unfixed Length Array / Dynamic Members ABI', async () => {
const method = new AbiEncoder.Method(AbiSamples.dynamicArrayDynamicMembersAbi);
const args = [["Brave", "New", "World"]];
const calldata = method.encode(args);
console.log(calldata);
console.log('*'.repeat(40));
console.log(JSON.stringify(args));
const expectedCalldata = '0x13e751a900000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000005427261766500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034e657700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005576f726c64000000000000000000000000000000000000000000000000000000';
expect(calldata).to.be.equal(expectedCalldata);
});
it('Unfixed Length Array / Static Members ABI', async () => {
const method = new AbiEncoder.Method(AbiSamples.dynamicArrayStaticMembersAbi);
const args = [[new BigNumber(127), new BigNumber(14), new BigNumber(54)]];
const calldata = method.encode(args);
const expectedCalldata = '0x4fc8a83300000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000007f000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000036';
expect(calldata).to.be.equal(expectedCalldata);
});
it('Fixed Length Array / Static Members ABI', async () => {
const method = new AbiEncoder.Method(AbiSamples.staticArrayAbi);
const args = [[new BigNumber(127), new BigNumber(14), new BigNumber(54)]];
const calldata = method.encode(args);
const expectedCalldata =
'0xf68ade72000000000000000000000000000000000000000000000000000000000000007f000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000036';
expect(calldata).to.be.equal(expectedCalldata);
});
it('Simple ABI 2', async () => {
const method = new AbiEncoder.Method(AbiSamples.simpleAbi2);
const args = [
'0xaf', // e (bytes1)
'0x0001020304050607080911121314151617181920212223242526272829303132', // f (bytes32)
'0x616161616161616161616161616161616161616161616161616161616161616161616161616161611114f324567838475647382938475677448899338457668899002020202020', // g
'My first name is Greg and my last name is Hysen, what do ya know!', // h
];
const calldata = method.encode(args);
const expectedCalldata =
'0x7ac2bd96af000000000000000000000000000000000000000000000000000000000000000001020304050607080911121314151617181920212223242526272829303132000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000047616161616161616161616161616161616161616161616161616161616161616161616161616161611114f3245678384756473829384756774488993384576688990020202020200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000414d79206669727374206e616d65206973204772656720616e64206d79206c617374206e616d6520697320487973656e2c207768617420646f207961206b6e6f772100000000000000000000000000000000000000000000000000000000000000';
expect(calldata).to.be.equal(expectedCalldata);
});
it.only('Yessir', async () => {
const method = new AbiEncoder.Method(AbiSamples.simpleAbi);
const calldata = method.encode([new BigNumber(5), 'five']);
console.log(calldata);
expect(true).to.be.true();
});
it('Array ABI', async () => {
const method = new AbiEncoder.Method(AbiSamples.stringAbi);
const calldata = method.encode([['five', 'six', 'seven']]);
console.log(method.getSignature());
console.log(method.selector);
console.log(calldata);
const expectedCalldata =
'0x13e751a900000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000046669766500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000373697800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005736576656e000000000000000000000000000000000000000000000000000000';
expect(calldata).to.be.equal(expectedCalldata);
});
it('Static Tuple', async () => {
// This is dynamic because it has dynamic members
const method = new AbiEncoder.Method(AbiSamples.staticTupleAbi);
const calldata = method.encode([[new BigNumber(5), new BigNumber(10), new BigNumber(15), false]]);
console.log(method.getSignature());
console.log(method.selector);
console.log(calldata);
const expectedCalldata = '0xa9125e150000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000f0000000000000000000000000000000000000000000000000000000000000000';
expect(calldata).to.be.equal(expectedCalldata);
});
it('Dynamic Tuple (Array input)', async () => {
// This is dynamic because it has dynamic members
const method = new AbiEncoder.Method(AbiSamples.dynamicTupleAbi);
const calldata = method.encode([[new BigNumber(5), 'five']]);
console.log(method.getSignature());
console.log(method.selector);
console.log(calldata);
const expectedCalldata =
'0x5b998f3500000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000046669766500000000000000000000000000000000000000000000000000000000';
expect(calldata).to.be.equal(expectedCalldata);
});
it('Dynamic Tuple (Object input)', async () => {
// This is dynamic because it has dynamic members
const method = new AbiEncoder.Method(AbiSamples.dynamicTupleAbi);
const calldata = method.encode([{ someUint: new BigNumber(5), someStr: 'five' }]);
console.log(method.getSignature());
console.log(method.selector);
console.log(calldata);
const expectedCalldata =
'0x5b998f3500000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000046669766500000000000000000000000000000000000000000000000000000000';
expect(calldata).to.be.equal(expectedCalldata);
});
it.skip('Object ABI (Object input - Missing Key)', async () => {
const method = new AbiEncoder.Method(AbiSamples.dynamicTupleAbi);
const calldata = method.encode([{ someUint: new BigNumber(5) }]);
console.log(method.getSignature());
console.log(method.selector);
console.log(calldata);
const expectedCalldata =
'0x5b998f3500000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000046669766500000000000000000000000000000000000000000000000000000000';
// @TODO: Figure out how to catch throw
expect(calldata).to.be.equal(expectedCalldata);
});
it.skip('Object ABI (Object input - Too Many Keys)', async () => {
const method = new AbiEncoder.Method(AbiSamples.dynamicTupleAbi);
const calldata = method.encode([{ someUint: new BigNumber(5), someStr: 'five', unwantedKey: 14 }]);
console.log(method.getSignature());
console.log(method.selector);
console.log(calldata);
const expectedCalldata =
'0x5b998f3500000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000046669766500000000000000000000000000000000000000000000000000000000';
// @TODO: Figure out how to catch throw
expect(calldata).to.be.equal(expectedCalldata);
});
});
/*
describe('Array', () => {
it('sample', async () => {
const testDataItem = { name: 'testArray', type: 'int[2]' };
const dataType = new AbiEncoder.SolArray(testDataItem);
console.log(JSON.stringify(dataType, null, 4));
console.log('*'.repeat(60));
dataType.assignValue([new BigNumber(5), new BigNumber(6)]);
console.log(JSON.stringify(dataType, null, 4));
const hexValue = dataType.getHexValue();
console.log('*'.repeat(60));
console.log(hexValue);
});
it('sample undefined size', async () => {
const testDataItem = { name: 'testArray', type: 'int[]' };
const dataType = new AbiEncoder.SolArray(testDataItem);
console.log(JSON.stringify(dataType, null, 4));
console.log('*'.repeat(60));
dataType.assignValue([new BigNumber(5), new BigNumber(6)]);
console.log(JSON.stringify(dataType, null, 4));
const hexValue = dataType.getHexValue();
console.log('*'.repeat(60));
console.log(hexValue);
});
it('sample dynamic types', async () => {
const testDataItem = { name: 'testArray', type: 'string[]' };
const dataType = new AbiEncoder.SolArray(testDataItem);
console.log(JSON.stringify(dataType, null, 4));
console.log('*'.repeat(60));
dataType.assignValue(['five', 'six', 'seven']);
console.log(JSON.stringify(dataType, null, 4));
const hexValue = dataType.getHexValue();
console.log('*'.repeat(60));
console.log(hexValue);
const calldata = new AbiEncoder.Calldata('0x01020304', 1);
dataType.bind(calldata, AbiEncoder.CalldataSection.PARAMS);
console.log('*'.repeat(60));
console.log(calldata.getHexValue());
});
});
describe('Address', () => {
const testAddressDataItem = { name: 'testAddress', type: 'address' };
it('Valid Address', async () => {
const addressDataType = new AbiEncoder.Address(testAddressDataItem);
addressDataType.assignValue('0xe41d2489571d322189246dafa5ebde1f4699f498');
const expectedAbiEncodedAddress = '0x000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f498';
console.log(addressDataType.getHexValue());
console.log(expectedAbiEncodedAddress);
expect(addressDataType.getHexValue()).to.be.equal(expectedAbiEncodedAddress);
});
});
describe('Bool', () => {
const testBoolDataItem = { name: 'testBool', type: 'bool' };
it('True', async () => {
const boolDataType = new AbiEncoder.Bool(testBoolDataItem);
boolDataType.assignValue(true);
const expectedAbiEncodedBool = '0x0000000000000000000000000000000000000000000000000000000000000001';
expect(boolDataType.getHexValue()).to.be.equal(expectedAbiEncodedBool);
});
it('False', async () => {
const boolDataType = new AbiEncoder.Bool(testBoolDataItem);
boolDataType.assignValue(false);
const expectedAbiEncodedBool = '0x0000000000000000000000000000000000000000000000000000000000000000';
expect(boolDataType.getHexValue()).to.be.equal(expectedAbiEncodedBool);
});
});
describe('Integer', () => {
const testIntDataItem = { name: 'testInt', type: 'int' };
it('Positive - Base case', async () => {
const intDataType = new AbiEncoder.Int(testIntDataItem);
intDataType.assignValue(new BigNumber(1));
const expectedAbiEncodedInt = '0x0000000000000000000000000000000000000000000000000000000000000001';
expect(intDataType.getHexValue()).to.be.equal(expectedAbiEncodedInt);
});
it('Positive', async () => {
const intDataType = new AbiEncoder.Int(testIntDataItem);
intDataType.assignValue(new BigNumber(437829473));
const expectedAbiEncodedInt = '0x000000000000000000000000000000000000000000000000000000001a18bf61';
expect(intDataType.getHexValue()).to.be.equal(expectedAbiEncodedInt);
});
it('Negative - Base case', async () => {
const intDataType = new AbiEncoder.Int(testIntDataItem);
intDataType.assignValue(new BigNumber(-1));
const expectedAbiEncodedInt = '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff';
expect(intDataType.getHexValue()).to.be.equal(expectedAbiEncodedInt);
});
it('Negative', async () => {
const intDataType = new AbiEncoder.Int(testIntDataItem);
intDataType.assignValue(new BigNumber(-437829473));
const expectedAbiEncodedInt = '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffe5e7409f';
expect(intDataType.getHexValue()).to.be.equal(expectedAbiEncodedInt);
});
// TODO: Add bounds tests + tests for different widths
});
describe('Unsigned Integer', () => {
const testIntDataItem = { name: 'testUInt', type: 'uint' };
it('Lower Bound', async () => {
const uintDataType = new AbiEncoder.UInt(testIntDataItem);
uintDataType.assignValue(new BigNumber(0));
const expectedAbiEncodedUInt = '0x0000000000000000000000000000000000000000000000000000000000000000';
expect(uintDataType.getHexValue()).to.be.equal(expectedAbiEncodedUInt);
});
it('Base Case', async () => {
const uintDataType = new AbiEncoder.UInt(testIntDataItem);
uintDataType.assignValue(new BigNumber(1));
const expectedAbiEncodedUInt = '0x0000000000000000000000000000000000000000000000000000000000000001';
expect(uintDataType.getHexValue()).to.be.equal(expectedAbiEncodedUInt);
});
it('Random value', async () => {
const uintDataType = new AbiEncoder.UInt(testIntDataItem);
uintDataType.assignValue(new BigNumber(437829473));
const expectedAbiEncodedUInt = '0x000000000000000000000000000000000000000000000000000000001a18bf61';
expect(uintDataType.getHexValue()).to.be.equal(expectedAbiEncodedUInt);
});
// TODO: Add bounds tests + tests for different widths
});
describe('Static Bytes', () => {
it('Byte (padded)', async () => {
const testByteDataItem = { name: 'testStaticBytes', type: 'byte' };
const byteDataType = new AbiEncoder.Byte(testByteDataItem);
byteDataType.assignValue('0x05');
const expectedAbiEncodedByte = '0x0500000000000000000000000000000000000000000000000000000000000000';
expect(byteDataType.getHexValue()).to.be.equal(expectedAbiEncodedByte);
});
it.skip('Byte (no padding)', async () => {
const testByteDataItem = { name: 'testStaticBytes', type: 'byte' };
const byteDataType = new AbiEncoder.Byte(testByteDataItem);
// @TODO: This does not catch the Error
expect(byteDataType.assignValue('0x5')).to.throw();
});
it('Bytes1', async () => {
const testByteDataItem = { name: 'testStaticBytes', type: 'bytes1' };
const byteDataType = new AbiEncoder.Byte(testByteDataItem);
byteDataType.assignValue('0x05');
const expectedAbiEncodedByte = '0x0500000000000000000000000000000000000000000000000000000000000000';
expect(byteDataType.getHexValue()).to.be.equal(expectedAbiEncodedByte);
});
it('Bytes32 (padded)', async () => {
const testByteDataItem = { name: 'testStaticBytes', type: 'bytes32' };
const byteDataType = new AbiEncoder.Byte(testByteDataItem);
byteDataType.assignValue('0x0001020304050607080911121314151617181920212223242526272829303132');
const expectedAbiEncodedByte = '0x0001020304050607080911121314151617181920212223242526272829303132';
expect(byteDataType.getHexValue()).to.be.equal(expectedAbiEncodedByte);
});
it('Bytes32 (unpadded)', async () => {
const testByteDataItem = { name: 'testStaticBytes', type: 'bytes32' };
const byteDataType = new AbiEncoder.Byte(testByteDataItem);
byteDataType.assignValue('0x1a18bf61');
const expectedAbiEncodedByte = '0x1a18bf6100000000000000000000000000000000000000000000000000000000';
expect(byteDataType.getHexValue()).to.be.equal(expectedAbiEncodedByte);
});
it.skip('Bytes32 - Too long', async () => {
const testByteDataItem = { name: 'testStaticBytes', type: 'bytes32' };
const byteDataType = new AbiEncoder.Byte(testByteDataItem);
// @TODO: This does not catch the Error
expect(
byteDataType.assignValue('0x000102030405060708091112131415161718192021222324252627282930313233'),
).to.throw(
`Tried to assign 0x000102030405060708091112131415161718192021222324252627282930313233 (33 bytes), which exceeds max bytes that can be stored in a bytes32`,
);
});
});
describe('Bytes (Dynamic)', () => {
const testBytesDataItem = { name: 'testBytes', type: 'bytes' };
it('Less than 32 bytes', async () => {
const bytesDataType = new AbiEncoder.Bytes(testBytesDataItem);
bytesDataType.assignValue('0x010203');
const expectedAbiEncodedBytes =
'0x00000000000000000000000000000000000000000000000000000000000000030102030000000000000000000000000000000000000000000000000000000000';
expect(bytesDataType.getHexValue()).to.be.equal(expectedAbiEncodedBytes);
});
it('Greater than 32 bytes', async () => {
const bytesDataType = new AbiEncoder.Bytes(testBytesDataItem);
const testValue = '0x' + '61'.repeat(40);
bytesDataType.assignValue(testValue);
const expectedAbiEncodedBytes =
'0x000000000000000000000000000000000000000000000000000000000000002861616161616161616161616161616161616161616161616161616161616161616161616161616161000000000000000000000000000000000000000000000000';
expect(bytesDataType.getHexValue()).to.be.equal(expectedAbiEncodedBytes);
});
// @TODO: Add test for throw on half-byte
// @TODO: Test with no 0x prefix
// @TODO: Test with Buffer as input
});
describe('String', () => {
const testStringDataItem = { name: 'testString', type: 'string' };
it('Less than 32 bytes', async () => {
const stringDataType = new AbiEncoder.SolString(testStringDataItem);
stringDataType.assignValue('five');
const expectedAbiEncodedString =
'0x00000000000000000000000000000000000000000000000000000000000000046669766500000000000000000000000000000000000000000000000000000000';
console.log(stringDataType.getHexValue());
console.log(expectedAbiEncodedString);
expect(stringDataType.getHexValue()).to.be.equal(expectedAbiEncodedString);
});
it('Greater than 32 bytes', async () => {
const stringDataType = new AbiEncoder.SolString(testStringDataItem);
const testValue = 'a'.repeat(40);
stringDataType.assignValue(testValue);
const expectedAbiEncodedString =
'0x000000000000000000000000000000000000000000000000000000000000002861616161616161616161616161616161616161616161616161616161616161616161616161616161000000000000000000000000000000000000000000000000';
expect(stringDataType.getHexValue()).to.be.equal(expectedAbiEncodedString);
});
});*/
});
|