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
2c36d5ff
Commit
2c36d5ff
authored
Jan 16, 2015
by
Marek Kotewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
big integers on abi.js output, tests
parent
f1295b50
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
78 additions
and
13 deletions
+78
-13
ethereum.js
dist/ethereum.js
+11
-2
ethereum.js.map
dist/ethereum.js.map
+2
-2
ethereum.min.js
dist/ethereum.min.js
+1
-1
abi.js
lib/abi.js
+11
-2
abi.parsers.js
test/abi.parsers.js
+53
-6
No files found.
dist/ethereum.js
View file @
2c36d5ff
...
...
@@ -176,7 +176,16 @@ var setupOutputTypes = function () {
/// Formats input right-aligned input bytes to int
/// @returns right-aligned input bytes formatted to int
var
formatInt
=
function
(
value
)
{
return
value
.
length
<=
8
?
+
parseInt
(
value
,
16
)
:
hexToDec
(
value
);
// check if it's negative number
// it it is, return two's complement
if
(
value
.
substr
(
0
,
1
).
toLowerCase
()
===
'f'
)
{
return
new
BigNumber
(
value
,
16
).
minus
(
new
BigNumber
(
'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
,
16
)).
minus
(
1
);
}
return
new
BigNumber
(
value
,
16
);
};
var
formatUInt
=
function
(
value
)
{
return
new
BigNumber
(
value
,
16
);
};
/// @returns right-aligned input bytes formatted to hex
...
...
@@ -200,7 +209,7 @@ var setupOutputTypes = function () {
};
return
[
{
type
:
prefixedType
(
'uint'
),
format
:
formatInt
},
{
type
:
prefixedType
(
'uint'
),
format
:
format
U
Int
},
{
type
:
prefixedType
(
'int'
),
format
:
formatInt
},
{
type
:
prefixedType
(
'hash'
),
format
:
formatHash
},
{
type
:
prefixedType
(
'string'
),
format
:
formatString
},
...
...
dist/ethereum.js.map
View file @
2c36d5ff
This diff is collapsed.
Click to expand it.
dist/ethereum.min.js
View file @
2c36d5ff
This diff is collapsed.
Click to expand it.
lib/abi.js
View file @
2c36d5ff
...
...
@@ -175,7 +175,16 @@ var setupOutputTypes = function () {
/// Formats input right-aligned input bytes to int
/// @returns right-aligned input bytes formatted to int
var
formatInt
=
function
(
value
)
{
return
value
.
length
<=
8
?
+
parseInt
(
value
,
16
)
:
hexToDec
(
value
);
// check if it's negative number
// it it is, return two's complement
if
(
value
.
substr
(
0
,
1
).
toLowerCase
()
===
'f'
)
{
return
new
BigNumber
(
value
,
16
).
minus
(
new
BigNumber
(
'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
,
16
)).
minus
(
1
);
}
return
new
BigNumber
(
value
,
16
);
};
var
formatUInt
=
function
(
value
)
{
return
new
BigNumber
(
value
,
16
);
};
/// @returns right-aligned input bytes formatted to hex
...
...
@@ -199,7 +208,7 @@ var setupOutputTypes = function () {
};
return
[
{
type
:
prefixedType
(
'uint'
),
format
:
formatInt
},
{
type
:
prefixedType
(
'uint'
),
format
:
format
U
Int
},
{
type
:
prefixedType
(
'int'
),
format
:
formatInt
},
{
type
:
prefixedType
(
'hash'
),
format
:
formatHash
},
{
type
:
prefixedType
(
'string'
),
format
:
formatString
},
...
...
test/abi.parsers.js
View file @
2c36d5ff
...
...
@@ -360,6 +360,14 @@ describe('abi', function() {
// then
assert
.
equal
(
parser
.
test
(
"0x0000000000000000000000000000000000000000000000000000000000000001"
)[
0
],
1
);
assert
.
equal
(
parser
.
test
(
"0x000000000000000000000000000000000000000000000000000000000000000a"
)[
0
],
10
);
assert
.
equal
(
parser
.
test
(
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
)[
0
].
toString
(
10
),
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
).
toString
(
10
)
);
assert
.
equal
(
parser
.
test
(
"0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0"
)[
0
].
toString
(
10
),
new
BigNumber
(
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0"
,
16
).
toString
(
10
)
);
});
it
(
'should parse output uint256'
,
function
()
{
...
...
@@ -377,6 +385,14 @@ describe('abi', function() {
// then
assert
.
equal
(
parser
.
test
(
"0x0000000000000000000000000000000000000000000000000000000000000001"
)[
0
],
1
);
assert
.
equal
(
parser
.
test
(
"0x000000000000000000000000000000000000000000000000000000000000000a"
)[
0
],
10
);
assert
.
equal
(
parser
.
test
(
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
)[
0
].
toString
(
10
),
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
).
toString
(
10
)
);
assert
.
equal
(
parser
.
test
(
"0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0"
)[
0
].
toString
(
10
),
new
BigNumber
(
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0"
,
16
).
toString
(
10
)
);
});
it
(
'should parse output uint128'
,
function
()
{
...
...
@@ -394,6 +410,14 @@ describe('abi', function() {
// then
assert
.
equal
(
parser
.
test
(
"0x0000000000000000000000000000000000000000000000000000000000000001"
)[
0
],
1
);
assert
.
equal
(
parser
.
test
(
"0x000000000000000000000000000000000000000000000000000000000000000a"
)[
0
],
10
);
assert
.
equal
(
parser
.
test
(
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
)[
0
].
toString
(
10
),
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
).
toString
(
10
)
);
assert
.
equal
(
parser
.
test
(
"0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0"
)[
0
].
toString
(
10
),
new
BigNumber
(
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0"
,
16
).
toString
(
10
)
);
});
it
(
'should parse output int'
,
function
()
{
...
...
@@ -411,6 +435,8 @@ describe('abi', function() {
// then
assert
.
equal
(
parser
.
test
(
"0x0000000000000000000000000000000000000000000000000000000000000001"
)[
0
],
1
);
assert
.
equal
(
parser
.
test
(
"0x000000000000000000000000000000000000000000000000000000000000000a"
)[
0
],
10
);
assert
.
equal
(
parser
.
test
(
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
)[
0
],
-
1
);
assert
.
equal
(
parser
.
test
(
"0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0"
)[
0
],
-
16
);
});
it
(
'should parse output int256'
,
function
()
{
...
...
@@ -428,6 +454,8 @@ describe('abi', function() {
// then
assert
.
equal
(
parser
.
test
(
"0x0000000000000000000000000000000000000000000000000000000000000001"
)[
0
],
1
);
assert
.
equal
(
parser
.
test
(
"0x000000000000000000000000000000000000000000000000000000000000000a"
)[
0
],
10
);
assert
.
equal
(
parser
.
test
(
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
)[
0
],
-
1
);
assert
.
equal
(
parser
.
test
(
"0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0"
)[
0
],
-
16
);
});
it
(
'should parse output int128'
,
function
()
{
...
...
@@ -445,6 +473,8 @@ describe('abi', function() {
// then
assert
.
equal
(
parser
.
test
(
"0x0000000000000000000000000000000000000000000000000000000000000001"
)[
0
],
1
);
assert
.
equal
(
parser
.
test
(
"0x000000000000000000000000000000000000000000000000000000000000000a"
)[
0
],
10
);
assert
.
equal
(
parser
.
test
(
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
)[
0
],
-
1
);
assert
.
equal
(
parser
.
test
(
"0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0"
)[
0
],
-
16
);
});
it
(
'should parse output hash'
,
function
()
{
...
...
@@ -460,7 +490,10 @@ describe('abi', function() {
var
parser
=
abi
.
outputParser
(
d
);
// then
assert
.
equal
(
parser
.
test
(
"0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1"
)[
0
],
"0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1"
)
assert
.
equal
(
parser
.
test
(
"0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1"
)[
0
],
"0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1"
);
});
it
(
'should parse output hash256'
,
function
()
{
...
...
@@ -476,7 +509,10 @@ describe('abi', function() {
var
parser
=
abi
.
outputParser
(
d
);
// then
assert
.
equal
(
parser
.
test
(
"0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1"
)[
0
],
"0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1"
)
assert
.
equal
(
parser
.
test
(
"0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1"
)[
0
],
"0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1"
);
});
it
(
'should parse output hash160'
,
function
()
{
...
...
@@ -492,7 +528,10 @@ describe('abi', function() {
var
parser
=
abi
.
outputParser
(
d
);
// then
assert
.
equal
(
parser
.
test
(
"0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1"
)[
0
],
"0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1"
)
assert
.
equal
(
parser
.
test
(
"0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1"
)[
0
],
"0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1"
);
// TODO shouldnt' the expected hash be shorter?
});
...
...
@@ -509,7 +548,10 @@ describe('abi', function() {
var
parser
=
abi
.
outputParser
(
d
);
// then
assert
.
equal
(
parser
.
test
(
"0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1"
)[
0
],
"0x407d73d8a49eeb85d32cf465507dd71d507100c1"
)
assert
.
equal
(
parser
.
test
(
"0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1"
)[
0
],
"0x407d73d8a49eeb85d32cf465507dd71d507100c1"
);
});
it
(
'should parse output bool'
,
function
()
{
...
...
@@ -545,8 +587,13 @@ describe('abi', function() {
var
parser
=
abi
.
outputParser
(
d
);
// then
assert
.
equal
(
parser
.
test
(
"0x68656c6c6f000000000000000000000000000000000000000000000000000000776f726c64000000000000000000000000000000000000000000000000000000"
)[
0
],
'hello'
);
assert
.
equal
(
parser
.
test
(
"0x68656c6c6f000000000000000000000000000000000000000000000000000000776f726c64000000000000000000000000000000000000000000000000000000"
)[
1
],
'world'
);
assert
.
equal
(
parser
.
test
(
"0x68656c6c6f000000000000000000000000000000000000000000000000000000776f726c64000000000000000000000000000000000000000000000000000000"
)[
0
],
'hello'
);
assert
.
equal
(
parser
.
test
(
"0x68656c6c6f000000000000000000000000000000000000000000000000000000776f726c64000000000000000000000000000000000000000000000000000000"
)[
1
],
'world'
);
});
...
...
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