Commit 603c7902 authored by Marek Kotewicz's avatar Marek Kotewicz

next part of abi.js parsers tests and fixes

parent b0a9bbf3
...@@ -111,7 +111,7 @@ var setupInputTypes = function () { ...@@ -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 () { ...@@ -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 () { ...@@ -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 }
]; ];
}; };
......
This diff is collapsed.
This diff is collapsed.
...@@ -110,7 +110,7 @@ var setupInputTypes = function () { ...@@ -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 () { ...@@ -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 () { ...@@ -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() { ...@@ -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() { ...@@ -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 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() { it('should parse input string', function () {
// given // given
var d = clone(description); var d = clone(description);
...@@ -273,6 +288,173 @@ describe('abi', function() { ...@@ -273,6 +288,173 @@ describe('abi', function() {
}); });
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment