Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
1e2c1ae9
Commit
1e2c1ae9
authored
Jan 17, 2015
by
Marek Kotewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
output parser string support
parent
b457e88c
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
207 additions
and
127 deletions
+207
-127
ethereum.js
dist/ethereum.js
+79
-50
ethereum.js.map
dist/ethereum.js.map
+2
-2
ethereum.min.js
dist/ethereum.min.js
+1
-1
abi.js
lib/abi.js
+78
-50
abi.parsers.js
test/abi.parsers.js
+47
-24
No files found.
dist/ethereum.js
View file @
1e2c1ae9
...
@@ -158,6 +158,7 @@ var toAbiInput = function (json, methodName, params) {
...
@@ -158,6 +158,7 @@ var toAbiInput = function (json, methodName, params) {
var
method
=
json
[
index
];
var
method
=
json
[
index
];
var
padding
=
ETH_PADDING
*
2
;
var
padding
=
ETH_PADDING
*
2
;
/// first we iterate in search for dynamic
method
.
inputs
.
forEach
(
function
(
input
,
index
)
{
method
.
inputs
.
forEach
(
function
(
input
,
index
)
{
bytes
+=
dynamicTypeBytes
(
input
.
type
,
params
[
index
]);
bytes
+=
dynamicTypeBytes
(
input
.
type
,
params
[
index
]);
});
});
...
@@ -186,57 +187,63 @@ var toAbiInput = function (json, methodName, params) {
...
@@ -186,57 +187,63 @@ var toAbiInput = function (json, methodName, params) {
return
bytes
;
return
bytes
;
};
};
/// Setups output formaters for solidity types
/// Formats input right-aligned input bytes to int
/// @returns an array of output formatters
/// @returns right-aligned input bytes formatted to int
var
setupOutputTypes
=
function
()
{
var
formatOutputInt
=
function
(
value
)
{
// check if it's negative number
// it it is, return two's complement
var
firstBit
=
new
BigNumber
(
value
.
substr
(
0
,
1
),
16
).
toString
(
2
).
substr
(
0
,
1
);
if
(
firstBit
===
'1'
)
{
return
new
BigNumber
(
value
,
16
).
minus
(
new
BigNumber
(
'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
,
16
)).
minus
(
1
);
}
return
new
BigNumber
(
value
,
16
);
};
/// Formats input right-aligned input bytes to int
/// Formats big right-aligned input bytes to uint
/// @returns right-aligned input bytes formatted to int
/// @returns right-aligned input bytes formatted to uint
var
formatInt
=
function
(
value
)
{
var
formatOutputUInt
=
function
(
value
)
{
// check if it's negative number
return
new
BigNumber
(
value
,
16
);
// it it is, return two's complement
};
var
firstBit
=
new
BigNumber
(
value
.
substr
(
0
,
1
),
16
).
toString
(
2
).
substr
(
0
,
1
);
if
(
firstBit
===
'1'
)
{
return
new
BigNumber
(
value
,
16
).
minus
(
new
BigNumber
(
'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
,
16
)).
minus
(
1
);
}
return
new
BigNumber
(
value
,
16
);
};
/// Formats big right-aligned input bytes to uint
/// @returns right-aligned input bytes formatted to hex
/// @returns right-aligned input bytes formatted to uint
var
formatOutputHash
=
function
(
value
)
{
var
formatUInt
=
function
(
value
)
{
return
"0x"
+
value
;
return
new
BigNumber
(
value
,
16
);
};
};
/// @returns right-aligned input bytes formatted to hex
/// @returns right-aligned input bytes formatted to bool
var
formatHash
=
function
(
value
)
{
var
formatOutputBool
=
function
(
value
)
{
return
"0x"
+
valu
e
;
return
value
===
'0000000000000000000000000000000000000000000000000000000000000001'
?
true
:
fals
e
;
};
};
/// @returns right-aligned input bytes formatted to bool
/// @returns left-aligned input bytes formatted to ascii string
var
formatBool
=
function
(
value
)
{
var
formatOutputString
=
function
(
value
)
{
return
value
===
'0000000000000000000000000000000000000000000000000000000000000001'
?
true
:
false
;
return
web3
.
toAscii
(
value
)
;
};
};
/// @returns left-aligned input bytes formatted to ascii string
/// @returns right-aligned input bytes formatted to address
var
formatString
=
function
(
value
)
{
var
formatOutputAddress
=
function
(
value
)
{
return
web3
.
toAscii
(
value
);
return
"0x"
+
value
.
slice
(
value
.
length
-
40
,
value
.
length
);
};
};
/// @returns right-aligned input bytes formatted to address
var
dynamicBytesLength
=
function
(
type
)
{
var
formatAddress
=
function
(
value
)
{
if
(
arrayType
(
type
)
||
prefixedType
(
'string'
)(
type
))
return
"0x"
+
value
.
slice
(
value
.
length
-
40
,
value
.
length
);
return
ETH_PADDING
*
2
;
};
return
0
;
};
/// Setups output formaters for solidity types
/// @returns an array of output formatters
var
setupOutputTypes
=
function
()
{
return
[
return
[
{
type
:
prefixedType
(
'uint'
),
format
:
formatUInt
},
{
type
:
prefixedType
(
'uint'
),
format
:
format
Output
UInt
},
{
type
:
prefixedType
(
'int'
),
format
:
formatInt
},
{
type
:
prefixedType
(
'int'
),
format
:
format
Output
Int
},
{
type
:
prefixedType
(
'hash'
),
format
:
formatHash
},
{
type
:
prefixedType
(
'hash'
),
format
:
format
Output
Hash
},
{
type
:
prefixedType
(
'string'
),
format
:
formatString
},
{
type
:
prefixedType
(
'string'
),
format
:
format
Output
String
},
{
type
:
prefixedType
(
'real'
),
format
:
formatInt
},
{
type
:
prefixedType
(
'real'
),
format
:
format
Output
Int
},
{
type
:
prefixedType
(
'ureal'
),
format
:
formatInt
},
{
type
:
prefixedType
(
'ureal'
),
format
:
format
Output
Int
},
{
type
:
namedType
(
'address'
),
format
:
formatAddress
},
{
type
:
namedType
(
'address'
),
format
:
format
Output
Address
},
{
type
:
namedType
(
'bool'
),
format
:
formatBool
}
{
type
:
namedType
(
'bool'
),
format
:
format
Output
Bool
}
];
];
};
};
...
@@ -259,22 +266,44 @@ var fromAbiOutput = function (json, methodName, output) {
...
@@ -259,22 +266,44 @@ var fromAbiOutput = function (json, methodName, output) {
var
result
=
[];
var
result
=
[];
var
method
=
json
[
index
];
var
method
=
json
[
index
];
var
padding
=
ETH_PADDING
*
2
;
var
padding
=
ETH_PADDING
*
2
;
for
(
var
i
=
0
;
i
<
method
.
outputs
.
length
;
i
++
)
{
var
dynamicPartLength
=
method
.
outputs
.
reduce
(
function
(
acc
,
curr
)
{
return
acc
+
dynamicBytesLength
(
curr
.
type
);
},
0
);
var
dynamicPart
=
output
.
slice
(
0
,
dynamicPartLength
);
output
=
output
.
slice
(
dynamicPartLength
);
method
.
outputs
.
forEach
(
function
(
out
,
i
)
{
var
typeMatch
=
false
;
var
typeMatch
=
false
;
for
(
var
j
=
0
;
j
<
outputTypes
.
length
&&
!
typeMatch
;
j
++
)
{
for
(
var
j
=
0
;
j
<
outputTypes
.
length
&&
!
typeMatch
;
j
++
)
{
typeMatch
=
outputTypes
[
j
].
type
(
method
.
outputs
[
i
].
type
);
typeMatch
=
outputTypes
[
j
].
type
(
method
.
outputs
[
i
].
type
);
}
}
if
(
!
typeMatch
)
{
if
(
!
typeMatch
)
{
// not found output parsing
console
.
error
(
'output parser does not support type: '
+
method
.
outputs
[
i
].
type
);
console
.
error
(
'output parser does not support type: '
+
method
.
outputs
[
i
].
type
);
continue
;
}
}
var
res
=
output
.
slice
(
0
,
padding
);
var
formatter
=
outputTypes
[
j
-
1
].
format
;
var
formatter
=
outputTypes
[
j
-
1
].
format
;
result
.
push
(
formatter
?
formatter
(
res
)
:
(
"0x"
+
res
));
if
(
arrayType
(
method
.
outputs
[
i
].
type
))
{
output
=
output
.
slice
(
padding
);
var
size
=
formatOutputUInt
(
dynamicPart
.
slice
(
0
,
padding
));
}
dynamicPart
=
dynamicPart
.
slice
(
padding
);
var
array
=
[];
for
(
var
k
=
0
;
k
<
size
;
k
++
)
{
array
.
push
(
formatter
(
output
.
slice
(
0
,
padding
)));
output
=
output
.
slice
(
padding
);
}
result
.
push
(
array
);
}
else
if
(
prefixedType
(
'string'
)(
method
.
outputs
[
i
].
type
))
{
dynamicPart
=
dynamicPart
.
slice
(
padding
);
result
.
push
(
formatter
(
output
.
slice
(
0
,
padding
)));
output
=
output
.
slice
(
padding
);
}
else
{
result
.
push
(
formatter
(
output
.
slice
(
0
,
padding
)));
output
=
output
.
slice
(
padding
);
}
});
return
result
;
return
result
;
};
};
...
...
dist/ethereum.js.map
View file @
1e2c1ae9
This diff is collapsed.
Click to expand it.
dist/ethereum.min.js
View file @
1e2c1ae9
This diff is collapsed.
Click to expand it.
lib/abi.js
View file @
1e2c1ae9
...
@@ -186,57 +186,63 @@ var toAbiInput = function (json, methodName, params) {
...
@@ -186,57 +186,63 @@ var toAbiInput = function (json, methodName, params) {
return
bytes
;
return
bytes
;
};
};
/// Setups output formaters for solidity types
/// Formats input right-aligned input bytes to int
/// @returns an array of output formatters
/// @returns right-aligned input bytes formatted to int
var
setupOutputTypes
=
function
()
{
var
formatOutputInt
=
function
(
value
)
{
// check if it's negative number
// it it is, return two's complement
var
firstBit
=
new
BigNumber
(
value
.
substr
(
0
,
1
),
16
).
toString
(
2
).
substr
(
0
,
1
);
if
(
firstBit
===
'1'
)
{
return
new
BigNumber
(
value
,
16
).
minus
(
new
BigNumber
(
'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
,
16
)).
minus
(
1
);
}
return
new
BigNumber
(
value
,
16
);
};
/// Formats input right-aligned input bytes to int
/// Formats big right-aligned input bytes to uint
/// @returns right-aligned input bytes formatted to int
/// @returns right-aligned input bytes formatted to uint
var
formatInt
=
function
(
value
)
{
var
formatOutputUInt
=
function
(
value
)
{
// check if it's negative number
return
new
BigNumber
(
value
,
16
);
// it it is, return two's complement
};
var
firstBit
=
new
BigNumber
(
value
.
substr
(
0
,
1
),
16
).
toString
(
2
).
substr
(
0
,
1
);
if
(
firstBit
===
'1'
)
{
return
new
BigNumber
(
value
,
16
).
minus
(
new
BigNumber
(
'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
,
16
)).
minus
(
1
);
}
return
new
BigNumber
(
value
,
16
);
};
/// Formats big right-aligned input bytes to uint
/// @returns right-aligned input bytes formatted to hex
/// @returns right-aligned input bytes formatted to uint
var
formatOutputHash
=
function
(
value
)
{
var
formatUInt
=
function
(
value
)
{
return
"0x"
+
value
;
return
new
BigNumber
(
value
,
16
);
};
};
/// @returns right-aligned input bytes formatted to hex
/// @returns right-aligned input bytes formatted to bool
var
formatHash
=
function
(
value
)
{
var
formatOutputBool
=
function
(
value
)
{
return
"0x"
+
valu
e
;
return
value
===
'0000000000000000000000000000000000000000000000000000000000000001'
?
true
:
fals
e
;
};
};
/// @returns right-aligned input bytes formatted to bool
/// @returns left-aligned input bytes formatted to ascii string
var
formatBool
=
function
(
value
)
{
var
formatOutputString
=
function
(
value
)
{
return
value
===
'0000000000000000000000000000000000000000000000000000000000000001'
?
true
:
false
;
return
web3
.
toAscii
(
value
)
;
};
};
/// @returns left-aligned input bytes formatted to ascii string
/// @returns right-aligned input bytes formatted to address
var
formatString
=
function
(
value
)
{
var
formatOutputAddress
=
function
(
value
)
{
return
web3
.
toAscii
(
value
);
return
"0x"
+
value
.
slice
(
value
.
length
-
40
,
value
.
length
);
};
};
/// @returns right-aligned input bytes formatted to address
var
dynamicBytesLength
=
function
(
type
)
{
var
formatAddress
=
function
(
value
)
{
if
(
arrayType
(
type
)
||
prefixedType
(
'string'
)(
type
))
return
"0x"
+
value
.
slice
(
value
.
length
-
40
,
value
.
length
);
return
ETH_PADDING
*
2
;
};
return
0
;
};
/// Setups output formaters for solidity types
/// @returns an array of output formatters
var
setupOutputTypes
=
function
()
{
return
[
return
[
{
type
:
prefixedType
(
'uint'
),
format
:
formatUInt
},
{
type
:
prefixedType
(
'uint'
),
format
:
format
Output
UInt
},
{
type
:
prefixedType
(
'int'
),
format
:
formatInt
},
{
type
:
prefixedType
(
'int'
),
format
:
format
Output
Int
},
{
type
:
prefixedType
(
'hash'
),
format
:
formatHash
},
{
type
:
prefixedType
(
'hash'
),
format
:
format
Output
Hash
},
{
type
:
prefixedType
(
'string'
),
format
:
formatString
},
{
type
:
prefixedType
(
'string'
),
format
:
format
Output
String
},
{
type
:
prefixedType
(
'real'
),
format
:
formatInt
},
{
type
:
prefixedType
(
'real'
),
format
:
format
Output
Int
},
{
type
:
prefixedType
(
'ureal'
),
format
:
formatInt
},
{
type
:
prefixedType
(
'ureal'
),
format
:
format
Output
Int
},
{
type
:
namedType
(
'address'
),
format
:
formatAddress
},
{
type
:
namedType
(
'address'
),
format
:
format
Output
Address
},
{
type
:
namedType
(
'bool'
),
format
:
formatBool
}
{
type
:
namedType
(
'bool'
),
format
:
format
Output
Bool
}
];
];
};
};
...
@@ -259,22 +265,44 @@ var fromAbiOutput = function (json, methodName, output) {
...
@@ -259,22 +265,44 @@ var fromAbiOutput = function (json, methodName, output) {
var
result
=
[];
var
result
=
[];
var
method
=
json
[
index
];
var
method
=
json
[
index
];
var
padding
=
ETH_PADDING
*
2
;
var
padding
=
ETH_PADDING
*
2
;
for
(
var
i
=
0
;
i
<
method
.
outputs
.
length
;
i
++
)
{
var
dynamicPartLength
=
method
.
outputs
.
reduce
(
function
(
acc
,
curr
)
{
return
acc
+
dynamicBytesLength
(
curr
.
type
);
},
0
);
var
dynamicPart
=
output
.
slice
(
0
,
dynamicPartLength
);
output
=
output
.
slice
(
dynamicPartLength
);
method
.
outputs
.
forEach
(
function
(
out
,
i
)
{
var
typeMatch
=
false
;
var
typeMatch
=
false
;
for
(
var
j
=
0
;
j
<
outputTypes
.
length
&&
!
typeMatch
;
j
++
)
{
for
(
var
j
=
0
;
j
<
outputTypes
.
length
&&
!
typeMatch
;
j
++
)
{
typeMatch
=
outputTypes
[
j
].
type
(
method
.
outputs
[
i
].
type
);
typeMatch
=
outputTypes
[
j
].
type
(
method
.
outputs
[
i
].
type
);
}
}
if
(
!
typeMatch
)
{
if
(
!
typeMatch
)
{
// not found output parsing
console
.
error
(
'output parser does not support type: '
+
method
.
outputs
[
i
].
type
);
console
.
error
(
'output parser does not support type: '
+
method
.
outputs
[
i
].
type
);
continue
;
}
}
var
res
=
output
.
slice
(
0
,
padding
);
var
formatter
=
outputTypes
[
j
-
1
].
format
;
var
formatter
=
outputTypes
[
j
-
1
].
format
;
result
.
push
(
formatter
?
formatter
(
res
)
:
(
"0x"
+
res
));
if
(
arrayType
(
method
.
outputs
[
i
].
type
))
{
output
=
output
.
slice
(
padding
);
var
size
=
formatOutputUInt
(
dynamicPart
.
slice
(
0
,
padding
));
}
dynamicPart
=
dynamicPart
.
slice
(
padding
);
var
array
=
[];
for
(
var
k
=
0
;
k
<
size
;
k
++
)
{
array
.
push
(
formatter
(
output
.
slice
(
0
,
padding
)));
output
=
output
.
slice
(
padding
);
}
result
.
push
(
array
);
}
else
if
(
prefixedType
(
'string'
)(
method
.
outputs
[
i
].
type
))
{
dynamicPart
=
dynamicPart
.
slice
(
padding
);
result
.
push
(
formatter
(
output
.
slice
(
0
,
padding
)));
output
=
output
.
slice
(
padding
);
}
else
{
result
.
push
(
formatter
(
output
.
slice
(
0
,
padding
)));
output
=
output
.
slice
(
padding
);
}
});
return
result
;
return
result
;
};
};
...
...
test/abi.parsers.js
View file @
1e2c1ae9
...
@@ -40,9 +40,9 @@ describe('abi', function() {
...
@@ -40,9 +40,9 @@ describe('abi', function() {
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
);
);
assert
.
equal
(
assert
.
equal
(
parser
.
test
(
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
)),
parser
.
test
(
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
)),
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
);
);
assert
.
equal
(
parser
.
test
(
0.1
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
0.1
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
3.9
),
"0000000000000000000000000000000000000000000000000000000000000003"
);
assert
.
equal
(
parser
.
test
(
3.9
),
"0000000000000000000000000000000000000000000000000000000000000003"
);
assert
.
equal
(
parser
.
test
(
'0.1'
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
'0.1'
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
...
@@ -71,9 +71,9 @@ describe('abi', function() {
...
@@ -71,9 +71,9 @@ describe('abi', function() {
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
);
);
assert
.
equal
(
assert
.
equal
(
parser
.
test
(
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
)),
parser
.
test
(
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
)),
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
);
);
assert
.
equal
(
parser
.
test
(
0.1
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
0.1
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
3.9
),
"0000000000000000000000000000000000000000000000000000000000000003"
);
assert
.
equal
(
parser
.
test
(
3.9
),
"0000000000000000000000000000000000000000000000000000000000000003"
);
assert
.
equal
(
parser
.
test
(
'0.1'
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
'0.1'
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
...
@@ -101,9 +101,9 @@ describe('abi', function() {
...
@@ -101,9 +101,9 @@ describe('abi', function() {
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
);
);
assert
.
equal
(
assert
.
equal
(
parser
.
test
(
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
)),
parser
.
test
(
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
)),
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
);
);
assert
.
equal
(
parser
.
test
(
0.1
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
0.1
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
3.9
),
"0000000000000000000000000000000000000000000000000000000000000003"
);
assert
.
equal
(
parser
.
test
(
3.9
),
"0000000000000000000000000000000000000000000000000000000000000003"
);
assert
.
equal
(
parser
.
test
(
'0.1'
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
'0.1'
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
...
@@ -134,9 +134,9 @@ describe('abi', function() {
...
@@ -134,9 +134,9 @@ describe('abi', function() {
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
);
);
assert
.
equal
(
assert
.
equal
(
parser
.
test
(
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
)),
parser
.
test
(
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
)),
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
);
);
assert
.
equal
(
parser
.
test
(
0.1
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
0.1
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
3.9
),
"0000000000000000000000000000000000000000000000000000000000000003"
);
assert
.
equal
(
parser
.
test
(
3.9
),
"0000000000000000000000000000000000000000000000000000000000000003"
);
assert
.
equal
(
parser
.
test
(
'0.1'
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
'0.1'
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
...
@@ -166,9 +166,9 @@ describe('abi', function() {
...
@@ -166,9 +166,9 @@ describe('abi', function() {
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
);
);
assert
.
equal
(
assert
.
equal
(
parser
.
test
(
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
)),
parser
.
test
(
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
)),
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
);
);
assert
.
equal
(
parser
.
test
(
0.1
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
0.1
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
3.9
),
"0000000000000000000000000000000000000000000000000000000000000003"
);
assert
.
equal
(
parser
.
test
(
3.9
),
"0000000000000000000000000000000000000000000000000000000000000003"
);
assert
.
equal
(
parser
.
test
(
'0.1'
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
'0.1'
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
...
@@ -199,9 +199,9 @@ describe('abi', function() {
...
@@ -199,9 +199,9 @@ describe('abi', function() {
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
);
);
assert
.
equal
(
assert
.
equal
(
parser
.
test
(
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
)),
parser
.
test
(
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
)),
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
);
);
assert
.
equal
(
parser
.
test
(
0.1
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
0.1
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
3.9
),
"0000000000000000000000000000000000000000000000000000000000000003"
);
assert
.
equal
(
parser
.
test
(
3.9
),
"0000000000000000000000000000000000000000000000000000000000000003"
);
assert
.
equal
(
parser
.
test
(
'0.1'
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
'0.1'
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
...
@@ -396,8 +396,18 @@ describe('abi', function() {
...
@@ -396,8 +396,18 @@ describe('abi', function() {
var
parser
=
abi
.
outputParser
(
d
);
var
parser
=
abi
.
outputParser
(
d
);
// then
// then
assert
.
equal
(
parser
.
test
(
"0x68656c6c6f000000000000000000000000000000000000000000000000000000"
)[
0
],
'hello'
);
assert
.
equal
(
assert
.
equal
(
parser
.
test
(
"0x776f726c64000000000000000000000000000000000000000000000000000000"
)[
0
],
'world'
);
parser
.
test
(
"0x"
+
"0000000000000000000000000000000000000000000000000000000000000005"
+
"68656c6c6f000000000000000000000000000000000000000000000000000000"
)[
0
],
'hello'
);
assert
.
equal
(
parser
.
test
(
"0x"
+
"0000000000000000000000000000000000000000000000000000000000000005"
+
"776f726c64000000000000000000000000000000000000000000000000000000"
)[
0
],
'world'
);
});
});
...
@@ -644,12 +654,21 @@ describe('abi', function() {
...
@@ -644,12 +654,21 @@ describe('abi', function() {
// then
// then
assert
.
equal
(
assert
.
equal
(
parser
.
test
(
"0x68656c6c6f000000000000000000000000000000000000000000000000000000776f726c64000000000000000000000000000000000000000000000000000000"
)[
0
],
parser
.
test
(
"0x"
+
"0000000000000000000000000000000000000000000000000000000000000005"
+
"0000000000000000000000000000000000000000000000000000000000000005"
+
"68656c6c6f000000000000000000000000000000000000000000000000000000"
+
"776f726c64000000000000000000000000000000000000000000000000000000"
)[
0
],
'hello'
'hello'
);
);
assert
.
equal
(
assert
.
equal
(
parser
.
test
(
"0x68656c6c6f000000000000000000000000000000000000000000000000000000776f726c64000000000000000000000000000000000000000000000000000000"
)[
1
],
parser
.
test
(
"0x"
+
'world'
);
"0000000000000000000000000000000000000000000000000000000000000005"
+
"0000000000000000000000000000000000000000000000000000000000000005"
+
"68656c6c6f000000000000000000000000000000000000000000000000000000"
+
"776f726c64000000000000000000000000000000000000000000000000000000"
)[
1
],
'world'
);
});
});
...
@@ -689,7 +708,11 @@ describe('abi', function() {
...
@@ -689,7 +708,11 @@ describe('abi', function() {
//then
//then
assert
.
equal
(
parser
.
test
(
"0000000000000000000000000000000000000000000000000000000000000001"
)[
0
],
1
);
assert
.
equal
(
parser
.
test
(
"0000000000000000000000000000000000000000000000000000000000000001"
)[
0
],
1
);
assert
.
equal
(
parser
.
test2
(
"0x68656c6c6f000000000000000000000000000000000000000000000000000000"
)[
0
],
"hello"
);
assert
.
equal
(
parser
.
test2
(
"0x"
+
"0000000000000000000000000000000000000000000000000000000000000005"
+
"68656c6c6f000000000000000000000000000000000000000000000000000000"
)[
0
],
"hello"
);
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment