Skip to content

Commit

Permalink
Merge branch '1.0' of github.com:ethereum/web3.js into 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
frozeman committed Oct 24, 2017
2 parents 10a80ff + f640061 commit edd801b
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ bower_components
/bower
.idea/
.npm/
.vscode/
14 changes: 7 additions & 7 deletions docs/web3-eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ Example

.. code-block:: javascript
web3.eth.getBlock(3150);
web3.eth.getBlock(3150)
.then(console.log);
> {
Expand Down Expand Up @@ -1401,7 +1401,7 @@ Example

.. code-block:: javascript
web3.eth.getCompilers();
web3.eth.getCompilers()
.then(console.log);
> ["lll", "solidity", "serpent"]
Expand Down Expand Up @@ -1444,7 +1444,7 @@ Example
" }\n" +
"}\n";
web3.eth.compile.solidity(source);
web3.eth.compile.solidity(source)
.then(console.log);
> {
Expand Down Expand Up @@ -1521,7 +1521,7 @@ Example
var source = "...";
web3.eth.compile.lll(source);
web3.eth.compile.lll(source)
.then(console.log);
> "0x603880600c6000396000f3006001600060e060020a600035048063c6888fa114601857005b6021600435602b565b8060005260206000f35b600081600702905091905056"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -1596,7 +1596,7 @@ Example

.. code-block:: javascript
web3.eth.getWork();
web3.eth.getWork()
.then(console.log);
> [
"0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
Expand Down Expand Up @@ -1642,7 +1642,7 @@ Example
"0x0000000000000001",
"0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
"0xD1FE5700000000000000000000000000D1FE5700000000000000000000000000"
]);
])
.then(console.log);
> true
Expand Down
28 changes: 14 additions & 14 deletions docs/web3-shh.rst
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ Example

.. code-block:: javascript
web3.shh.setMinPoW(0.9);
web3.shh.setMinPoW(0.9)
.then(console.log);
> true
Expand Down Expand Up @@ -247,7 +247,7 @@ Example

.. code-block:: javascript
web3.shh.markTrustedPeer();
web3.shh.markTrustedPeer()
.then(console.log);
> true
Expand Down Expand Up @@ -285,7 +285,7 @@ Example

.. code-block:: javascript
web3.shh.newKeyPair();
web3.shh.newKeyPair()
.then(console.log);
> "5e57b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f"
Expand Down Expand Up @@ -324,7 +324,7 @@ Example

.. code-block:: javascript
web3.shh.addPrivateKey('0x8bda3abeb454847b515fa9b404cede50b1cc63cfdeddd4999d074284b4c21e15');
web3.shh.addPrivateKey('0x8bda3abeb454847b515fa9b404cede50b1cc63cfdeddd4999d074284b4c21e15')
.then(console.log);
> "3e22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f"
Expand Down Expand Up @@ -363,7 +363,7 @@ Example

.. code-block:: javascript
web3.shh.deleteKeyPair('3e22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f');
web3.shh.deleteKeyPair('3e22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f')
.then(console.log);
> true
Expand Down Expand Up @@ -402,7 +402,7 @@ Example

.. code-block:: javascript
web3.shh.hasKeyPair('fe22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f');
web3.shh.hasKeyPair('fe22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f')
.then(console.log);
> true
Expand Down Expand Up @@ -441,7 +441,7 @@ Example

.. code-block:: javascript
web3.shh.getPublicKey('3e22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f');
web3.shh.getPublicKey('3e22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f')
.then(console.log);
> "0x04d1574d4eab8f3dde4d2dc7ed2c4d699d77cbbdd09167b8fffa099652ce4df00c4c6e0263eafe05007a46fdf0c8d32b11aeabcd3abbc7b2bc2bb967368a68e9c6"
Expand Down Expand Up @@ -480,7 +480,7 @@ Example

.. code-block:: javascript
web3.shh.getPrivateKey('3e22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f');
web3.shh.getPrivateKey('3e22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f')
.then(console.log);
> "0x234234e22b9ffc2387e18636e0534534a3d0c56b0243567432453264c16e78a2adc"
Expand Down Expand Up @@ -519,7 +519,7 @@ Example

.. code-block:: javascript
web3.shh.newSymKey();
web3.shh.newSymKey()
.then(console.log);
> "cec94d139ff51d7df1d228812b90c23ec1f909afa0840ed80f1e04030bb681e4"
Expand Down Expand Up @@ -558,7 +558,7 @@ Example

.. code-block:: javascript
web3.shh.addSymKey('0x5e11b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f');
web3.shh.addSymKey('0x5e11b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f')
.then(console.log);
> "fea94d139ff51d7df1d228812b90c23ec1f909afa0840ed80f1e04030bb681e4"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -636,7 +636,7 @@ Example

.. code-block:: javascript
web3.shh.hasSymKey('f6dcf21ed6a17bd78d8c4c63195ab997b3b65ea683705501eae82d32667adc92');
web3.shh.hasSymKey('f6dcf21ed6a17bd78d8c4c63195ab997b3b65ea683705501eae82d32667adc92')
.then(console.log);
> true
Expand Down Expand Up @@ -675,7 +675,7 @@ Example

.. code-block:: javascript
web3.shh.getSymKey('af33b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f');
web3.shh.getSymKey('af33b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f')
.then(console.log);
> "0xa82a520aff70f7a989098376e48ec128f25f767085e84d7fb995a9815eebff0a"
Expand Down Expand Up @@ -714,7 +714,7 @@ Example

.. code-block:: javascript
web3.shh.deleteSymKey('bf31b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f');
web3.shh.deleteSymKey('bf31b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f')
.then(console.log);
> true
Expand Down
4 changes: 4 additions & 0 deletions packages/web3-eth-abi/src/formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/web3/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 22 additions & 1 deletion packages/web3/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,22 @@ export declare interface TransactionReceipt {
logs?: Array<Log>
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 {
Expand Down Expand Up @@ -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<any>
Expand Down Expand Up @@ -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<string> | Signature
recoverTransaction(signature: string | Signature): string
Expand Down Expand Up @@ -376,6 +396,7 @@ export declare class Eth {
isSyncing(cb?: Callback<boolean>): Promise<boolean>
net: Net
personal: Personal
signTransaction(tx: Tx, address?: string, cb?: Callback<string>): Promise<EncodedTransaction>
sendSignedTransaction(data: string, cb?: Callback<string>): PromiEvent<TransactionReceipt>
sendTransaction(tx: Tx, cb?: Callback<string>): PromiEvent<TransactionReceipt>
submitWork(nonce: string, powHash: string, digest: string, cb?: Callback<boolean>): Promise<boolean>
Expand Down
4 changes: 0 additions & 4 deletions test/abi.encodeParameter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

108 changes: 108 additions & 0 deletions test/contract.encodeABI.js
Original file line number Diff line number Diff line change
@@ -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"');
});
});
});

0 comments on commit edd801b

Please sign in to comment.