From 4056c046a7d1907bdb0c0682cd487538915fcdd2 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 13 Jan 2015 13:47:31 +0100 Subject: [PATCH] tests... --- test/abi.parsers.js | 122 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 111 insertions(+), 11 deletions(-) diff --git a/test/abi.parsers.js b/test/abi.parsers.js index f9dba6688..8d0c2bc95 100644 --- a/test/abi.parsers.js +++ b/test/abi.parsers.js @@ -21,29 +21,53 @@ describe('abi', function() { describe('inputParser', function() { it('should parse input uint', function() { + // given var d = clone(description); d[0].inputs = [ - { type: "uint256" } + { type: "uint" } ]; + // when var parser = abi.inputParser(d); + + // then assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a"); + }); + + it('should parse input uint128', function() { + + // given + var d = clone(description); + d[0].inputs = [ { type: "uint128" } ]; + // when var parser = abi.inputParser(d); + + // then assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a"); + }); + + it('should parse input uint', function() { + + // given + var d = clone(description); + d[0].inputs = [ - { type: "uint" } + { type: "uint256" } ]; + // when var parser = abi.inputParser(d); + + // then assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a"); @@ -51,70 +75,123 @@ describe('abi', function() { it('should parse input int', function() { + // given var d = clone(description); d[0].inputs = [ - { type: "int256" } + { type: "int" } ]; + // when var parser = abi.inputParser(d); + + // then assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a"); + }); + + it('should parse input int128', function() { + + // given + var d = clone(description); + d[0].inputs = [ { type: "int128" } ]; + // when var parser = abi.inputParser(d); + + // then assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a"); + }); + + it('should parse input int256', function() { + + // given + var d = clone(description); + d[0].inputs = [ - { type: "int" } + { type: "int256" } ]; + // when var parser = abi.inputParser(d); + + // then assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a"); }); it('should parse input hash', function() { - +/* + // given var d = clone(description); d[0].inputs = [ - { type: "hash256" } + { type: "hash" } ]; + // when var parser = abi.inputParser(d); + + // then assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); +*/ + }); + + it('should parse input hash128', function() { +/* + // given + var d = clone(description); d[0].inputs = [ { type: "hash128" } ]; + // when var parser = abi.inputParser(d); + + // then assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); +*/ + }); + + + it('should parse input hash', function() { +/* + // given + var d = clone(description); d[0].inputs = [ { type: "hash" } ]; + // when var parser = abi.inputParser(d); - assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); + // then + assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); +*/ }); it('should parse input string', function() { + // given var d = clone(description); d[0].inputs = [ { type: "string" } ]; + // when var parser = abi.inputParser(d); + + // then assert.equal(parser.test('hello'), "68656c6c6f000000000000000000000000000000000000000000000000000000"); assert.equal(parser.test('world'), "776f726c64000000000000000000000000000000000000000000000000000000"); }); @@ -123,17 +200,40 @@ describe('abi', function() { describe('outputParser', function() { - it('parse ...', function() { - + it('should parse output string', function() { + + // given var d = clone(description); d[0].outputs = [ { type: "string" } ]; + // when var parser = abi.outputParser(d); - assert.equal(parser.test("0x68656c6c6f00000000000000000000000000000000000000000000000000000")[0], 'hello'); - assert.equal(parser.test("0x776f726c6400000000000000000000000000000000000000000000000000000")[0], 'world'); + + // then + assert.equal(parser.test("0x68656c6c6f000000000000000000000000000000000000000000000000000000")[0], 'hello'); + assert.equal(parser.test("0x776f726c64000000000000000000000000000000000000000000000000000000")[0], 'world'); + + }); + + it('should parse multiplt output strings', function() { + + // given + var d = clone(description); + + d[0].outputs = [ + { type: "string" }, + { type: "string" } + ]; + + // when + var parser = abi.outputParser(d); + + // then + assert.equal(parser.test("0x68656c6c6f000000000000000000000000000000000000000000000000000000776f726c64000000000000000000000000000000000000000000000000000000")[0], 'hello'); + assert.equal(parser.test("0x68656c6c6f000000000000000000000000000000000000000000000000000000776f726c64000000000000000000000000000000000000000000000000000000")[1], 'world'); }); });