From 78bdf99674c079ceaf8741eb1ec11117fed7d6f0 Mon Sep 17 00:00:00 2001 From: littleskunk Date: Mon, 23 Oct 2017 09:57:05 +0200 Subject: [PATCH 1/3] Wiki fix syntax errors in code examples (#1133) --- docs/web3-eth.rst | 14 +++++++------- docs/web3-shh.rst | 28 ++++++++++++++-------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/docs/web3-eth.rst b/docs/web3-eth.rst index f6219fc8e6f..676be05de26 100644 --- a/docs/web3-eth.rst +++ b/docs/web3-eth.rst @@ -633,7 +633,7 @@ Example .. code-block:: javascript - web3.eth.getBlock(3150); + web3.eth.getBlock(3150) .then(console.log); > { @@ -1401,7 +1401,7 @@ Example .. code-block:: javascript - web3.eth.getCompilers(); + web3.eth.getCompilers() .then(console.log); > ["lll", "solidity", "serpent"] @@ -1444,7 +1444,7 @@ Example " }\n" + "}\n"; - web3.eth.compile.solidity(source); + web3.eth.compile.solidity(source) .then(console.log); > { @@ -1521,7 +1521,7 @@ Example var source = "..."; - web3.eth.compile.lll(source); + web3.eth.compile.lll(source) .then(console.log); > "0x603880600c6000396000f3006001600060e060020a600035048063c6888fa114601857005b6021600435602b565b8060005260206000f35b600081600702905091905056" @@ -1556,7 +1556,7 @@ Returns var source = "..."; - var code = web3.eth.compile.serpent(source); + var code = web3.eth.compile.serpent(source) .then(console.log); > "0x603880600c6000396000f3006001600060e060020a600035048063c6888fa114601857005b6021600435602b565b8060005260206000f35b600081600702905091905056" @@ -1596,7 +1596,7 @@ Example .. code-block:: javascript - web3.eth.getWork(); + web3.eth.getWork() .then(console.log); > [ "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef", @@ -1642,7 +1642,7 @@ Example "0x0000000000000001", "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef", "0xD1FE5700000000000000000000000000D1FE5700000000000000000000000000" - ]); + ]) .then(console.log); > true diff --git a/docs/web3-shh.rst b/docs/web3-shh.rst index 0f63b14bce9..9984d1356f8 100644 --- a/docs/web3-shh.rst +++ b/docs/web3-shh.rst @@ -206,7 +206,7 @@ Example .. code-block:: javascript - web3.shh.setMinPoW(0.9); + web3.shh.setMinPoW(0.9) .then(console.log); > true @@ -247,7 +247,7 @@ Example .. code-block:: javascript - web3.shh.markTrustedPeer(); + web3.shh.markTrustedPeer() .then(console.log); > true @@ -285,7 +285,7 @@ Example .. code-block:: javascript - web3.shh.newKeyPair(); + web3.shh.newKeyPair() .then(console.log); > "5e57b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f" @@ -324,7 +324,7 @@ Example .. code-block:: javascript - web3.shh.addPrivateKey('0x8bda3abeb454847b515fa9b404cede50b1cc63cfdeddd4999d074284b4c21e15'); + web3.shh.addPrivateKey('0x8bda3abeb454847b515fa9b404cede50b1cc63cfdeddd4999d074284b4c21e15') .then(console.log); > "3e22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f" @@ -363,7 +363,7 @@ Example .. code-block:: javascript - web3.shh.deleteKeyPair('3e22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f'); + web3.shh.deleteKeyPair('3e22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f') .then(console.log); > true @@ -402,7 +402,7 @@ Example .. code-block:: javascript - web3.shh.hasKeyPair('fe22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f'); + web3.shh.hasKeyPair('fe22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f') .then(console.log); > true @@ -441,7 +441,7 @@ Example .. code-block:: javascript - web3.shh.getPublicKey('3e22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f'); + web3.shh.getPublicKey('3e22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f') .then(console.log); > "0x04d1574d4eab8f3dde4d2dc7ed2c4d699d77cbbdd09167b8fffa099652ce4df00c4c6e0263eafe05007a46fdf0c8d32b11aeabcd3abbc7b2bc2bb967368a68e9c6" @@ -480,7 +480,7 @@ Example .. code-block:: javascript - web3.shh.getPrivateKey('3e22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f'); + web3.shh.getPrivateKey('3e22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f') .then(console.log); > "0x234234e22b9ffc2387e18636e0534534a3d0c56b0243567432453264c16e78a2adc" @@ -519,7 +519,7 @@ Example .. code-block:: javascript - web3.shh.newSymKey(); + web3.shh.newSymKey() .then(console.log); > "cec94d139ff51d7df1d228812b90c23ec1f909afa0840ed80f1e04030bb681e4" @@ -558,7 +558,7 @@ Example .. code-block:: javascript - web3.shh.addSymKey('0x5e11b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f'); + web3.shh.addSymKey('0x5e11b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f') .then(console.log); > "fea94d139ff51d7df1d228812b90c23ec1f909afa0840ed80f1e04030bb681e4" @@ -597,7 +597,7 @@ Example .. code-block:: javascript - web3.shh.generateSymKeyFromPassword('Never use this password - password!'); + web3.shh.generateSymKeyFromPassword('Never use this password - password!') .then(console.log); > "2e57b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f" @@ -636,7 +636,7 @@ Example .. code-block:: javascript - web3.shh.hasSymKey('f6dcf21ed6a17bd78d8c4c63195ab997b3b65ea683705501eae82d32667adc92'); + web3.shh.hasSymKey('f6dcf21ed6a17bd78d8c4c63195ab997b3b65ea683705501eae82d32667adc92') .then(console.log); > true @@ -675,7 +675,7 @@ Example .. code-block:: javascript - web3.shh.getSymKey('af33b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f'); + web3.shh.getSymKey('af33b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f') .then(console.log); > "0xa82a520aff70f7a989098376e48ec128f25f767085e84d7fb995a9815eebff0a" @@ -714,7 +714,7 @@ Example .. code-block:: javascript - web3.shh.deleteSymKey('bf31b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f'); + web3.shh.deleteSymKey('bf31b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f') .then(console.log); > true From 006b394cf89f2301218ca7b0bcdbdd669bcf7a02 Mon Sep 17 00:00:00 2001 From: Nick Addison Date: Tue, 24 Oct 2017 08:58:43 +0000 Subject: [PATCH 2/3] Fixes to TypeScript definitions (#1131) * removed privateKey from web3.eth.signTransaction and web3.eth.accounts.signTransaction documentation * removed privateKey from web3.eth.signTransaction and web3.eth.accounts.signTransaction documentation * added vscode to gitignore and minor doco change * Added test to show privateKey can not be passed to accounts.signTransaction * removed passing of private key * Added Eth.signTransaction function renamed accounts.privateToAccount to accounts.privateKeyToAccount Added missing Contract.options Added status to TransactionReceipt * reversing changes so my forked 1.0 branch is in sync with the upstream 1.0 branch --- .gitignore | 1 + packages/web3/index.d.ts | 2 +- packages/web3/types.d.ts | 23 ++++++++++++++++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 7ab4350d86a..2dfb2150de0 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ bower_components /bower .idea/ .npm/ +.vscode/ \ No newline at end of file diff --git a/packages/web3/index.d.ts b/packages/web3/index.d.ts index e0799833411..c8e825c62b0 100644 --- a/packages/web3/index.d.ts +++ b/packages/web3/index.d.ts @@ -10,7 +10,7 @@ declare class Web3 { Shh: new (provider: t.Provider) => t.Shh Bzz: new (provider: t.Provider) => t.Bzz } - constructor(provider: t.Provider) + constructor(provider: t.Provider | string) version: string BatchRequest: new () => t.BatchRequest extend(methods: any): any // TODO diff --git a/packages/web3/types.d.ts b/packages/web3/types.d.ts index 1e71cfeedae..a11dc79ade5 100644 --- a/packages/web3/types.d.ts +++ b/packages/web3/types.d.ts @@ -112,6 +112,22 @@ export declare interface TransactionReceipt { logs?: Array events?: { [eventName: string]: EventLog + }, + status: string +} +export declare interface EncodedTransaction { + raw: string, + tx: { + nonce: string, + gasPrice: string, + gas: string, + to: string, + value: string, + input: string, + v: string, + r: string, + s: string, + hash: string } } export declare interface BlockHeader { @@ -265,6 +281,10 @@ export declare interface Contract { options: { address: string jsonInterface: ABIDefinition[] + data: string + from: string + gasPrice: string + gas: number } methods: { [fnName: string]: (...args) => TransactionObject @@ -313,7 +333,7 @@ export declare class Eth { } accounts: { 'new'(entropy?: string): Account - privateToAccount(privKey: string): Account + privateKeyToAccount(privKey: string): Account publicToAddress(key: string): string signTransaction(tx: Tx, privateKey: string, returnSignature?: boolean, cb?: (err: Error, result: string | Signature) => void): Promise | Signature recoverTransaction(signature: string | Signature): string @@ -376,6 +396,7 @@ export declare class Eth { isSyncing(cb?: Callback): Promise net: Net personal: Personal + signTransaction(tx: Tx, address?: string, cb?: Callback): Promise sendSignedTransaction(data: string, cb?: Callback): PromiEvent sendTransaction(tx: Tx, cb?: Callback): PromiEvent submitWork(nonce: string, powHash: string, digest: string, cb?: Callback): Promise From f6400610f194c0b5088ef1a6b23d8a83b87f875a Mon Sep 17 00:00:00 2001 From: "David A. Carley" Date: Tue, 24 Oct 2017 02:01:31 -0700 Subject: [PATCH 3/3] Fix for Bug #1123 (#1135) * Fix for Bug #1123 * Trigger travis * Removed a bogus test for `bytes64` --- packages/web3-eth-abi/src/formatters.js | 4 + test/abi.encodeParameter.js | 4 - test/contract.encodeABI.js | 108 ++++++++++++++++++++++++ 3 files changed, 112 insertions(+), 4 deletions(-) create mode 100644 test/contract.encodeABI.js diff --git a/packages/web3-eth-abi/src/formatters.js b/packages/web3-eth-abi/src/formatters.js index 2f52726ba41..08baac7e9f5 100644 --- a/packages/web3-eth-abi/src/formatters.js +++ b/packages/web3-eth-abi/src/formatters.js @@ -62,6 +62,10 @@ var formatInputBytes = function (value) { throw new Error('Given parameter bytes has an invalid length: "'+ value + '"'); } + if (result.length > 64) { + throw new Error('Given parameter bytes is too long: "' + value + '"'); + } + var l = Math.floor((result.length + 63) / 64); result = utils.padRight(result, l * 64); return new SolidityParam(result); diff --git a/test/abi.encodeParameter.js b/test/abi.encodeParameter.js index 12690b88ad5..8476643afdf 100644 --- a/test/abi.encodeParameter.js +++ b/test/abi.encodeParameter.js @@ -133,10 +133,6 @@ describe('lib/solidity/coder', function () { 'c3a40000c3a40000000000000000000000000000000000000000000000000000'}); test({ type: 'bytes32', value: '0xc3a40000c3a4', expected: 'c3a40000c3a40000000000000000000000000000000000000000000000000000'}); - test({ type: 'bytes64', value: '0xc3a40000c3a40000000000000000000000000000000000000000000000000000' + - 'c3a40000c3a40000000000000000000000000000000000000000000000000000', - expected: 'c3a40000c3a40000000000000000000000000000000000000000000000000000' + - 'c3a40000c3a40000000000000000000000000000000000000000000000000000'}); test({ type: 'string', value: 'ää', expected: '0000000000000000000000000000000000000000000000000000000000000020' + '0000000000000000000000000000000000000000000000000000000000000008' + diff --git a/test/contract.encodeABI.js b/test/contract.encodeABI.js new file mode 100644 index 00000000000..20e7bcfa781 --- /dev/null +++ b/test/contract.encodeABI.js @@ -0,0 +1,108 @@ +var chai = require('chai'); +var assert = chai.assert; +var Eth = require('../packages/web3-eth'); +var sha3 = require('../packages/web3-utils').sha3; +var FakeIpcProvider = require('./helpers/FakeIpcProvider'); +var FakeHttpProvider = require('./helpers/FakeHttpProvider'); +var Promise = require('bluebird'); + +var abi = [ + { + constant: true, + inputs: [ + { + name: "a", + type: "bytes32" + }, + { + name: "b", + type: "bytes32" + } + ], + name: "takesTwoBytes32", + outputs: [ + { + name: "", + type: "bytes32" + } + ], + payable: false, + type: "function", + stateMutability: "view" + } +]; + +describe('contract', function () { + describe('method.encodeABI', function () { + it('should handle bytes32 arrays that only contain 1 byte', function () { + var provider = new FakeIpcProvider(); + var eth = new Eth(provider); + + var contract = new eth.Contract(abi); + + var result = contract.methods.takesTwoBytes32('0x'.concat('a'.repeat(2)), '0x'.concat('b'.repeat(2))).encodeABI(); + + assert.equal(result, [ + '0x1323517e', + 'aa00000000000000000000000000000000000000000000000000000000000000', + 'bb00000000000000000000000000000000000000000000000000000000000000' + ].join('')); + }); + + it('should handle bytes32 arrays that are short 1 byte', function () { + var provider = new FakeIpcProvider(); + var eth = new Eth(provider); + + var contract = new eth.Contract(abi); + + var result = contract.methods.takesTwoBytes32('0x'.concat('a'.repeat(62)), '0x'.concat('b'.repeat(62))).encodeABI(); + + assert.equal(result, [ + '0x1323517e', + 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa00', + 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb00' + ].join('')); + }); + + it('should throw an exception on bytes32 arrays that have an invalid length', function () { + var provider = new FakeIpcProvider(); + var eth = new Eth(provider); + + var contract = new eth.Contract(abi); + + var test = function () { + contract.methods.takesTwoBytes32('0x'.concat('a'.repeat(63)), '0x'.concat('b'.repeat(63))).encodeABI(); + } + + assert.throws(test, 'Given parameter bytes has an invalid length: "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"'); + }); + + it('should handle bytes32 arrays that are full', function () { + var provider = new FakeIpcProvider(); + var eth = new Eth(provider); + + var contract = new eth.Contract(abi); + + var result = contract.methods.takesTwoBytes32('0x'.concat('a'.repeat(64)), '0x'.concat('b'.repeat(64))).encodeABI(); + + assert.equal(result, [ + '0x1323517e', + 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' + ].join('')); + }); + + it('should throw an exception on bytes32 arrays that are too long', function () { + var provider = new FakeIpcProvider(); + var eth = new Eth(provider); + + var contract = new eth.Contract(abi); + + var test = function() { + contract.methods.takesTwoBytes32('0x'.concat('a'.repeat(66)), '0x'.concat('b'.repeat(66))).encodeABI(); + } + + assert.throws(test, 'Given parameter bytes is too long: "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"'); + }); + }); +});