mirror of https://github.com/status-im/op-geth.git
fixed #23
This commit is contained in:
parent
42a25f2f26
commit
09f633596d
|
@ -212,6 +212,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)) {
|
||||
|
@ -223,6 +224,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);
|
||||
};
|
||||
|
||||
|
@ -1078,7 +1080,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
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -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)) {
|
||||
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue