forked from web3/web3.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheth.abi.decodeParameters.js
More file actions
91 lines (86 loc) · 3.16 KB
/
eth.abi.decodeParameters.js
File metadata and controls
91 lines (86 loc) · 3.16 KB
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
var chai = require('chai');
var assert = chai.assert;
var Abi = require('../packages/web3-eth-abi');
var tests = [{
params: [['string', 'uint256'], '0x000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000ea000000000000000000000000000000000000000000000000000000000000000848656c6c6f212521000000000000000000000000000000000000000000000000'],
result: {
'0': 'Hello!%!',
'1': '234',
"__length__": 2
}
},{
params: [[{
type: 'string',
name: 'myString'
},{
type: 'uint256',
name: 'myNumber'
}], '0x000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000ea000000000000000000000000000000000000000000000000000000000000000848656c6c6f212521000000000000000000000000000000000000000000000000'],
result: {
'0': 'Hello!%!',
'1': '234',
myString: 'Hello!%!',
myNumber: '234',
"__length__": 2
}
},{
params: [['string'], '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'],
result: {'0': "", "__length__": 1}
},{
params: [['int256'], '0x0000000000000000000000000000000000000000000000000000000000000000'],
result: {'0': "0", "__length__": 1}
},{
params: [['uint256'], '0x0000000000000000000000000000000000000000000000000000000000000000'],
result: {'0': "0", "__length__": 1}
},{
params: [['bytes'], '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'],
result: {'0': null, "__length__": 1}
},{
params: [['address'], '0x0000000000000000000000000000000000000000000000000000000000000000'],
result: {'0': "0x0000000000000000000000000000000000000000", "__length__": 1}
},{
params: [['bytes32'], '0x0000000000000000000000000000000000000000000000000000000000000000'],
result: {'0': "0x0000000000000000000000000000000000000000000000000000000000000000", "__length__": 1}
},{
params: [['bool'], '0x0000000000000000000000000000000000000000000000000000000000000000'],
result: {'0': false, "__length__": 1}
}];
describe('decodeParameters', function () {
tests.forEach(function (test) {
it('should convert correctly', function () {
assert.deepEqual(Abi.decodeParameters.apply(Abi, test.params), test.result);
});
});
});
var failures = [{
params: [['string', 'uint256'], '0x']
},{
params: [[{
type: 'string',
name: 'myString'
},{
type: 'uint256',
name: 'myNumber'
}], '0x']
},{
params: [['string'], '0x']
},{
params: [['int256'], '0x']
},{
params: [['uint256'], '0x']
},{
params: [['bytes'], '0x']
},{
params: [['address'], '0x']
},{
params: [['bytes32'], '0x']
},{
params: [['bool'], '0x']
}];
describe('decodeParameters', function () {
failures.forEach(function (test) {
it('should not convert '+test.params[1]+' to '+test.params[0], function () {
assert.throws(_ => {Abi.decodeParameters.apply(Abi, test.params)});
});
});
});