Browse Source
Conflicts: libjsqrc/ethereumjs/dist/web3-light.js libjsqrc/ethereumjs/dist/web3-light.js.map libjsqrc/ethereumjs/dist/web3-light.min.js libjsqrc/ethereumjs/dist/web3.js libjsqrc/ethereumjs/dist/web3.js.map libjsqrc/ethereumjs/dist/web3.min.js libjsqrc/ethereumjs/lib/web3/eth.jscl-refactor
Marek Kotewicz
10 years ago
26 changed files with 2831 additions and 2016 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,14 +1,13 @@ |
|||
// dont override global variable
|
|||
if (typeof web3 !== 'undefined') { |
|||
var web3; |
|||
} |
|||
|
|||
web3 = require('./lib/web3'); |
|||
var web3 = require('./lib/web3'); |
|||
web3.providers.HttpProvider = require('./lib/web3/httpprovider'); |
|||
web3.providers.QtSyncProvider = require('./lib/web3/qtsync'); |
|||
web3.eth.contract = require('./lib/web3/contract'); |
|||
web3.abi = require('./lib/solidity/abi'); |
|||
|
|||
|
|||
// dont override global variable
|
|||
if (typeof window !== 'undefined' && typeof window.web3 === 'undefined') { |
|||
window.web3 = web3; |
|||
} |
|||
|
|||
module.exports = web3; |
|||
|
|||
|
@ -0,0 +1,68 @@ |
|||
/* |
|||
This file is part of ethereum.js. |
|||
|
|||
ethereum.js is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU Lesser General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
ethereum.js is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU Lesser General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU Lesser General Public License |
|||
along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** |
|||
* @file utils.js |
|||
* @author Marek Kotewicz <marek@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
/** |
|||
* Returns the contstructor with matching number of arguments |
|||
* |
|||
* @method getConstructor |
|||
* @param {Array} abi |
|||
* @param {Number} numberOfArgs |
|||
* @returns {Object} constructor function abi |
|||
*/ |
|||
var getConstructor = function (abi, numberOfArgs) { |
|||
return abi.filter(function (f) { |
|||
return f.type === 'constructor' && f.inputs.length === numberOfArgs; |
|||
})[0]; |
|||
}; |
|||
|
|||
/** |
|||
* Filters all functions from input abi |
|||
* |
|||
* @method filterFunctions |
|||
* @param {Array} abi |
|||
* @returns {Array} abi array with filtered objects of type 'function' |
|||
*/ |
|||
var filterFunctions = function (json) { |
|||
return json.filter(function (current) { |
|||
return current.type === 'function'; |
|||
}); |
|||
}; |
|||
|
|||
/** |
|||
* Filters all events from input abi |
|||
* |
|||
* @method filterEvents |
|||
* @param {Array} abi |
|||
* @returns {Array} abi array with filtered objects of type 'event' |
|||
*/ |
|||
var filterEvents = function (json) { |
|||
return json.filter(function (current) { |
|||
return current.type === 'event'; |
|||
}); |
|||
}; |
|||
|
|||
module.exports = { |
|||
getConstructor: getConstructor, |
|||
filterFunctions: filterFunctions, |
|||
filterEvents: filterEvents |
|||
}; |
|||
|
@ -1,3 +1,3 @@ |
|||
{ |
|||
"version": "0.2.5" |
|||
"version": "0.2.6" |
|||
} |
|||
|
@ -0,0 +1,106 @@ |
|||
var chai = require('chai'); |
|||
var assert = require('assert'); |
|||
var abi = require('../lib/solidity/abi'); |
|||
|
|||
describe('lib/solidity/abi', function () { |
|||
describe('formatConstructorParams', function () { |
|||
it('should format uint256 properly', function () { |
|||
// given
|
|||
var description = [{ |
|||
"name": "test", |
|||
"type": "constructor", |
|||
"inputs": [{ |
|||
"name": "a", |
|||
"type": "uint256" |
|||
} |
|||
] |
|||
}]; |
|||
|
|||
// when
|
|||
var bytes = abi.formatConstructorParams(description, [2]); |
|||
|
|||
// then
|
|||
assert.equal(bytes, '0000000000000000000000000000000000000000000000000000000000000002'); |
|||
}); |
|||
|
|||
it('should not find matching constructor', function () { |
|||
// given
|
|||
var description = [{ |
|||
"name": "test", |
|||
"type": "constructor", |
|||
"inputs": [{ |
|||
"name": "a", |
|||
"type": "uint256" |
|||
} |
|||
] |
|||
}]; |
|||
|
|||
// when
|
|||
var bytes = abi.formatConstructorParams(description, []); |
|||
|
|||
// then
|
|||
assert.equal(bytes, ''); |
|||
}); |
|||
|
|||
it('should not find matching constructor2', function () { |
|||
// given
|
|||
var description = [{ |
|||
"name": "test", |
|||
"type": "constructor", |
|||
"inputs": [{ |
|||
"name": "a", |
|||
"type": "uint256" |
|||
} |
|||
] |
|||
}]; |
|||
|
|||
// when
|
|||
var bytes = abi.formatConstructorParams(description, [1,2]); |
|||
|
|||
// then
|
|||
assert.equal(bytes, ''); |
|||
}); |
|||
|
|||
it('should not find matching constructor3', function () { |
|||
// given
|
|||
var description = [{ |
|||
"name": "test", |
|||
"type": "function", |
|||
"inputs": [{ |
|||
"name": "a", |
|||
"type": "uint256" |
|||
} |
|||
] |
|||
}]; |
|||
|
|||
// when
|
|||
var bytes = abi.formatConstructorParams(description, [2]); |
|||
|
|||
// then
|
|||
assert.equal(bytes, ''); |
|||
}); |
|||
|
|||
it('should find matching constructor with multiple args', function () { |
|||
// given
|
|||
var description = [{ |
|||
"name": "test", |
|||
"type": "constructor", |
|||
"inputs": [{ |
|||
"name": "a", |
|||
"type": "uint256" |
|||
}, { |
|||
"name": "b", |
|||
"type": "uint256" |
|||
}] |
|||
}]; |
|||
|
|||
// when
|
|||
var bytes = abi.formatConstructorParams(description, ['1', '5']); |
|||
|
|||
// then
|
|||
assert.equal(bytes, '00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000005'); |
|||
}); |
|||
}); |
|||
}); |
|||
|
|||
|
@ -0,0 +1,23 @@ |
|||
var chai = require('chai'); |
|||
var utils = require('../lib/utils/utils.js'); |
|||
var assert = chai.assert; |
|||
|
|||
var tests = [ |
|||
{ value: function () {}, is: false}, |
|||
{ value: new Function(), is: false}, |
|||
{ value: 'function', is: false}, |
|||
{ value: {}, is: false}, |
|||
{ value: '0xc6d9d2cd449a754c494264e1809c50e34d64562b', is: true }, |
|||
{ value: 'c6d9d2cd449a754c494264e1809c50e34d64562b', is: false } |
|||
]; |
|||
|
|||
describe('lib/utils/utils', function () { |
|||
describe('isStrictAddress', function () { |
|||
tests.forEach(function (test) { |
|||
it('shoud test if value ' + test.value + ' is address: ' + test.is, function () { |
|||
assert.equal(utils.isStrictAddress(test.value), test.is); |
|||
}); |
|||
}); |
|||
}); |
|||
}); |
|||
|
@ -0,0 +1,39 @@ |
|||
var chai = require('chai'); |
|||
var assert = chai.assert; |
|||
var web3 = require('../index'); |
|||
var BigNumber = require('bignumber.js'); |
|||
var FakeHttpProvider = require('./helpers/FakeHttpProvider'); |
|||
|
|||
var method = 'gasPrice'; |
|||
|
|||
var tests = [{ |
|||
result: '0x15f90', |
|||
formattedResult: new BigNumber(90000), |
|||
call: 'eth_'+ method |
|||
}]; |
|||
|
|||
describe('web3.eth', function () { |
|||
describe(method, function () { |
|||
tests.forEach(function (test, index) { |
|||
it('property test: ' + index, function () { |
|||
|
|||
// given
|
|||
var provider = new FakeHttpProvider(); |
|||
web3.setProvider(provider); |
|||
provider.injectResult(test.result); |
|||
provider.injectValidation(function (payload) { |
|||
assert.equal(payload.jsonrpc, '2.0'); |
|||
assert.equal(payload.method, test.call); |
|||
assert.deepEqual(payload.params, []); |
|||
}); |
|||
|
|||
// when
|
|||
var result = web3.eth[method]; |
|||
|
|||
// then
|
|||
assert.deepEqual(test.formattedResult, result); |
|||
}); |
|||
}); |
|||
}); |
|||
}); |
|||
|
Loading…
Reference in new issue