Skip to content

Commit

Permalink
fixed #23
Browse files Browse the repository at this point in the history
  • Loading branch information
debris committed Jan 27, 2015
1 parent 42a25f2 commit 09f6335
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 6 deletions.
6 changes: 5 additions & 1 deletion dist/ethereum.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/ethereum.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ethereum.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/abi.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ var signedIsNegative = function (value) {
/// Formats input right-aligned input bytes to int
/// @returns right-aligned input bytes formatted to int
var formatOutputInt = function (value) {
value = value || "0";
// check if it's negative number
// it it is, return two's complement
if (signedIsNegative(value)) {
Expand All @@ -222,6 +223,7 @@ var formatOutputInt = function (value) {
/// Formats big right-aligned input bytes to uint
/// @returns right-aligned input bytes formatted to uint
var formatOutputUInt = function (value) {
value = value || "0";
return new BigNumber(value, 16);
};

Expand Down
4 changes: 3 additions & 1 deletion lib/web3.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ var web3 = {

/// @returns decimal representaton of hex value prefixed by 0x
toDecimal: function (val) {
return (new BigNumber(val.substring(2), 16).toString(10));
// remove 0x and place 0, if it's required
val = val.length > 2 ? val.substring(2) : "0";
return (new BigNumber(val, 16).toString(10));
},

/// @returns hex representation (prefixed by 0x) of decimal value
Expand Down
32 changes: 32 additions & 0 deletions test/abi.parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,38 @@ describe('abi', function() {

});

it('should parse 0x value', function () {

// given
var d = clone(description);
d[0].outputs = [
{ type: 'int' }
];

// when
var parser = abi.outputParser(d);

// then
assert.equal(parser.test("0x")[0], 0);

});

it('should parse 0x value', function () {

// given
var d = clone(description);
d[0].outputs = [
{ type: 'uint' }
];

// when
var parser = abi.outputParser(d);

// then
assert.equal(parser.test("0x")[0], 0);

});

});
});

0 comments on commit 09f6335

Please sign in to comment.