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
|
var assert = require('assert');
var abi = require('../lib/abi.js');
var clone = function (object) { return JSON.parse(JSON.stringify(object)); };
var description = [{
"name": "test",
"inputs": [{
"name": "a",
"type": "uint256"
}
],
"outputs": [
{
"name": "d",
"type": "uint256"
}
]
}];
describe('abi', function() {
describe('inputParser', function() {
it('should parse input uint', function() {
var d = clone(description);
d[0].inputs = [
{ type: "uint256" }
];
var parser = abi.inputParser(d);
assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001");
assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a");
d[0].inputs = [
{ type: "uint128" }
];
var parser = abi.inputParser(d);
assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001");
assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a");
d[0].inputs = [
{ type: "uint" }
];
var parser = abi.inputParser(d);
assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001");
assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a");
});
it('should parse input int', function() {
var d = clone(description);
d[0].inputs = [
{ type: "int256" }
];
var parser = abi.inputParser(d);
assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001");
assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a");
d[0].inputs = [
{ type: "int128" }
];
var parser = abi.inputParser(d);
assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001");
assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a");
d[0].inputs = [
{ type: "int" }
];
var parser = abi.inputParser(d);
assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001");
assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a");
});
it('should parse input hash', function() {
var d = clone(description);
d[0].inputs = [
{ type: "hash256" }
];
var parser = abi.inputParser(d);
assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001");
d[0].inputs = [
{ type: "hash128" }
];
var parser = abi.inputParser(d);
assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001");
d[0].inputs = [
{ type: "hash" }
];
var parser = abi.inputParser(d);
assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001");
});
it('should parse input string', function() {
var d = clone(description);
d[0].inputs = [
{ type: "string" }
];
var parser = abi.inputParser(d);
assert.equal(parser.test('hello'), "68656c6c6f000000000000000000000000000000000000000000000000000000");
assert.equal(parser.test('world'), "776f726c64000000000000000000000000000000000000000000000000000000");
});
});
describe('outputParser', function() {
it('parse ...', function() {
var d = clone(description);
d[0].outputs = [
{ type: "string" }
];
var parser = abi.outputParser(d);
assert.equal(parser.test("0x68656c6c6f00000000000000000000000000000000000000000000000000000")[0], 'hello');
assert.equal(parser.test("0x776f726c6400000000000000000000000000000000000000000000000000000")[0], 'world');
});
});
});
|