mirror of
https://github.com/status-im/web3.js.git
synced 2025-02-23 03:28:07 +00:00
Merge develop and bump version (#870)
* bumped version (#865) * validate number of args to solidity functions (#866) * Fix for "filterCreationErrorCallback is not a function" Error #552 (#861) * Missing some checks in order to verify if given value is an object (#568) * make sure the old behaviour is valued in toHex * Porting personal.importRawKey, personal.sign, personal.ecRecover from go-ethereum to web3.js (#565) * Porting personal.importRawKey * Porting personal.sign * Porting personal.ecRecover * Export padLeft and padRight as functions of web3 (#848) I'm working with `bytes12` and it's useful to have these two functions in the web3 object for formatting. * bumped version * fixed lint * new versions file
This commit is contained in:
parent
a075680c85
commit
89b9cb9e04
@ -5,7 +5,7 @@
|
||||
"eqeqeq": true,
|
||||
"freeze": true,
|
||||
"funcscope": false,
|
||||
"maxcomplexity": 4, /* our target is 3! */
|
||||
"maxcomplexity": 5, /* our target is 3! */
|
||||
"maxdepth": 3,
|
||||
"maxerr": 50,
|
||||
/*"maxlen": 80*/ /*this should be our goal*/
|
||||
|
@ -1,3 +1,3 @@
|
||||
ethereum:web3@0.18.4
|
||||
ethereum:web3@0.19.0
|
||||
meteor@1.6.1
|
||||
underscore@1.0.10
|
||||
|
88
dist/web3-light.js
vendored
88
dist/web3-light.js
vendored
@ -1884,7 +1884,7 @@ var sha3 = require('./sha3.js');
|
||||
var utf8 = require('utf8');
|
||||
|
||||
var unitMap = {
|
||||
'noether': '0',
|
||||
'noether': '0',
|
||||
'wei': '1',
|
||||
'kwei': '1000',
|
||||
'Kwei': '1000',
|
||||
@ -2104,7 +2104,7 @@ var toHex = function (val) {
|
||||
if (isBigNumber(val))
|
||||
return fromDecimal(val);
|
||||
|
||||
if (isObject(val))
|
||||
if (typeof val === 'object')
|
||||
return fromUtf8(JSON.stringify(val));
|
||||
|
||||
// if its a negative number, pass it through fromDecimal
|
||||
@ -2265,18 +2265,18 @@ var isAddress = function (address) {
|
||||
* @param {String} address the given HEX adress
|
||||
* @return {Boolean}
|
||||
*/
|
||||
var isChecksumAddress = function (address) {
|
||||
var isChecksumAddress = function (address) {
|
||||
// Check each case
|
||||
address = address.replace('0x','');
|
||||
var addressHash = sha3(address.toLowerCase());
|
||||
|
||||
for (var i = 0; i < 40; i++ ) {
|
||||
for (var i = 0; i < 40; i++ ) {
|
||||
// the nth letter should be uppercase if the nth digit of casemap is 1
|
||||
if ((parseInt(addressHash[i], 16) > 7 && address[i].toUpperCase() !== address[i]) || (parseInt(addressHash[i], 16) <= 7 && address[i].toLowerCase() !== address[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
@ -2288,15 +2288,15 @@ var isChecksumAddress = function (address) {
|
||||
* @param {String} address the given HEX adress
|
||||
* @return {String}
|
||||
*/
|
||||
var toChecksumAddress = function (address) {
|
||||
var toChecksumAddress = function (address) {
|
||||
if (typeof address === 'undefined') return '';
|
||||
|
||||
address = address.toLowerCase().replace('0x','');
|
||||
var addressHash = sha3(address);
|
||||
var checksumAddress = '0x';
|
||||
|
||||
for (var i = 0; i < address.length; i++ ) {
|
||||
// If ith character is 9 to f then make it uppercase
|
||||
for (var i = 0; i < address.length; i++ ) {
|
||||
// If ith character is 9 to f then make it uppercase
|
||||
if (parseInt(addressHash[i], 16) > 7) {
|
||||
checksumAddress += address[i].toUpperCase();
|
||||
} else {
|
||||
@ -2368,7 +2368,7 @@ var isFunction = function (object) {
|
||||
* @return {Boolean}
|
||||
*/
|
||||
var isObject = function (object) {
|
||||
return typeof object === 'object';
|
||||
return object !== null && !(object instanceof Array) && typeof object === 'object';
|
||||
};
|
||||
|
||||
/**
|
||||
@ -2420,7 +2420,7 @@ var isBloom = function (bloom) {
|
||||
return false;
|
||||
} else if (/^(0x)?[0-9a-f]{512}$/.test(bloom) || /^(0x)?[0-9A-F]{512}$/.test(bloom)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
@ -2436,7 +2436,7 @@ var isTopic = function (topic) {
|
||||
return false;
|
||||
} else if (/^(0x)?[0-9a-f]{64}$/.test(topic) || /^(0x)?[0-9A-F]{64}$/.test(topic)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
@ -2475,7 +2475,7 @@ module.exports = {
|
||||
|
||||
},{"./sha3.js":19,"bignumber.js":"bignumber.js","utf8":85}],21:[function(require,module,exports){
|
||||
module.exports={
|
||||
"version": "0.18.4"
|
||||
"version": "0.19.0"
|
||||
}
|
||||
|
||||
},{}],22:[function(require,module,exports){
|
||||
@ -2581,6 +2581,8 @@ Web3.prototype.isAddress = utils.isAddress;
|
||||
Web3.prototype.isChecksumAddress = utils.isChecksumAddress;
|
||||
Web3.prototype.toChecksumAddress = utils.toChecksumAddress;
|
||||
Web3.prototype.isIBAN = utils.isIBAN;
|
||||
Web3.prototype.padLeft = utils.padLeft;
|
||||
Web3.prototype.padRight = utils.padRight;
|
||||
|
||||
|
||||
Web3.prototype.sha3 = function(string, options) {
|
||||
@ -3124,8 +3126,11 @@ module.exports = ContractFactory;
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
InvalidNumberOfParams: function () {
|
||||
return new Error('Invalid number of input parameters');
|
||||
InvalidNumberOfSolidityArgs: function () {
|
||||
return new Error('Invalid number of arguments to Solidity function');
|
||||
},
|
||||
InvalidNumberOfRPCParams: function () {
|
||||
return new Error('Invalid number of input parameters to RPC method');
|
||||
},
|
||||
InvalidConnection: function (host){
|
||||
return new Error('CONNECTION ERROR: Couldn\'t connect to node '+ host +'.');
|
||||
@ -3555,7 +3560,9 @@ var Filter = function (requestManager, options, methods, formatter, callback, fi
|
||||
self.callbacks.forEach(function(cb){
|
||||
cb(error);
|
||||
});
|
||||
filterCreationErrorCallback(error);
|
||||
if (typeof filterCreationErrorCallback === 'function') {
|
||||
filterCreationErrorCallback(error);
|
||||
}
|
||||
} else {
|
||||
self.filterId = id;
|
||||
|
||||
@ -3969,6 +3976,7 @@ module.exports = {
|
||||
|
||||
var coder = require('../solidity/coder');
|
||||
var utils = require('../utils/utils');
|
||||
var errors = require('./errors');
|
||||
var formatters = require('./formatters');
|
||||
var sha3 = require('../utils/sha3');
|
||||
|
||||
@ -4001,6 +4009,23 @@ SolidityFunction.prototype.extractDefaultBlock = function (args) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Should be called to check if the number of arguments is correct
|
||||
*
|
||||
* @method validateArgs
|
||||
* @param {Array} arguments
|
||||
* @throws {Error} if it is not
|
||||
*/
|
||||
SolidityFunction.prototype.validateArgs = function (args) {
|
||||
var inputArgs = args.filter(function (a) {
|
||||
// filter the options object but not arguments that are arrays
|
||||
return !(utils.isObject(a) === true && utils.isArray(a) === false);
|
||||
});
|
||||
if (inputArgs.length !== this._inputTypes.length) {
|
||||
throw errors.InvalidNumberOfSolidityArgs();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Should be used to create payload from arguments
|
||||
*
|
||||
@ -4013,6 +4038,7 @@ SolidityFunction.prototype.toPayload = function (args) {
|
||||
if (args.length > this._inputTypes.length && utils.isObject(args[args.length -1])) {
|
||||
options = args[args.length - 1];
|
||||
}
|
||||
this.validateArgs(args);
|
||||
options.to = this._address;
|
||||
options.data = '0x' + this.signature() + coder.encodeParams(this._inputTypes, args);
|
||||
return options;
|
||||
@ -4207,8 +4233,7 @@ SolidityFunction.prototype.attachToContract = function (contract) {
|
||||
|
||||
module.exports = SolidityFunction;
|
||||
|
||||
|
||||
},{"../solidity/coder":7,"../utils/sha3":19,"../utils/utils":20,"./formatters":30}],32:[function(require,module,exports){
|
||||
},{"../solidity/coder":7,"../utils/sha3":19,"../utils/utils":20,"./errors":26,"./formatters":30}],32:[function(require,module,exports){
|
||||
/*
|
||||
This file is part of web3.js.
|
||||
|
||||
@ -4960,7 +4985,7 @@ Method.prototype.extractCallback = function (args) {
|
||||
*/
|
||||
Method.prototype.validateArgs = function (args) {
|
||||
if (args.length !== this.params) {
|
||||
throw errors.InvalidNumberOfParams();
|
||||
throw errors.InvalidNumberOfRPCParams();
|
||||
}
|
||||
};
|
||||
|
||||
@ -5054,7 +5079,6 @@ Method.prototype.request = function () {
|
||||
|
||||
module.exports = Method;
|
||||
|
||||
|
||||
},{"../utils/utils":20,"./errors":26}],37:[function(require,module,exports){
|
||||
/*
|
||||
This file is part of web3.js.
|
||||
@ -5461,8 +5485,8 @@ Eth.prototype.contract = function (abi) {
|
||||
return factory;
|
||||
};
|
||||
|
||||
Eth.prototype.filter = function (fil, callback) {
|
||||
return new Filter(this._requestManager, fil, watches.eth(), formatters.outputLogFormatter, callback);
|
||||
Eth.prototype.filter = function (fil, callback, filterCreationErrorCallback) {
|
||||
return new Filter(this._requestManager, fil, watches.eth(), formatters.outputLogFormatter, callback, filterCreationErrorCallback);
|
||||
};
|
||||
|
||||
Eth.prototype.namereg = function () {
|
||||
@ -5587,6 +5611,25 @@ var methods = function () {
|
||||
inputFormatter: [null]
|
||||
});
|
||||
|
||||
var importRawKey = new Method({
|
||||
name: 'importRawKey',
|
||||
call: 'personal_importRawKey',
|
||||
params: 2
|
||||
});
|
||||
|
||||
var sign = new Method({
|
||||
name: 'sign',
|
||||
call: 'personal_sign',
|
||||
params: 3,
|
||||
inputFormatter: [null, formatters.inputAddressFormatter, null]
|
||||
});
|
||||
|
||||
var ecRecover = new Method({
|
||||
name: 'ecRecover',
|
||||
call: 'personal_ecRecover',
|
||||
params: 2
|
||||
});
|
||||
|
||||
var unlockAccount = new Method({
|
||||
name: 'unlockAccount',
|
||||
call: 'personal_unlockAccount',
|
||||
@ -5610,7 +5653,10 @@ var methods = function () {
|
||||
|
||||
return [
|
||||
newAccount,
|
||||
importRawKey,
|
||||
unlockAccount,
|
||||
ecRecover,
|
||||
sign,
|
||||
sendTransaction,
|
||||
lockAccount
|
||||
];
|
||||
|
8
dist/web3-light.min.js
vendored
8
dist/web3-light.min.js
vendored
File diff suppressed because one or more lines are too long
5587
dist/web3.js
vendored
5587
dist/web3.js
vendored
File diff suppressed because it is too large
Load Diff
24
dist/web3.js.map
vendored
24
dist/web3.js.map
vendored
File diff suppressed because one or more lines are too long
10
dist/web3.min.js
vendored
10
dist/web3.min.js
vendored
File diff suppressed because one or more lines are too long
@ -39,7 +39,7 @@ var sha3 = require('./sha3.js');
|
||||
var utf8 = require('utf8');
|
||||
|
||||
var unitMap = {
|
||||
'noether': '0',
|
||||
'noether': '0',
|
||||
'wei': '1',
|
||||
'kwei': '1000',
|
||||
'Kwei': '1000',
|
||||
@ -259,7 +259,7 @@ var toHex = function (val) {
|
||||
if (isBigNumber(val))
|
||||
return fromDecimal(val);
|
||||
|
||||
if (isObject(val))
|
||||
if (typeof val === 'object')
|
||||
return fromUtf8(JSON.stringify(val));
|
||||
|
||||
// if its a negative number, pass it through fromDecimal
|
||||
@ -420,18 +420,18 @@ var isAddress = function (address) {
|
||||
* @param {String} address the given HEX adress
|
||||
* @return {Boolean}
|
||||
*/
|
||||
var isChecksumAddress = function (address) {
|
||||
var isChecksumAddress = function (address) {
|
||||
// Check each case
|
||||
address = address.replace('0x','');
|
||||
var addressHash = sha3(address.toLowerCase());
|
||||
|
||||
for (var i = 0; i < 40; i++ ) {
|
||||
for (var i = 0; i < 40; i++ ) {
|
||||
// the nth letter should be uppercase if the nth digit of casemap is 1
|
||||
if ((parseInt(addressHash[i], 16) > 7 && address[i].toUpperCase() !== address[i]) || (parseInt(addressHash[i], 16) <= 7 && address[i].toLowerCase() !== address[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
@ -443,15 +443,15 @@ var isChecksumAddress = function (address) {
|
||||
* @param {String} address the given HEX adress
|
||||
* @return {String}
|
||||
*/
|
||||
var toChecksumAddress = function (address) {
|
||||
var toChecksumAddress = function (address) {
|
||||
if (typeof address === 'undefined') return '';
|
||||
|
||||
address = address.toLowerCase().replace('0x','');
|
||||
var addressHash = sha3(address);
|
||||
var checksumAddress = '0x';
|
||||
|
||||
for (var i = 0; i < address.length; i++ ) {
|
||||
// If ith character is 9 to f then make it uppercase
|
||||
for (var i = 0; i < address.length; i++ ) {
|
||||
// If ith character is 9 to f then make it uppercase
|
||||
if (parseInt(addressHash[i], 16) > 7) {
|
||||
checksumAddress += address[i].toUpperCase();
|
||||
} else {
|
||||
@ -523,7 +523,7 @@ var isFunction = function (object) {
|
||||
* @return {Boolean}
|
||||
*/
|
||||
var isObject = function (object) {
|
||||
return typeof object === 'object';
|
||||
return object !== null && !(object instanceof Array) && typeof object === 'object';
|
||||
};
|
||||
|
||||
/**
|
||||
@ -575,7 +575,7 @@ var isBloom = function (bloom) {
|
||||
return false;
|
||||
} else if (/^(0x)?[0-9a-f]{512}$/.test(bloom) || /^(0x)?[0-9A-F]{512}$/.test(bloom)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
@ -591,7 +591,7 @@ var isTopic = function (topic) {
|
||||
return false;
|
||||
} else if (/^(0x)?[0-9a-f]{64}$/.test(topic) || /^(0x)?[0-9A-F]{64}$/.test(topic)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
{
|
||||
"version": "0.18.4"
|
||||
"version": "0.19.0"
|
||||
}
|
||||
|
@ -100,6 +100,8 @@ Web3.prototype.isAddress = utils.isAddress;
|
||||
Web3.prototype.isChecksumAddress = utils.isChecksumAddress;
|
||||
Web3.prototype.toChecksumAddress = utils.toChecksumAddress;
|
||||
Web3.prototype.isIBAN = utils.isIBAN;
|
||||
Web3.prototype.padLeft = utils.padLeft;
|
||||
Web3.prototype.padRight = utils.padRight;
|
||||
|
||||
|
||||
Web3.prototype.sha3 = function(string, options) {
|
||||
|
@ -21,8 +21,11 @@
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
InvalidNumberOfParams: function () {
|
||||
return new Error('Invalid number of input parameters');
|
||||
InvalidNumberOfSolidityArgs: function () {
|
||||
return new Error('Invalid number of arguments to Solidity function');
|
||||
},
|
||||
InvalidNumberOfRPCParams: function () {
|
||||
return new Error('Invalid number of input parameters to RPC method');
|
||||
},
|
||||
InvalidConnection: function (host){
|
||||
return new Error('CONNECTION ERROR: Couldn\'t connect to node '+ host +'.');
|
||||
|
@ -150,7 +150,9 @@ var Filter = function (requestManager, options, methods, formatter, callback, fi
|
||||
self.callbacks.forEach(function(cb){
|
||||
cb(error);
|
||||
});
|
||||
filterCreationErrorCallback(error);
|
||||
if (typeof filterCreationErrorCallback === 'function') {
|
||||
filterCreationErrorCallback(error);
|
||||
}
|
||||
} else {
|
||||
self.filterId = id;
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
var coder = require('../solidity/coder');
|
||||
var utils = require('../utils/utils');
|
||||
var errors = require('./errors');
|
||||
var formatters = require('./formatters');
|
||||
var sha3 = require('../utils/sha3');
|
||||
|
||||
@ -54,6 +55,23 @@ SolidityFunction.prototype.extractDefaultBlock = function (args) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Should be called to check if the number of arguments is correct
|
||||
*
|
||||
* @method validateArgs
|
||||
* @param {Array} arguments
|
||||
* @throws {Error} if it is not
|
||||
*/
|
||||
SolidityFunction.prototype.validateArgs = function (args) {
|
||||
var inputArgs = args.filter(function (a) {
|
||||
// filter the options object but not arguments that are arrays
|
||||
return !(utils.isObject(a) === true && utils.isArray(a) === false);
|
||||
});
|
||||
if (inputArgs.length !== this._inputTypes.length) {
|
||||
throw errors.InvalidNumberOfSolidityArgs();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Should be used to create payload from arguments
|
||||
*
|
||||
@ -66,6 +84,7 @@ SolidityFunction.prototype.toPayload = function (args) {
|
||||
if (args.length > this._inputTypes.length && utils.isObject(args[args.length -1])) {
|
||||
options = args[args.length - 1];
|
||||
}
|
||||
this.validateArgs(args);
|
||||
options.to = this._address;
|
||||
options.data = '0x' + this.signature() + coder.encodeParams(this._inputTypes, args);
|
||||
return options;
|
||||
@ -259,4 +278,3 @@ SolidityFunction.prototype.attachToContract = function (contract) {
|
||||
};
|
||||
|
||||
module.exports = SolidityFunction;
|
||||
|
||||
|
@ -69,7 +69,7 @@ Method.prototype.extractCallback = function (args) {
|
||||
*/
|
||||
Method.prototype.validateArgs = function (args) {
|
||||
if (args.length !== this.params) {
|
||||
throw errors.InvalidNumberOfParams();
|
||||
throw errors.InvalidNumberOfRPCParams();
|
||||
}
|
||||
};
|
||||
|
||||
@ -162,4 +162,3 @@ Method.prototype.request = function () {
|
||||
};
|
||||
|
||||
module.exports = Method;
|
||||
|
||||
|
@ -335,8 +335,8 @@ Eth.prototype.contract = function (abi) {
|
||||
return factory;
|
||||
};
|
||||
|
||||
Eth.prototype.filter = function (fil, callback) {
|
||||
return new Filter(this._requestManager, fil, watches.eth(), formatters.outputLogFormatter, callback);
|
||||
Eth.prototype.filter = function (fil, callback, filterCreationErrorCallback) {
|
||||
return new Filter(this._requestManager, fil, watches.eth(), formatters.outputLogFormatter, callback, filterCreationErrorCallback);
|
||||
};
|
||||
|
||||
Eth.prototype.namereg = function () {
|
||||
|
@ -51,6 +51,25 @@ var methods = function () {
|
||||
inputFormatter: [null]
|
||||
});
|
||||
|
||||
var importRawKey = new Method({
|
||||
name: 'importRawKey',
|
||||
call: 'personal_importRawKey',
|
||||
params: 2
|
||||
});
|
||||
|
||||
var sign = new Method({
|
||||
name: 'sign',
|
||||
call: 'personal_sign',
|
||||
params: 3,
|
||||
inputFormatter: [null, formatters.inputAddressFormatter, null]
|
||||
});
|
||||
|
||||
var ecRecover = new Method({
|
||||
name: 'ecRecover',
|
||||
call: 'personal_ecRecover',
|
||||
params: 2
|
||||
});
|
||||
|
||||
var unlockAccount = new Method({
|
||||
name: 'unlockAccount',
|
||||
call: 'personal_unlockAccount',
|
||||
@ -74,7 +93,10 @@ var methods = function () {
|
||||
|
||||
return [
|
||||
newAccount,
|
||||
importRawKey,
|
||||
unlockAccount,
|
||||
ecRecover,
|
||||
sign,
|
||||
sendTransaction,
|
||||
lockAccount
|
||||
];
|
||||
|
@ -1,7 +1,7 @@
|
||||
/* jshint ignore:start */
|
||||
Package.describe({
|
||||
name: 'ethereum:web3',
|
||||
version: '0.18.4',
|
||||
version: '0.19.0',
|
||||
summary: 'Ethereum JavaScript API, middleware to talk to a ethreum node over RPC',
|
||||
git: 'https://github.com/ethereum/ethereum.js',
|
||||
// By default, Meteor will default to using README.md for documentation.
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "web3",
|
||||
"namespace": "ethereum",
|
||||
"version": "0.18.4",
|
||||
"version": "0.19.0",
|
||||
"description": "Ethereum JavaScript API, middleware to talk to a ethereum node over RPC",
|
||||
"main": "./index.js",
|
||||
"directories": {
|
||||
|
@ -4,6 +4,7 @@ var Web3 = require('../index');
|
||||
var FakeHttpProvider = require('./helpers/FakeHttpProvider');
|
||||
var FakeHttpProvider2 = require('./helpers/FakeHttpProvider2');
|
||||
var utils = require('../lib/utils/utils');
|
||||
var errors = require('../lib/web3/errors');
|
||||
var BigNumber = require('bignumber.js');
|
||||
var sha3 = require('../lib/utils/sha3');
|
||||
|
||||
@ -353,6 +354,31 @@ describe('contract', function () {
|
||||
|
||||
});
|
||||
|
||||
it('should throw if called with optional params without all args', function () {
|
||||
var provider = new FakeHttpProvider();
|
||||
var web3 = new Web3(provider);
|
||||
provider.injectResult('0x0000000000000000000000000000000000000000000000000000000000000032');
|
||||
var signature = 'balance(address)';
|
||||
var address = '0x1234567890123456789012345678901234567891';
|
||||
provider.injectValidation(function (payload) {
|
||||
assert.equal(payload.method, 'eth_call');
|
||||
assert.deepEqual(payload.params, [{
|
||||
data: '0x' + sha3(signature).slice(0, 8) + '0000000000000000000000001234567890123456789012345678901234567891',
|
||||
to: address,
|
||||
from: address,
|
||||
gas: '0xc350'
|
||||
}, 'latest']);
|
||||
});
|
||||
|
||||
var contract = web3.eth.contract(desc).at(address);
|
||||
|
||||
var test = function() {
|
||||
var r = contract.balance({from: address, gas: 50000});
|
||||
}
|
||||
assert.throws(test, errors.InvalidNumberOfSolidityArgs().message);
|
||||
|
||||
});
|
||||
|
||||
it('should explicitly make a call with optional params', function () {
|
||||
var provider = new FakeHttpProvider();
|
||||
var web3 = new Web3(provider);
|
||||
@ -399,6 +425,35 @@ describe('contract', function () {
|
||||
|
||||
});
|
||||
|
||||
it('it should throw if sendTransaction with optional params without all args', function () {
|
||||
var provider = new FakeHttpProvider();
|
||||
var web3 = new Web3(provider);
|
||||
var signature = 'send(address,uint256)';
|
||||
var address = '0x1234567890123456789012345678901234567891';
|
||||
provider.injectValidation(function (payload) {
|
||||
assert.equal(payload.method, 'eth_sendTransaction');
|
||||
assert.deepEqual(payload.params, [{
|
||||
data: '0x' + sha3(signature).slice(0, 8) +
|
||||
'0000000000000000000000001234567890123456789012345678901234567891' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000011' ,
|
||||
to: address,
|
||||
from: address,
|
||||
gas: '0xc350',
|
||||
gasPrice: '0xbb8',
|
||||
value: '0x2710'
|
||||
}]);
|
||||
});
|
||||
|
||||
var contract = web3.eth.contract(desc).at(address);
|
||||
|
||||
var test = function() {
|
||||
contract.send(address, {from: address, gas: 50000, gasPrice: 3000, value: 10000});
|
||||
}
|
||||
|
||||
assert.throws(test, errors.InvalidNumberOfSolidityArgs().message);
|
||||
|
||||
});
|
||||
|
||||
it('should sendTransaction with optional params', function () {
|
||||
var provider = new FakeHttpProvider();
|
||||
var web3 = new Web3(provider);
|
||||
@ -557,4 +612,3 @@ describe('contract', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -39,9 +39,8 @@ describe('lib/web3/method', function () {
|
||||
var test2 = function () { method.validateArgs(args2); };
|
||||
|
||||
// then
|
||||
assert.throws(test, errors.InvalidNumberOfParams().message);
|
||||
assert.throws(test2, errors.InvalidNumberOfParams().message);
|
||||
assert.throws(test, errors.InvalidNumberOfRPCParams().message);
|
||||
assert.throws(test2, errors.InvalidNumberOfRPCParams().message);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user