Merge branch 'develop' into allAsync
Conflicts: dist/web3-light.js.map dist/web3-light.min.js dist/web3.js.map dist/web3.min.js
This commit is contained in:
commit
b09bf319bd
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 one or more lines are too long
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 one or more lines are too long
17
lib/web3.js
17
lib/web3.js
|
@ -148,6 +148,23 @@ Object.defineProperty(web3.eth, 'defaultAccount', {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
// EXTEND
|
||||
web3._extend = function(extension){
|
||||
/*jshint maxcomplexity: 6 */
|
||||
|
||||
if(extension.property && !web3[extension.property])
|
||||
web3[extension.property] = {};
|
||||
|
||||
setupMethods(web3[extension.property] || web3, extension.methods || []);
|
||||
setupProperties(web3[extension.property] || web3, extension.properties || []);
|
||||
};
|
||||
web3._extend.formatters = formatters;
|
||||
web3._extend.utils = utils;
|
||||
web3._extend.Method = require('./web3/method');
|
||||
web3._extend.Property = require('./web3/property');
|
||||
|
||||
|
||||
/// setups all api methods
|
||||
setupProperties(web3, web3Properties);
|
||||
setupMethods(web3.net, net.methods);
|
||||
|
|
|
@ -89,8 +89,10 @@ var inputTransactionFormatter = function (options){
|
|||
* @returns {Object} transaction
|
||||
*/
|
||||
var outputTransactionFormatter = function (tx){
|
||||
tx.blockNumber = utils.toDecimal(tx.blockNumber);
|
||||
tx.transactionIndex = utils.toDecimal(tx.transactionIndex);
|
||||
if(tx.blockNumber !== null)
|
||||
tx.blockNumber = utils.toDecimal(tx.blockNumber);
|
||||
if(tx.transactionIndex !== null)
|
||||
tx.transactionIndex = utils.toDecimal(tx.transactionIndex);
|
||||
tx.nonce = utils.toDecimal(tx.nonce);
|
||||
tx.gas = utils.toDecimal(tx.gas);
|
||||
tx.gasPrice = utils.toBigNumber(tx.gasPrice);
|
||||
|
@ -112,7 +114,8 @@ var outputBlockFormatter = function(block) {
|
|||
block.gasUsed = utils.toDecimal(block.gasUsed);
|
||||
block.size = utils.toDecimal(block.size);
|
||||
block.timestamp = utils.toDecimal(block.timestamp);
|
||||
block.number = utils.toDecimal(block.number);
|
||||
if(block.number !== null)
|
||||
block.number = utils.toDecimal(block.number);
|
||||
|
||||
block.difficulty = utils.toBigNumber(block.difficulty);
|
||||
block.totalDifficulty = utils.toBigNumber(block.totalDifficulty);
|
||||
|
@ -139,9 +142,12 @@ var outputLogFormatter = function(log) {
|
|||
return null;
|
||||
}
|
||||
|
||||
log.blockNumber = utils.toDecimal(log.blockNumber);
|
||||
log.transactionIndex = utils.toDecimal(log.transactionIndex);
|
||||
log.logIndex = utils.toDecimal(log.logIndex);
|
||||
if(log.blockNumber !== null)
|
||||
log.blockNumber = utils.toDecimal(log.blockNumber);
|
||||
if(log.transactionIndex !== null)
|
||||
log.transactionIndex = utils.toDecimal(log.transactionIndex);
|
||||
if(log.logIndex !== null)
|
||||
log.logIndex = utils.toDecimal(log.logIndex);
|
||||
|
||||
return log;
|
||||
};
|
||||
|
|
|
@ -8,38 +8,72 @@ describe('formatters', function () {
|
|||
it('should return the correct value', function () {
|
||||
|
||||
assert.deepEqual(formatters.outputBlockFormatter({
|
||||
hash: '0x34234kjh23kj4234',
|
||||
parentHash: '0x34234kjh23kj4234',
|
||||
miner: '0x34234kjh23kj4234',
|
||||
stateRoot: '0x34234kjh23kj4234',
|
||||
sha3Uncles: '0x34234kjh23kj4234',
|
||||
bloom: '0x34234kjh23kj4234',
|
||||
hash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||
parentHash: '0x83ffb245cfced97ccc5c75253d6960376d6c6dea93647397a543a72fdaea5265',
|
||||
miner: '0xdcc6960376d6c6dea93647383ffb245cfced97cf',
|
||||
stateRoot: '0x54dda68af07643f68739a6e9612ad157a26ae7e2ce81f77842bb5835fbcde583',
|
||||
sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
|
||||
bloom: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||
difficulty: '0x3e8',
|
||||
totalDifficulty: '0x3e8',
|
||||
number: '0x3e8',
|
||||
gasLimit: '0x3e8',
|
||||
gasUsed: '0x3e8',
|
||||
timestamp: '0x3e8',
|
||||
extraData: '0x34234kjh23kj4234',
|
||||
nonce: '0x34234kjh23kj4234',
|
||||
children: ['0x34234kjh23kj4234'],
|
||||
extraData: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||
nonce: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||
size: '0x3e8'
|
||||
}), {
|
||||
hash: '0x34234kjh23kj4234',
|
||||
parentHash: '0x34234kjh23kj4234',
|
||||
miner: '0x34234kjh23kj4234',
|
||||
stateRoot: '0x34234kjh23kj4234',
|
||||
sha3Uncles: '0x34234kjh23kj4234',
|
||||
bloom: '0x34234kjh23kj4234',
|
||||
hash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||
parentHash: '0x83ffb245cfced97ccc5c75253d6960376d6c6dea93647397a543a72fdaea5265',
|
||||
miner: '0xdcc6960376d6c6dea93647383ffb245cfced97cf',
|
||||
stateRoot: '0x54dda68af07643f68739a6e9612ad157a26ae7e2ce81f77842bb5835fbcde583',
|
||||
sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
|
||||
bloom: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||
difficulty: new BigNumber(1000),
|
||||
totalDifficulty: new BigNumber(1000),
|
||||
number: 1000,
|
||||
gasLimit: 1000,
|
||||
gasUsed: 1000,
|
||||
timestamp: 1000,
|
||||
extraData: '0x34234kjh23kj4234',
|
||||
nonce: '0x34234kjh23kj4234',
|
||||
children: ['0x34234kjh23kj4234'],
|
||||
extraData: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||
nonce: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||
size: 1000
|
||||
});
|
||||
});
|
||||
it('should return the correct value, when null values are present', function () {
|
||||
|
||||
assert.deepEqual(formatters.outputBlockFormatter({
|
||||
hash: null,
|
||||
parentHash: '0x83ffb245cfced97ccc5c75253d6960376d6c6dea93647397a543a72fdaea5265',
|
||||
miner: null,
|
||||
stateRoot: '0x54dda68af07643f68739a6e9612ad157a26ae7e2ce81f77842bb5835fbcde583',
|
||||
sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
|
||||
bloom: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||
difficulty: '0x3e8',
|
||||
totalDifficulty: '0x3e8',
|
||||
number: null,
|
||||
gasLimit: '0x3e8',
|
||||
gasUsed: '0x3e8',
|
||||
timestamp: '0x3e8',
|
||||
extraData: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||
nonce: null,
|
||||
size: '0x3e8'
|
||||
}), {
|
||||
hash: null,
|
||||
parentHash: '0x83ffb245cfced97ccc5c75253d6960376d6c6dea93647397a543a72fdaea5265',
|
||||
miner: null,
|
||||
stateRoot: '0x54dda68af07643f68739a6e9612ad157a26ae7e2ce81f77842bb5835fbcde583',
|
||||
sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
|
||||
bloom: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||
difficulty: new BigNumber(1000),
|
||||
totalDifficulty: new BigNumber(1000),
|
||||
number: null,
|
||||
gasLimit: 1000,
|
||||
gasUsed: 1000,
|
||||
timestamp: 1000,
|
||||
extraData: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||
nonce: null,
|
||||
size: 1000
|
||||
});
|
||||
});
|
||||
|
|
|
@ -9,17 +9,37 @@ describe('formatters', function () {
|
|||
transactionIndex: '0x3e8',
|
||||
logIndex: '0x3e8',
|
||||
blockNumber: '0x3e8',
|
||||
transactionHash: '0x7b2274657374223a2274657374227d',
|
||||
blockHash: '0x7b2274657374223a2274657374227d',
|
||||
data: '0x7b2274657374223a2274657374227d',
|
||||
transactionHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||
blockHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||
data: '0x7b2274657374223a2274657374227',
|
||||
topics: ['0x68656c6c6f','0x6d79746f70696373']
|
||||
}), {
|
||||
transactionIndex: 1000,
|
||||
logIndex: 1000,
|
||||
blockNumber: 1000,
|
||||
transactionHash: '0x7b2274657374223a2274657374227d',
|
||||
blockHash: '0x7b2274657374223a2274657374227d',
|
||||
data: '0x7b2274657374223a2274657374227d',
|
||||
transactionHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||
blockHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||
data: '0x7b2274657374223a2274657374227',
|
||||
topics: ['0x68656c6c6f','0x6d79746f70696373']
|
||||
});
|
||||
});
|
||||
it('should return the correct value, when null values are present', function () {
|
||||
|
||||
assert.deepEqual(formatters.outputLogFormatter({
|
||||
transactionIndex: null,
|
||||
logIndex: null,
|
||||
blockNumber: null,
|
||||
transactionHash: null,
|
||||
blockHash: null,
|
||||
data: '0x7b2274657374223a2274657374227',
|
||||
topics: ['0x68656c6c6f','0x6d79746f70696373']
|
||||
}), {
|
||||
transactionIndex: null,
|
||||
logIndex: null,
|
||||
blockNumber: null,
|
||||
transactionHash: null,
|
||||
blockHash: null,
|
||||
data: '0x7b2274657374223a2274657374227',
|
||||
topics: ['0x68656c6c6f','0x6d79746f70696373']
|
||||
});
|
||||
});
|
||||
|
|
|
@ -7,7 +7,7 @@ describe('formatters', function () {
|
|||
it('should return the correct value', function () {
|
||||
|
||||
assert.deepEqual(formatters.outputTransactionFormatter({
|
||||
input: '0x34234kjh23kj4234',
|
||||
input: '0x3454645634534',
|
||||
from: '0x00000',
|
||||
to: '0x00000',
|
||||
value: '0x3e8',
|
||||
|
@ -16,9 +16,9 @@ describe('formatters', function () {
|
|||
nonce: '0xb',
|
||||
transactionIndex: '0x1',
|
||||
blockNumber: '0x3e8',
|
||||
blockHash: '0x34234bf23bf4234'
|
||||
blockHash: '0xc9b9cdc2092a9d6589d96662b1fd6949611163fb3910cf8a173cd060f17702f9'
|
||||
}), {
|
||||
input: '0x34234kjh23kj4234',
|
||||
input: '0x3454645634534',
|
||||
from: '0x00000',
|
||||
to: '0x00000',
|
||||
value: new BigNumber(1000),
|
||||
|
@ -26,9 +26,36 @@ describe('formatters', function () {
|
|||
gasPrice: new BigNumber(1000),
|
||||
nonce: 11,
|
||||
blockNumber: 1000,
|
||||
blockHash: '0x34234bf23bf4234',
|
||||
blockHash: '0xc9b9cdc2092a9d6589d96662b1fd6949611163fb3910cf8a173cd060f17702f9',
|
||||
transactionIndex: 1
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the correct value, when null values are present', function () {
|
||||
|
||||
assert.deepEqual(formatters.outputTransactionFormatter({
|
||||
input: '0x3454645634534',
|
||||
from: '0x00000',
|
||||
to: null,
|
||||
value: '0x3e8',
|
||||
gas: '0x3e8',
|
||||
gasPrice: '0x3e8',
|
||||
nonce: '0xb',
|
||||
transactionIndex: null,
|
||||
blockNumber: null,
|
||||
blockHash: null
|
||||
}), {
|
||||
input: '0x3454645634534',
|
||||
from: '0x00000',
|
||||
to: null,
|
||||
value: new BigNumber(1000),
|
||||
gas: 1000,
|
||||
gasPrice: new BigNumber(1000),
|
||||
nonce: 11,
|
||||
blockNumber: null,
|
||||
blockHash: null,
|
||||
transactionIndex: null
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
var chai = require('chai');
|
||||
var assert = chai.assert;
|
||||
var FakeHttpProvider = require('./helpers/FakeHttpProvider');
|
||||
var web3 = require('../lib/web3');
|
||||
|
||||
|
||||
var tests = [{
|
||||
properties: [new web3._extend.Property({
|
||||
name: 'gasPrice',
|
||||
getter: 'eth_gasPrice',
|
||||
outputFormatter: web3._extend.formatters.outputBigNumberFormatter
|
||||
})]
|
||||
},{
|
||||
methods: [new web3._extend.Method({
|
||||
name: 'getBalance',
|
||||
call: 'eth_getBalance',
|
||||
params: 2,
|
||||
inputFormatter: [web3._extend.utils.toAddress, web3._extend.formatters.inputDefaultBlockNumberFormatter],
|
||||
outputFormatter: web3._extend.formatters.outputBigNumberFormatter
|
||||
})]
|
||||
},{
|
||||
property: 'admin',
|
||||
properties: [new web3._extend.Property({
|
||||
name: 'gasPrice',
|
||||
getter: 'eth_gasPrice',
|
||||
outputFormatter: web3._extend.formatters.outputBigNumberFormatter
|
||||
})],
|
||||
methods: [new web3._extend.Method({
|
||||
name: 'getBalance',
|
||||
call: 'eth_getBalance',
|
||||
params: 2,
|
||||
inputFormatter: [web3._extend.utils.toAddress, web3._extend.formatters.inputDefaultBlockNumberFormatter],
|
||||
outputFormatter: web3._extend.formatters.outputBigNumberFormatter
|
||||
})]
|
||||
}];
|
||||
|
||||
describe('web3', function () {
|
||||
describe('_extend', function () {
|
||||
tests.forEach(function (test, index) {
|
||||
it('test no: ' + index, function () {
|
||||
web3._extend(test);
|
||||
|
||||
|
||||
if(test.properties)
|
||||
test.properties.forEach(function(property){
|
||||
|
||||
var provider = new FakeHttpProvider();
|
||||
web3.setProvider(provider);
|
||||
provider.injectResult('');
|
||||
provider.injectValidation(function (payload) {
|
||||
assert.equal(payload.jsonrpc, '2.0');
|
||||
assert.equal(payload.method, property.getter);
|
||||
});
|
||||
|
||||
if(test.property) {
|
||||
assert.isObject(web3[test.property][property.name]);
|
||||
assert.isFunction(web3[test.property]['get'+ property.name.charAt(0).toUpperCase() + property.name.slice(1)]);
|
||||
} else {
|
||||
assert.isObject(web3[property.name]);
|
||||
assert.isFunction(web3['get'+ property.name.charAt(0).toUpperCase() + property.name.slice(1)]);
|
||||
}
|
||||
});
|
||||
|
||||
if(test.methods)
|
||||
test.methods.forEach(function(property){
|
||||
if(test.property)
|
||||
assert.isFunction(web3[test.property][property.name]);
|
||||
else
|
||||
assert.isFunction(web3[property.name]);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue