diff --git a/abi.inputParser.js b/abi.inputParser.js index 7dc50b537..6700acd72 100644 --- a/abi.inputParser.js +++ b/abi.inputParser.js @@ -469,10 +469,10 @@ describe('lib/solidity/abi', function () { var parser = abi.inputParser(d); // then - assert.equal(parser.test([1]), "0000000000000000000000000000000100000000000000000000000000000000"); - assert.equal(parser.test([2.125]), "0000000000000000000000000000000220000000000000000000000000000000"); - assert.equal(parser.test([8.5]), "0000000000000000000000000000000880000000000000000000000000000000"); - assert.equal(parser.test([-1]), "ffffffffffffffffffffffffffffffff00000000000000000000000000000000"); + assert.equal(parser.test(1), "0000000000000000000000000000000100000000000000000000000000000000"); + assert.equal(parser.test(2.125), "0000000000000000000000000000000220000000000000000000000000000000"); + assert.equal(parser.test(8.5), "0000000000000000000000000000000880000000000000000000000000000000"); + assert.equal(parser.test(-1), "ffffffffffffffffffffffffffffffff00000000000000000000000000000000"); }); @@ -489,9 +489,9 @@ describe('lib/solidity/abi', function () { var parser = abi.inputParser(d); // then - assert.equal(parser.test([1]), "0000000000000000000000000000000100000000000000000000000000000000"); - assert.equal(parser.test([2.125]), "0000000000000000000000000000000220000000000000000000000000000000"); - assert.equal(parser.test([8.5]), "0000000000000000000000000000000880000000000000000000000000000000"); + assert.equal(parser.test(1), "0000000000000000000000000000000100000000000000000000000000000000"); + assert.equal(parser.test(2.125), "0000000000000000000000000000000220000000000000000000000000000000"); + assert.equal(parser.test(8.5), "0000000000000000000000000000000880000000000000000000000000000000"); }); diff --git a/abi.outputParser.js b/abi.outputParser.js index a57b84a83..5fe23e28a 100644 --- a/abi.outputParser.js +++ b/abi.outputParser.js @@ -35,13 +35,13 @@ describe('lib/solidity/abi', function() { // then assert.equal( - parser.test("0x" + + parser.test( "0000000000000000000000000000000000000000000000000000000000000005" + "68656c6c6f000000000000000000000000000000000000000000000000000000")[0], 'hello' ); assert.equal( - parser.test("0x" + + parser.test( "0000000000000000000000000000000000000000000000000000000000000005" + "776f726c64000000000000000000000000000000000000000000000000000000")[0], 'world' @@ -62,14 +62,14 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); // then - assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); + assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); + assert.equal(parser.test("000000000000000000000000000000000000000000000000000000000000000a")[0], 10); assert.equal( - parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0].toString(10), + parser.test("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0].toString(10), new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).toString(10) ); assert.equal( - parser.test("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0].toString(10), + parser.test("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0].toString(10), new BigNumber("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0", 16).toString(10) ); }); @@ -87,14 +87,14 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); // then - assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); + assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); + assert.equal(parser.test("000000000000000000000000000000000000000000000000000000000000000a")[0], 10); assert.equal( - parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0].toString(10), + parser.test("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0].toString(10), new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).toString(10) ); assert.equal( - parser.test("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0].toString(10), + parser.test("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0].toString(10), new BigNumber("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0", 16).toString(10) ); }); @@ -112,14 +112,14 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); // then - assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); + assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); + assert.equal(parser.test("000000000000000000000000000000000000000000000000000000000000000a")[0], 10); assert.equal( - parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0].toString(10), + parser.test("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0].toString(10), new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).toString(10) ); assert.equal( - parser.test("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0].toString(10), + parser.test("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0].toString(10), new BigNumber("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0", 16).toString(10) ); }); @@ -137,10 +137,10 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); // then - assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); - assert.equal(parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0], -1); - assert.equal(parser.test("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0], -16); + assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); + assert.equal(parser.test("000000000000000000000000000000000000000000000000000000000000000a")[0], 10); + assert.equal(parser.test("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0], -1); + assert.equal(parser.test("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0], -16); }); it('should parse output int256', function() { @@ -156,10 +156,10 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); // then - assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); - assert.equal(parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0], -1); - assert.equal(parser.test("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0], -16); + assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); + assert.equal(parser.test("000000000000000000000000000000000000000000000000000000000000000a")[0], 10); + assert.equal(parser.test("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0], -1); + assert.equal(parser.test("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0], -16); }); it('should parse output int128', function() { @@ -175,10 +175,10 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); // then - assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); - assert.equal(parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0], -1); - assert.equal(parser.test("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0], -16); + assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); + assert.equal(parser.test("000000000000000000000000000000000000000000000000000000000000000a")[0], 10); + assert.equal(parser.test("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0], -1); + assert.equal(parser.test("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0], -16); }); it('should parse output address', function() { @@ -195,7 +195,7 @@ describe('lib/solidity/abi', function() { // then assert.equal( - parser.test("0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1")[0], + parser.test("000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1")[0], "0x407d73d8a49eeb85d32cf465507dd71d507100c1" ); }); @@ -213,8 +213,8 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); // then - assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], true); - assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000000")[0], false); + assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000001")[0], true); + assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000000")[0], false); }); @@ -232,10 +232,10 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); // then - assert.equal(parser.test("0x0000000000000000000000000000000100000000000000000000000000000000")[0], 1); - assert.equal(parser.test("0x0000000000000000000000000000000220000000000000000000000000000000")[0], 2.125); - assert.equal(parser.test("0x0000000000000000000000000000000880000000000000000000000000000000")[0], 8.5); - assert.equal(parser.test("0xffffffffffffffffffffffffffffffff00000000000000000000000000000000")[0], -1); + assert.equal(parser.test("0000000000000000000000000000000100000000000000000000000000000000")[0], 1); + assert.equal(parser.test("0000000000000000000000000000000220000000000000000000000000000000")[0], 2.125); + assert.equal(parser.test("0000000000000000000000000000000880000000000000000000000000000000")[0], 8.5); + assert.equal(parser.test("ffffffffffffffffffffffffffffffff00000000000000000000000000000000")[0], -1); }); @@ -252,9 +252,9 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); // then - assert.equal(parser.test("0x0000000000000000000000000000000100000000000000000000000000000000")[0], 1); - assert.equal(parser.test("0x0000000000000000000000000000000220000000000000000000000000000000")[0], 2.125); - assert.equal(parser.test("0x0000000000000000000000000000000880000000000000000000000000000000")[0], 8.5); + assert.equal(parser.test("0000000000000000000000000000000100000000000000000000000000000000")[0], 1); + assert.equal(parser.test("0000000000000000000000000000000220000000000000000000000000000000")[0], 2.125); + assert.equal(parser.test("0000000000000000000000000000000880000000000000000000000000000000")[0], 8.5); }); @@ -274,7 +274,7 @@ describe('lib/solidity/abi', function() { // then assert.equal( - parser.test("0x" + + parser.test( "0000000000000000000000000000000000000000000000000000000000000005" + "0000000000000000000000000000000000000000000000000000000000000005" + "68656c6c6f000000000000000000000000000000000000000000000000000000" + @@ -282,7 +282,7 @@ describe('lib/solidity/abi', function() { 'hello' ); assert.equal( - parser.test("0x" + + parser.test( "0000000000000000000000000000000000000000000000000000000000000005" + "0000000000000000000000000000000000000000000000000000000000000005" + "68656c6c6f000000000000000000000000000000000000000000000000000000" + @@ -305,8 +305,8 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); // then - assert.equal(parser.helloworld("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.helloworld['int']("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); + assert.equal(parser.helloworld("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); + assert.equal(parser.helloworld['int']("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); }); @@ -330,8 +330,8 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); //then - assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test2("0x" + + assert.equal(parser.test("00000000000000000000000000000000000000000000000000000000000001")[0], 1); + assert.equal(parser.test2( "0000000000000000000000000000000000000000000000000000000000000005" + "68656c6c6f000000000000000000000000000000000000000000000000000000")[0], "hello" @@ -351,13 +351,13 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); // then - assert.equal(parser.test("0x" + + assert.equal(parser.test( "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000005" + "0000000000000000000000000000000000000000000000000000000000000006")[0][0], 5 ); - assert.equal(parser.test("0x" + + assert.equal(parser.test( "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000005" + "0000000000000000000000000000000000000000000000000000000000000006")[0][1], @@ -366,7 +366,7 @@ describe('lib/solidity/abi', function() { }); - it('should parse 0x value', function () { + it('should parse 0x0 value', function () { // given var d = clone(description); @@ -378,11 +378,11 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); // then - assert.equal(parser.test("0x")[0], 0); + assert.equal(parser.test("0x0")[0], 0); }); - it('should parse 0x value', function () { + it('should parse 0x0 value', function () { // given var d = clone(description); @@ -394,7 +394,7 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); // then - assert.equal(parser.test("0x")[0], 0); + assert.equal(parser.test("0x0")[0], 0); }); diff --git a/coder.decodeParam.js b/coder.decodeParam.js new file mode 100644 index 000000000..6fbeb8537 --- /dev/null +++ b/coder.decodeParam.js @@ -0,0 +1,20 @@ +var chai = require('chai'); +var assert = chai.assert; +var coder = require('../lib/solidity/coder'); + +var tests = [ + { type: 'int', value: '0000000000000000000000000000000000000000000000000000000000000001', expected: 1}, + { type: 'int', value: '0000000000000000000000000000000000000000000000000000000000000010', expected: 16}, + { type: 'int', value: 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: -1} +]; + +describe('lib/solidity/coder', function () { + describe('decodeParam', function () { + tests.forEach(function (test) { + it('should turn ' + test.value + ' to ' + test.expected, function () { + assert.equal(coder.decodeParam(test.type, test.value), test.expected); + }); + }); + }); +}); + diff --git a/coder.encodeParam.js b/coder.encodeParam.js new file mode 100644 index 000000000..52b0a04d5 --- /dev/null +++ b/coder.encodeParam.js @@ -0,0 +1,20 @@ +var chai = require('chai'); +var assert = chai.assert; +var coder = require('../lib/solidity/coder'); + +var tests = [ + { type: 'int', value: 1, expected: '0000000000000000000000000000000000000000000000000000000000000001'}, + { type: 'int', value: 16, expected: '0000000000000000000000000000000000000000000000000000000000000010'}, + { type: 'int', value: -1, expected: 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'} +]; + +describe('lib/solidity/coder', function () { + describe('encodeParam', function () { + tests.forEach(function (test) { + it('should turn ' + test.value + ' to ' + test.expected, function () { + assert.equal(coder.encodeParam(test.type, test.value), test.expected); + }); + }); + }); +}); + diff --git a/contract.js b/contract.js index fec9fc314..db9840c52 100644 --- a/contract.js +++ b/contract.js @@ -63,11 +63,27 @@ describe('web3.eth.contract', function () { assert.deepEqual(payload.params[0], { topics: [ sha3, - '0x1234567890123456789012345678901234567890' + '0x0000000000000000000000001234567890123456789012345678901234567890', + null ], address: '0x1234567890123456789012345678901234567890' }); - } else if (step === 2 && utils.isArray(payload)) { + } else if (step === 2) { + step = 3; + provider.injectResult([{ + address: address, + topics: [ + sha3, + '0x0000000000000000000000001234567890123456789012345678901234567890', + '0x0000000000000000000000000000000000000000000000000000000000000001' + ], + number: 2, + data: '0x0000000000000000000000000000000000000000000000000000000000000001' + + '0000000000000000000000000000000000000000000000000000000000000008' + }]); + assert.equal(payload.jsonrpc, '2.0'); + assert.equal(payload.method, 'eth_getFilterLogs'); + } else if (step === 3 && utils.isArray(payload)) { provider.injectBatchResults([[{ address: address, topics: [ @@ -89,12 +105,16 @@ describe('web3.eth.contract', function () { var Contract = web3.eth.contract(desc); var contract = new Contract(address); + var res = 0; contract.Changed({from: address}).watch(function(err, result) { assert.equal(result.args.from, address); assert.equal(result.args.amount, 1); assert.equal(result.args.t1, 1); assert.equal(result.args.t2, 8); - done(); + res++; + if (res === 2) { + done(); + } }); }); @@ -187,7 +207,40 @@ describe('web3.eth.contract', function () { var Contract = web3.eth.contract(desc); var contract = new Contract(address); - contract.call({from: address, gas: 50000}).balance(address); + contract.balance(address, {from: address, gas: 50000}); + + }); + + it('should explicitly make a call with optional params', function () { + + var provider = new FakeHttpProvider(); + web3.setProvider(provider); + web3.reset(); + var sha3 = '0x5131231231231231231231'; + var address = '0x1234567890123456789012345678901234567890'; + provider.injectResult(sha3); + var step = 0; + provider.injectValidation(function (payload) { + if (step === 0) { + step = 1; + assert.equal(payload.jsonrpc, '2.0'); + assert.equal(payload.method, 'web3_sha3'); + assert.equal(payload.params[0], web3.fromAscii('balance(address)')); + } else if (step === 1) { + assert.equal(payload.method, 'eth_call'); + assert.deepEqual(payload.params, [{ + data: sha3.slice(0, 10) + '0000000000000000000000001234567890123456789012345678901234567890', + to: address, + from: address, + gas: '0xc350' + }, 'latest']); + } + }); + + var Contract = web3.eth.contract(desc); + var contract = new Contract(address); + + contract.balance.call(address, {from: address, gas: 50000}); }); @@ -223,7 +276,42 @@ describe('web3.eth.contract', function () { var Contract = web3.eth.contract(desc); var contract = new Contract(address); - contract.sendTransaction({from: address, gas: 50000, gasPrice: 3000, value: 10000}).send(address, 17); + contract.send(address, 17, {from: address, gas: 50000, gasPrice: 3000, value: 10000}); + }); + + it('should explicitly sendTransaction with optional params', function () { + var provider = new FakeHttpProvider(); + web3.setProvider(provider); + web3.reset(); + var sha3 = '0x5131231231231231231231'; + var address = '0x1234567890123456789012345678901234567890'; + provider.injectResult(sha3); + var step = 0; + provider.injectValidation(function (payload) { + if (step === 0) { + step = 1; + assert.equal(payload.jsonrpc, '2.0'); + assert.equal(payload.method, 'web3_sha3'); + assert.equal(payload.params[0], web3.fromAscii('send(address,uint256)')); + } else if (step === 1) { + assert.equal(payload.method, 'eth_sendTransaction'); + assert.deepEqual(payload.params, [{ + data: sha3.slice(0, 10) + + '0000000000000000000000001234567890123456789012345678901234567890' + + '0000000000000000000000000000000000000000000000000000000000000011' , + to: address, + from: address, + gas: '0xc350', + gasPrice: '0xbb8', + value: '0x2710' + }]); + } + }); + + var Contract = web3.eth.contract(desc); + var contract = new Contract(address); + + contract.send.sendTransaction(address, 17, {from: address, gas: 50000, gasPrice: 3000, value: 10000}); }); }); }); diff --git a/event.decode.js b/event.decode.js new file mode 100644 index 000000000..971c44010 --- /dev/null +++ b/event.decode.js @@ -0,0 +1,180 @@ +var chai = require('chai'); +var assert = chai.assert; +var BigNumber = require('bignumber.js'); +var SolidityEvent = require('../lib/web3/event'); + +var name = 'event1'; +var address = '0x1234567890123456789012345678901234567890'; + +var tests = [{ + abi: { + name: name, + inputs: [] + }, + data: { + logIndex: '0x1', + transactionIndex: '0x10', + transactionHash: '0x1234567890', + address: address, + blockHash: '0x1234567890', + blockNumber: '0x1' + }, + expected: { + event: name, + args: {}, + logIndex: 1, + transactionIndex: 16, + transactionHash: '0x1234567890', + address: address, + blockHash: '0x1234567890', + blockNumber: 1 + } +}, { + abi: { + name: name, + inputs: [{ + name: 'a', + type: 'int', + indexed: false + }] + }, + data: { + logIndex: '0x1', + transactionIndex: '0x10', + transactionHash: '0x1234567890', + address: address, + blockHash: '0x1234567890', + blockNumber: '0x1', + data: '0x0000000000000000000000000000000000000000000000000000000000000001' + }, + expected: { + event: name, + args: { + a: new BigNumber(1) + }, + logIndex: 1, + transactionIndex: 16, + transactionHash: '0x1234567890', + address: address, + blockHash: '0x1234567890', + blockNumber: 1 + } +}, { + abi: { + name: name, + inputs: [{ + name: 'a', + type: 'int', + indexed: false + }, { + name: 'b', + type: 'int', + indexed: true + }, { + name: 'c', + type: 'int', + indexed: false + }, { + name: 'd', + type: 'int', + indexed: true + }] + }, + data: { + logIndex: '0x1', + transactionIndex: '0x10', + transactionHash: '0x1234567890', + address: address, + blockHash: '0x1234567890', + blockNumber: '0x1', + data: '0x' + + '0000000000000000000000000000000000000000000000000000000000000001' + + '0000000000000000000000000000000000000000000000000000000000000004', + topics: [ + address, + '0x000000000000000000000000000000000000000000000000000000000000000a', + '0x0000000000000000000000000000000000000000000000000000000000000010' + ] + }, + expected: { + event: name, + args: { + a: new BigNumber(1), + b: new BigNumber(10), + c: new BigNumber(4), + d: new BigNumber(16) + }, + logIndex: 1, + transactionIndex: 16, + transactionHash: '0x1234567890', + address: address, + blockHash: '0x1234567890', + blockNumber: 1 + } +}, { + abi: { + name: name, + anonymous: true, + inputs: [{ + name: 'a', + type: 'int', + indexed: false + }, { + name: 'b', + type: 'int', + indexed: true + }, { + name: 'c', + type: 'int', + indexed: false + }, { + name: 'd', + type: 'int', + indexed: true + }] + }, + data: { + logIndex: '0x1', + transactionIndex: '0x10', + transactionHash: '0x1234567890', + address: address, + blockHash: '0x1234567890', + blockNumber: '0x1', + data: '0x' + + '0000000000000000000000000000000000000000000000000000000000000001' + + '0000000000000000000000000000000000000000000000000000000000000004', + topics: [ + '0x000000000000000000000000000000000000000000000000000000000000000a', + '0x0000000000000000000000000000000000000000000000000000000000000010' + ] + }, + expected: { + event: name, + args: { + a: new BigNumber(1), + b: new BigNumber(10), + c: new BigNumber(4), + d: new BigNumber(16) + }, + logIndex: 1, + transactionIndex: 16, + transactionHash: '0x1234567890', + address: address, + blockHash: '0x1234567890', + blockNumber: 1 + } +}]; + +describe('lib/web3/event', function () { + describe('decode', function () { + tests.forEach(function (test, index) { + it('test no: ' + index, function () { + var event = new SolidityEvent(test.abi, address); + + var result = event.decode(test.data); + assert.deepEqual(result, test.expected); + }); + }); + }); +}); + diff --git a/event.encode.js b/event.encode.js new file mode 100644 index 000000000..c28588c2e --- /dev/null +++ b/event.encode.js @@ -0,0 +1,206 @@ +var chai = require('chai'); +var assert = chai.assert; +var SolidityEvent = require('../lib/web3/event'); + +var address = '0x1234567890123456789012345678901234567890'; +var signature = '0xffff'; + +var tests = [{ + abi: { + name: 'event1', + inputs: [] + }, + indexed: {}, + options: {}, + expected: { + address: address, + topics: [ + signature + ] + } +}, { + abi: { + name: 'event1', + inputs: [{ + type: 'int', + name: 'a', + indexed: true + }] + }, + indexed: { + a: 16 + }, + options: {}, + expected: { + address: address, + topics: [ + signature, + '0x0000000000000000000000000000000000000000000000000000000000000010' + ] + } +},{ + abi: { + name: 'event1', + inputs: [{ + type: 'int', + name: 'a', + indexed: true + }, { + type: 'int', + name: 'b', + indexed: true + }, { + type: 'int', + name: 'c', + indexed: false + }, { + type: 'int', + name: 'd', + indexed: true + }] + }, + indexed: { + b: 4 + }, + options: {}, + expected: { + address: address, + topics: [ + signature, // signature + null, // a + '0x0000000000000000000000000000000000000000000000000000000000000004', // b + null // d + ] + } +}, { + abi: { + name: 'event1', + inputs: [{ + type: 'int', + name: 'a', + indexed: true + }, { + type: 'int', + name: 'b', + indexed: true + }] + }, + indexed: { + a: [16, 1], + b: 2 + }, + options: {}, + expected: { + address: address, + topics: [ + signature, + ['0x0000000000000000000000000000000000000000000000000000000000000010', '0x0000000000000000000000000000000000000000000000000000000000000001'], + '0x0000000000000000000000000000000000000000000000000000000000000002' + ] + } +}, { + abi: { + name: 'event1', + inputs: [{ + type: 'int', + name: 'a', + indexed: true + }] + }, + indexed: { + a: null + }, + options: {}, + expected: { + address: address, + topics: [ + signature, + null + ] + } +}, { + abi: { + name: 'event1', + inputs: [{ + type: 'int', + name: 'a', + indexed: true + }] + }, + indexed: { + a: 1 + }, + options: { + fromBlock: 4, + toBlock: 10 + }, + expected: { + address: address, + fromBlock: '0x4', + toBlock: '0xa', + topics: [ + signature, + '0x0000000000000000000000000000000000000000000000000000000000000001' + ] + } +}, { + abi: { + name: 'event1', + inputs: [{ + type: 'int', + name: 'a', + indexed: true + }], + anonymous: true + }, + indexed: { + a: 1 + }, + options: {}, + expected: { + topics: [ + '0x0000000000000000000000000000000000000000000000000000000000000001' + ] + } +}, { + abi: { + name: 'event1', + inputs: [{ + type: 'int', + name: 'a', + indexed: true + }, { + type: 'int', + name: 'b', + indexed: true + }], + anonymous: true + }, + indexed: { + b: 1 + }, + options: {}, + expected: { + topics: [ + null, + '0x0000000000000000000000000000000000000000000000000000000000000001' + ] + } +}]; + +describe('lib/web3/event', function () { + describe('encode', function () { + tests.forEach(function (test, index) { + it('test no: ' + index, function () { + var event = new SolidityEvent(test.abi, address); + event.signature = function () { // inject signature + return signature.slice(2); + }; + + var result = event.encode(test.indexed, test.options); + assert.deepEqual(result, test.expected); + }); + }); + }); +}); + diff --git a/event.inputParser.js b/event.inputParser.js deleted file mode 100644 index 15e0b6d2a..000000000 --- a/event.inputParser.js +++ /dev/null @@ -1,113 +0,0 @@ -var assert = require('assert'); -var event = require('../lib/web3/event.js'); -var f = require('../lib/solidity/formatters.js'); - -describe('lib/web3/event', function () { - describe('inputParser', function () { - it('should create basic filter input object', function () { - - // given - var address = '0x012345'; - var signature = '0x987654'; - var e = { - name: 'Event', - inputs: [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"hash256","indexed":false}] - }; - - // when - var impl = event.inputParser(address, signature, e); - var result = impl(); - - // then - assert.equal(result.address, address); - assert.equal(result.topics.length, 1); - assert.equal(result.topics[0], signature); - - }); - - it('should create filter input object with options', function () { - - // given - var address = '0x012345'; - var signature = '0x987654'; - var options = { - fromBlock: 1, - toBlock: 2, - }; - var e = { - name: 'Event', - inputs: [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"hash256","indexed":false}] - }; - - // when - var impl = event.inputParser(address, signature, e); - var result = impl({}, options); - - // then - assert.equal(result.address, address); - assert.equal(result.topics.length, 1); - assert.equal(result.topics[0], signature); - assert.equal(result.fromBlock, options.fromBlock); - assert.equal(result.toBlock, options.toBlock); - - }); - - it('should create filter input object with indexed params', function () { - - // given - var address = '0x012345'; - var signature = '0x987654'; - var options = { - fromBlock: 1, - toBlock: 2 - }; - var e = { - name: 'Event', - inputs: [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"hash256","indexed":false}] - }; - - // when - var impl = event.inputParser(address, signature, e); - var result = impl({a: 4}, options); - - // then - assert.equal(result.address, address); - assert.equal(result.topics.length, 2); - assert.equal(result.topics[0], signature); - assert.equal(result.topics[1], '0x' + f.formatInputInt(4)); - assert.equal(result.fromBlock, options.fromBlock); - assert.equal(result.toBlock, options.toBlock); - - }); - - it('should create filter input object with an array of indexed params', function () { - - // given - var address = '0x012345'; - var signature = '0x987654'; - var options = { - fromBlock: 1, - toBlock: 2, - }; - var e = { - name: 'Event', - inputs: [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"hash256","indexed":false}] - }; - - // when - var impl = event.inputParser(address, signature, e); - var result = impl({a: [4, 69]}, options); - - // then - assert.equal(result.address, address); - assert.equal(result.topics.length, 2); - assert.equal(result.topics[0], signature); - assert.equal(result.topics[1][0], f.formatInputInt(4)); - assert.equal(result.topics[1][1], f.formatInputInt(69)); - assert.equal(result.fromBlock, options.fromBlock); - assert.equal(result.toBlock, options.toBlock); - - }); - }); -}); - diff --git a/event.outputParser.js b/event.outputParser.js deleted file mode 100644 index d31e49fa8..000000000 --- a/event.outputParser.js +++ /dev/null @@ -1,81 +0,0 @@ -var assert = require('assert'); -var event = require('../lib/web3/event.js'); - -describe('lib/web3/event', function () { - describe('outputParser', function () { - it('should parse basic event output object', function () { - - // given - var output = { - "address":"0x78dfc5983baecf65f73e3de3a96cee24e6b7981e", - "data":"0x000000000000000000000000000000000000000000000000000000000000004b", - "number":2, - "topics":[ - "0x6e61ef44ac2747ff8b84d353a908eb8bd5c3fb118334d57698c5cfc7041196ad", - "0x0000000000000000000000000000000000000000000000000000000000000001" - ] - }; - - var e = { - name: 'Event', - inputs: [{"name":"a","type":"bool","indexed":true},{"name":"b","type":"uint256","indexed":false}] - }; - - // when - var impl = event.outputParser(e); - var result = impl(output); - - // then - assert.equal(result.event, 'Event'); - assert.equal(result.number, 2); - assert.equal(Object.keys(result.args).length, 2); - assert.equal(result.args.a, true); - assert.equal(result.args.b, 75); - }); - - it('should parse event output object arguments in correct order', function () { - - // given - var output = { - "address":"0x78dfc5983baecf65f73e3de3a96cee24e6b7981e", - "data": "0x" + - "000000000000000000000000000000000000000000000000000000000000004b" + - "000000000000000000000000000000000000000000000000000000000000004c" + - "0000000000000000000000000000000000000000000000000000000000000001", - "number":3, - "topics":[ - "0x6e61ef44ac2747ff8b84d353a908eb8bd5c3fb118334d57698c5cfc7041196ad", - "0x0000000000000000000000000000000000000000000000000000000000000001", - "0x0000000000000000000000000000000000000000000000000000000000000005" - ] - }; - - var e = { - name: 'Event2', - inputs: [ - {"name":"a","type":"bool","indexed":true}, - {"name":"b","type":"int","indexed":false}, - {"name":"c","type":"int","indexed":false}, - {"name":"d","type":"int","indexed":true}, - {"name":"e","type":"bool","indexed":false} - ] - }; - - // when - var impl = event.outputParser(e); - var result = impl(output); - - // then - assert.equal(result.event, 'Event2'); - assert.equal(result.number, 3); - assert.equal(Object.keys(result.args).length, 5); - assert.equal(result.args.a, true); - assert.equal(result.args.b, 75); - assert.equal(result.args.c, 76); - assert.equal(result.args.d, 5); - assert.equal(result.args.e, true); - - }); - }); -}); - diff --git a/formatters.inputPostFormatter.js b/formatters.inputPostFormatter.js index 7f0ce5298..705a93bc5 100644 --- a/formatters.inputPostFormatter.js +++ b/formatters.inputPostFormatter.js @@ -20,7 +20,8 @@ describe('formatters', function () { payload: '0x7b2274657374223a2274657374227d', ttl: '0xc8', priority: '0x3e8', - topics: ['0x68656c6c6f','0x6d79746f70696373'] + topics: ['0x68656c6c6f','0x6d79746f70696373'], + workToProve: '0x0' }); }); diff --git a/formatters.outputBlockFormatter.js b/formatters.outputBlockFormatter.js index f31cced99..272250651 100644 --- a/formatters.outputBlockFormatter.js +++ b/formatters.outputBlockFormatter.js @@ -1,4 +1,5 @@ -var assert = require('assert'); +var chai = require('chai'); +var assert = chai.assert; var formatters = require('../lib/web3/formatters.js'); var BigNumber = require('bignumber.js'); @@ -16,7 +17,6 @@ describe('formatters', function () { difficulty: '0x3e8', totalDifficulty: '0x3e8', number: '0x3e8', - minGasPrice: '0x3e8', gasLimit: '0x3e8', gasUsed: '0x3e8', timestamp: '0x3e8', @@ -34,7 +34,6 @@ describe('formatters', function () { difficulty: new BigNumber(1000), totalDifficulty: new BigNumber(1000), number: 1000, - minGasPrice: new BigNumber(1000), gasLimit: 1000, gasUsed: 1000, timestamp: 1000, diff --git a/formatters.outputTransactionFormatter.js b/formatters.outputTransactionFormatter.js index b1eaff52d..ef19b6da7 100644 --- a/formatters.outputTransactionFormatter.js +++ b/formatters.outputTransactionFormatter.js @@ -13,6 +13,7 @@ describe('formatters', function () { value: '0x3e8', gas: '0x3e8', gasPrice: '0x3e8', + nonce: '0xb', transactionIndex: '0x1', blockNumber: '0x3e8', blockHash: '0x34234bf23bf4234' @@ -23,6 +24,7 @@ describe('formatters', function () { value: new BigNumber(1000), gas: 1000, gasPrice: new BigNumber(1000), + nonce: 11, blockNumber: 1000, blockHash: '0x34234bf23bf4234', transactionIndex: 1 diff --git a/helpers/test.method.js b/helpers/test.method.js index 8de318d8c..70068c0f5 100644 --- a/helpers/test.method.js +++ b/helpers/test.method.js @@ -2,6 +2,7 @@ var chai = require('chai'); var assert = chai.assert; var web3 = require('../../index'); var FakeHttpProvider = require('./FakeHttpProvider'); +var clone = function (object) { return JSON.parse(JSON.stringify(object)); }; var runTests = function (obj, method, tests) { @@ -22,10 +23,18 @@ var runTests = function (obj, method, tests) { assert.deepEqual(payload.params, test.formattedArgs); }); + var args = clone(test.args) + // when - var result = (obj) - ? web3[obj][method].apply(null, test.args.slice(0)) - : web3[method].apply(null, test.args.slice(0)); + if (obj) { + var result = web3[obj][method].apply(null, args); + } else { + var result = web3[method].apply(null, args); + } + // when + //var result = (obj) + //? web3[obj][method].apply(null, test.args.slice(0)) + //: web3[method].apply(null, test.args.slice(0)); // then assert.deepEqual(test.formattedResult, result); @@ -43,7 +52,8 @@ var runTests = function (obj, method, tests) { assert.deepEqual(payload.params, test.formattedArgs); }); - var args = test.args.slice(0); + var args = clone(test.args); + // add callback args.push(function (err, result) { assert.deepEqual(test.formattedResult, result); @@ -51,10 +61,11 @@ var runTests = function (obj, method, tests) { }); // when - if(obj) + if (obj) { web3[obj][method].apply(null, args); - else + } else { web3[method].apply(null, args); + } }); }); }); diff --git a/method.validateArgs.js b/method.validateArgs.js index 5cb16e1e0..cd4882cee 100644 --- a/method.validateArgs.js +++ b/method.validateArgs.js @@ -39,8 +39,8 @@ describe('lib/web3/method', function () { var test2 = function () { method.validateArgs(args2); }; // then - assert.throws(test, errors.InvalidNumberOfParams); - assert.throws(test2, errors.InvalidNumberOfParams); + assert.throws(test, errors.InvalidNumberOfParams().message); + assert.throws(test2, errors.InvalidNumberOfParams().message); }); }); }); diff --git a/signature.js b/signature.js deleted file mode 100644 index 709f662fd..000000000 --- a/signature.js +++ /dev/null @@ -1,48 +0,0 @@ -var chai = require('chai'); -var assert = chai.assert; -var utils = require('../lib/utils/utils'); -var FakeHttpProvider = require('./helpers/FakeHttpProvider'); -var signature = require('../lib/web3/signature'); -var web3 = require('../index'); - -var tests = [{ - method: 'functionSignatureFromAscii', - call: 'web3_sha3', - request: 'multiply', - formattedRequest: utils.fromAscii('multiply'), - result: '0x255d31552d29a21e93334e96055c6dca7cd329f5420ae74ec166d0c47f9f9843', - formattedResult: '0x255d3155' -},{ - method: 'eventSignatureFromAscii', - call: 'web3_sha3', - request: 'multiply', - formattedRequest: utils.fromAscii('multiply'), - result: '0x255d31552d29a21e93334e96055c6dca7cd329f5420ae74ec166d0c47f9f9843', - formattedResult: '0x255d31552d29a21e93334e96055c6dca7cd329f5420ae74ec166d0c47f9f9843' -}]; - -describe('lib/web3/signature', function () { - tests.forEach(function (test, index) { - describe(test.method, function () { - it('should properly format and return signature of solidity functioni ' + index, function () { - - // given - var provider = new FakeHttpProvider(); - web3.setProvider(provider); - provider.injectResult(test.result); - provider.injectValidation(function (payload) { - assert.equal(payload.method, test.call); - assert.equal(payload.jsonrpc, '2.0'); - assert.equal(payload.params[0], test.formattedRequest); - }); - - // when - var result = signature[test.method].call(null, test.request); - - // then - assert.equal(result, test.formattedResult); - }); - }); - }); -}); - diff --git a/utils.filters.js b/utils.filters.js deleted file mode 100644 index 5f37b6f1a..000000000 --- a/utils.filters.js +++ /dev/null @@ -1,49 +0,0 @@ -var assert = require('assert'); -var utils = require('../lib/solidity/utils'); - -describe('lib/utils/utils', function() { - it('should filter functions and events from input array properly', function () { - - // given - var description = [{ - "name": "test", - "type": "function", - "inputs": [{ - "name": "a", - "type": "uint256" - } - ], - "outputs": [ - { - "name": "d", - "type": "uint256" - } - ], - }, { - "name": "test2", - "type": "event", - "inputs": [{ - "name": "a", - "type": "uint256" - } - ], - "outputs": [ - { - "name": "d", - "type": "uint256" - } - ] - }]; - - // when - var events = utils.filterEvents(description); - var functions = utils.filterFunctions(description); - - // then - assert.equal(events.length, 1); - assert.equal(events[0].name, 'test2'); - assert.equal(functions.length, 1); - assert.equal(functions[0].name, 'test'); - - }); -}); diff --git a/web3.eth.contract.js b/web3.eth.contract.js index a657545db..651810b69 100644 --- a/web3.eth.contract.js +++ b/web3.eth.contract.js @@ -234,7 +234,7 @@ describe('web3.eth.contract', function() { }); var Con = contract(description); - var myCon = new Con(code, 2); + var myCon = new Con({data: code}, 2); }); }); diff --git a/web3.eth.getBlock.js b/web3.eth.getBlock.js index 539e433a6..48926e89c 100644 --- a/web3.eth.getBlock.js +++ b/web3.eth.getBlock.js @@ -19,7 +19,6 @@ var blockResult = { "size": "0x027f07", "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", "gasLimit": "0x9f759", - "minGasPrice": "0x9f759", "gasUsed": "0x9f759", "timestamp": "0x54e34e8e", "transactions": ['0x460cfb8472af2c5fd05b5a2','0x460cfb8472af2c5fd05b5a2'], @@ -40,7 +39,6 @@ var formattedBlockResult = { "size": 163591, "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", "gasLimit": 653145, - "minGasPrice": new BigNumber(653145), "gasUsed": 653145, "timestamp": 1424182926, "transactions": ['0x460cfb8472af2c5fd05b5a2','0x460cfb8472af2c5fd05b5a2'], @@ -61,13 +59,12 @@ var blockResultWithTx = { "size": "0x027f07", "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", "gasLimit": "0x9f759", - "minGasPrice": "0x9f759", "gasUsed": "0x9f759", "timestamp": "0x54e34e8e", "transactions": [{ "status": "mined", "hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", - "nonce":"0x", + "nonce":"0x2", "blockHash": "0x6fd9e2a26ab", "blockNumber": "0x15df", "transactionIndex": "0x1", @@ -95,13 +92,12 @@ var formattedBlockResultWithTx = { "size": 163591, "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", "gasLimit": 653145, - "minGasPrice": new BigNumber(653145), "gasUsed": 653145, "timestamp": 1424182926, "transactions": [{ "status": "mined", "hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", - "nonce":"0x", + "nonce": 2, "blockHash": "0x6fd9e2a26ab", "blockNumber": 5599, "transactionIndex": 1, diff --git a/web3.eth.getTransaction.js b/web3.eth.getTransaction.js index fb833edf3..b9ef034af 100644 --- a/web3.eth.getTransaction.js +++ b/web3.eth.getTransaction.js @@ -8,7 +8,7 @@ var method = 'getTransaction'; var txResult = { "status": "mined", "hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", - "nonce":"0x", + "nonce":"0x5", "blockHash": "0x6fd9e2a26ab", "blockNumber": "0x15df", "transactionIndex": "0x1", @@ -22,7 +22,7 @@ var txResult = { var formattedTxResult = { "status": "mined", "hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", - "nonce":"0x", + "nonce":5, "blockHash": "0x6fd9e2a26ab", "blockNumber": 5599, "transactionIndex": 1, diff --git a/web3.eth.getTransactionFromBlock.js b/web3.eth.getTransactionFromBlock.js index 7b59a3ba1..9f59a606c 100644 --- a/web3.eth.getTransactionFromBlock.js +++ b/web3.eth.getTransactionFromBlock.js @@ -8,7 +8,7 @@ var method = 'getTransactionFromBlock'; var txResult = { "status": "mined", "hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", - "nonce":"0x", + "nonce":"0xb", "blockHash": "0x6fd9e2a26ab", "blockNumber": "0x15df", "transactionIndex": "0x1", @@ -22,7 +22,7 @@ var txResult = { var formattedTxResult = { "status": "mined", "hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", - "nonce":"0x", + "nonce":11, "blockHash": "0x6fd9e2a26ab", "blockNumber": 5599, "transactionIndex": 1, diff --git a/web3.eth.getUncle.js b/web3.eth.getUncle.js index c5d723dc9..4c5473c0c 100644 --- a/web3.eth.getUncle.js +++ b/web3.eth.getUncle.js @@ -20,7 +20,6 @@ var blockResult = { "size": "0x027f07", "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", "gasLimit": "0x9f759", - "minGasPrice": "0x9f759", "gasUsed": "0x9f759", "timestamp": "0x54e34e8e", "transactions": ['0x460cfb8472af2c5fd05b5a2','0x460cfb8472af2c5fd05b5a2'], @@ -41,7 +40,6 @@ var formattedBlockResult = { "size": 163591, "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", "gasLimit": 653145, - "minGasPrice": new BigNumber(653145), "gasUsed": 653145, "timestamp": 1424182926, "transactions": ['0x460cfb8472af2c5fd05b5a2','0x460cfb8472af2c5fd05b5a2'], @@ -62,13 +60,12 @@ var blockResultWithTx = { "size": "0x027f07", "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", "gasLimit": "0x9f759", - "minGasPrice": "0x9f759", "gasUsed": "0x9f759", "timestamp": "0x54e34e8e", "transactions": [{ "status": "mined", "hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", - "nonce":"0x", + "nonce":"0x2", "blockHash": "0x6fd9e2a26ab", "blockNumber": "0x15df", "transactionIndex": "0x1", @@ -96,13 +93,12 @@ var formattedBlockResultWithTx = { "size": 163591, "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", "gasLimit": 653145, - "minGasPrice": new BigNumber(653145), "gasUsed": 653145, "timestamp": 1424182926, "transactions": [{ "status": "mined", "hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", - "nonce":"0x", + "nonce": 2, "blockHash": "0x6fd9e2a26ab", "blockNumber": 5599, "transactionIndex": 1, diff --git a/shh.filter.js b/web3.shh.filter.js similarity index 53% rename from shh.filter.js rename to web3.shh.filter.js index 57df4d0c5..05ec35a6a 100644 --- a/shh.filter.js +++ b/web3.shh.filter.js @@ -17,6 +17,45 @@ var tests = [{ result: '0xf', formattedResult: '0xf', call: 'shh_newFilter' +}, +{ + args: [{ + to: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', + topics: ['0x324f5435', ['0x564b4566f3453', '0x345345343453']] + }], + formattedArgs: [{ + to: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', + topics: ['0x324f5435', ['0x564b4566f3453', '0x345345343453']] + }], + result: '0xf', + formattedResult: '0xf', + call: 'shh_newFilter' +}, +{ + args: [{ + to: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', + topics: ['0x324f5435', null, ['0x564b4566f3453', '0x345345343453']] + }], + formattedArgs: [{ + to: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', + topics: ['0x324f5435', null, ['0x564b4566f3453', '0x345345343453']] + }], + result: '0xf', + formattedResult: '0xf', + call: 'shh_newFilter' +}, +{ + args: [{ + to: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', + topics: ['myString', 11, '23', null] + }], + formattedArgs: [{ + to: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', + topics: ['0x6d79537472696e67', '0x3131', '0x3233', null] + }], + result: '0xf', + formattedResult: '0xf', + call: 'shh_newFilter' }]; describe('shh', function () { diff --git a/web3.shh.post.js b/web3.shh.post.js new file mode 100644 index 000000000..89862b645 --- /dev/null +++ b/web3.shh.post.js @@ -0,0 +1,49 @@ +var chai = require('chai'); +var web3 = require('../index'); +var testMethod = require('./helpers/test.method.js'); + +var method = 'post'; + +var tests = [{ + args: [{ + from: '0x123123123', + topics: ['hello_world'], + payload: '12345', + ttl: 100, + workToProve: 101 + }], + formattedArgs: [{ + from: '0x123123123', + topics: [web3.fromAscii('hello_world')], + payload: web3.toHex('12345'), + ttl: web3.toHex('100'), + workToProve: web3.toHex('101'), + priority: '0x0' + }], + result: true, + formattedResult: true, + call: 'shh_'+ method +}, { + args: [{ + from: '0x21312', + topics: ['hello_world'], + payload: '0x12345', + ttl: 0x100, + workToProve: 0x101, + priority: 0x15 + }], + formattedArgs: [{ + from: '0x21312', + topics: [web3.fromAscii('hello_world')], + payload: '0x12345', + ttl: '0x100', + workToProve: '0x101', + priority: '0x15' + }], + result: true, + formattedResult: true, + call: 'shh_'+ method +}]; + +testMethod.runTests('shh', method, tests); +