next part of abi.js parsers tests and fixes

This commit is contained in:
Marek Kotewicz 2015-01-14 20:29:20 +01:00
parent b0a9bbf33a
commit 603c790213
5 changed files with 211 additions and 21 deletions

8
dist/ethereum.js vendored

@ -111,7 +111,7 @@ var setupInputTypes = function () {
{ type: prefixedType('string'), format: formatString }, { type: prefixedType('string'), format: formatString },
{ type: prefixedType('real'), format: formatInt }, { type: prefixedType('real'), format: formatInt },
{ type: prefixedType('ureal'), format: formatInt }, { type: prefixedType('ureal'), format: formatInt },
{ type: namedType('address') }, { type: namedType('address'), format: formatInt },
{ type: namedType('bool'), format: formatBool } { type: namedType('bool'), format: formatBool }
]; ];
}; };
@ -173,6 +173,10 @@ var setupOutputTypes = function () {
return web3.toAscii(value); return web3.toAscii(value);
}; };
var formatAddress = function (value) {
return "0x" + value.slice(value.length - 40, value.length);
};
return [ return [
{ type: prefixedType('uint'), format: formatInt }, { type: prefixedType('uint'), format: formatInt },
{ type: prefixedType('int'), format: formatInt }, { type: prefixedType('int'), format: formatInt },
@ -180,7 +184,7 @@ var setupOutputTypes = function () {
{ type: prefixedType('string'), format: formatString }, { type: prefixedType('string'), format: formatString },
{ type: prefixedType('real'), format: formatInt }, { type: prefixedType('real'), format: formatInt },
{ type: prefixedType('ureal'), format: formatInt }, { type: prefixedType('ureal'), format: formatInt },
{ type: namedType('address') }, { type: namedType('address'), format: formatAddress },
{ type: namedType('bool'), format: formatBool } { type: namedType('bool'), format: formatBool }
]; ];
}; };

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -110,7 +110,7 @@ var setupInputTypes = function () {
{ type: prefixedType('string'), format: formatString }, { type: prefixedType('string'), format: formatString },
{ type: prefixedType('real'), format: formatInt }, { type: prefixedType('real'), format: formatInt },
{ type: prefixedType('ureal'), format: formatInt }, { type: prefixedType('ureal'), format: formatInt },
{ type: namedType('address') }, { type: namedType('address'), format: formatInt },
{ type: namedType('bool'), format: formatBool } { type: namedType('bool'), format: formatBool }
]; ];
}; };
@ -172,6 +172,10 @@ var setupOutputTypes = function () {
return web3.toAscii(value); return web3.toAscii(value);
}; };
var formatAddress = function (value) {
return "0x" + value.slice(value.length - 40, value.length);
};
return [ return [
{ type: prefixedType('uint'), format: formatInt }, { type: prefixedType('uint'), format: formatInt },
{ type: prefixedType('int'), format: formatInt }, { type: prefixedType('int'), format: formatInt },
@ -179,7 +183,7 @@ var setupOutputTypes = function () {
{ type: prefixedType('string'), format: formatString }, { type: prefixedType('string'), format: formatString },
{ type: prefixedType('real'), format: formatInt }, { type: prefixedType('real'), format: formatInt },
{ type: prefixedType('ureal'), format: formatInt }, { type: prefixedType('ureal'), format: formatInt },
{ type: namedType('address') }, { type: namedType('address'), format: formatAddress },
{ type: namedType('bool'), format: formatBool } { type: namedType('bool'), format: formatBool }
]; ];
}; };

@ -146,7 +146,7 @@ describe('abi', function() {
}); });
it('should parse input hash', function() { it('should parse input hash', function() {
/*
// given // given
var d = clone(description); var d = clone(description);
@ -158,46 +158,61 @@ describe('abi', function() {
var parser = abi.inputParser(d); var parser = abi.inputParser(d);
// then // then
assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); assert.equal(parser.test("0x407d73d8a49eeb85d32cf465507dd71d507100c1"), "000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1");
*/
}); });
it('should parse input hash128', function() { it('should parse input hash256', function() {
/*
// given // given
var d = clone(description); var d = clone(description);
d[0].inputs = [ d[0].inputs = [
{ type: "hash128" } { type: "hash256" }
]; ];
// when // when
var parser = abi.inputParser(d); var parser = abi.inputParser(d);
// then // then
assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); assert.equal(parser.test("0x407d73d8a49eeb85d32cf465507dd71d507100c1"), "000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1");
*/
}); });
it('should parse input hash', function() { it('should parse input hash160', function() {
/*
// given // given
var d = clone(description); var d = clone(description);
d[0].inputs = [ d[0].inputs = [
{ type: "hash" } { type: "hash160" }
]; ];
// when // when
var parser = abi.inputParser(d); var parser = abi.inputParser(d);
// then // then
assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); assert.equal(parser.test("0x407d73d8a49eeb85d32cf465507dd71d507100c1"), "000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1");
*/
}); });
it('should parse input string', function() { it('should parse input address', function () {
// given
var d = clone(description);
d[0].inputs = [
{ type: "address" }
];
// when
var parser = abi.inputParser(d)
// then
assert.equal(parser.test("0x407d73d8a49eeb85d32cf465507dd71d507100c1"), "000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1");
});
it('should parse input string', function () {
// given // given
var d = clone(description); var d = clone(description);
@ -272,7 +287,174 @@ describe('abi', function() {
assert.equal(parser.test("0x776f726c64000000000000000000000000000000000000000000000000000000")[0], 'world'); assert.equal(parser.test("0x776f726c64000000000000000000000000000000000000000000000000000000")[0], 'world');
}); });
it('should parse output uint', function() {
// given
var d = clone(description);
d[0].outputs = [
{ type: 'uint' }
];
// when
var parser = abi.outputParser(d);
// then
assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1);
assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10);
});
it('should parse output uint256', function() {
// given
var d = clone(description);
d[0].outputs = [
{ type: 'uint256' }
];
// when
var parser = abi.outputParser(d);
// then
assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1);
assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10);
});
it('should parse output uint128', function() {
// given
var d = clone(description);
d[0].outputs = [
{ type: 'uinti128' }
];
// when
var parser = abi.outputParser(d);
// then
assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1);
assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10);
});
it('should parse output int', function() {
// given
var d = clone(description);
d[0].outputs = [
{ type: 'int' }
];
// when
var parser = abi.outputParser(d);
// then
assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1);
assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10);
});
it('should parse output int256', function() {
// given
var d = clone(description);
d[0].outputs = [
{ type: 'int256' }
];
// when
var parser = abi.outputParser(d);
// then
assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1);
assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10);
});
it('should parse output int128', function() {
// given
var d = clone(description);
d[0].outputs = [
{ type: 'inti128' }
];
// when
var parser = abi.outputParser(d);
// then
assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1);
assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10);
});
it('should parse output hash', function() {
// given
var d = clone(description);
d[0].outputs = [
{ type: 'hash' }
];
// when
var parser = abi.outputParser(d);
// then
assert.equal(parser.test("0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1")[0], "0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1")
});
it('should parse output hash256', function() {
// given
var d = clone(description);
d[0].outputs = [
{ type: 'hash256' }
];
// when
var parser = abi.outputParser(d);
// then
assert.equal(parser.test("0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1")[0], "0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1")
});
it('should parse output hash160', function() {
// given
var d = clone(description);
d[0].outputs = [
{ type: 'hash256' }
];
// when
var parser = abi.outputParser(d);
// then
assert.equal(parser.test("0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1")[0], "0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1")
// TODO shouldnt' the expected hash be shorter?
});
it('should parse output address', function() {
// given
var d = clone(description);
d[0].outputs = [
{ type: 'address' }
];
// when
var parser = abi.outputParser(d);
// then
assert.equal(parser.test("0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1")[0], "0x407d73d8a49eeb85d32cf465507dd71d507100c1")
});
it('should parse output bool', function() { it('should parse output bool', function() {
// given // given