2015-06-04 10:25:46 +00:00
|
|
|
var chai = require('chai');
|
|
|
|
var assert = chai.assert;
|
|
|
|
var FakeHttpProvider = require('./helpers/FakeHttpProvider');
|
|
|
|
var web3 = require('../lib/web3');
|
|
|
|
|
|
|
|
|
|
|
|
var tests = [{
|
2015-06-08 12:46:19 +00:00
|
|
|
properties: [new web3._extend.Property({
|
2015-06-04 10:25:46 +00:00
|
|
|
name: 'gasPrice',
|
|
|
|
getter: 'eth_gasPrice',
|
2015-06-08 12:46:19 +00:00
|
|
|
outputFormatter: web3._extend.formatters.outputBigNumberFormatter
|
2015-06-04 10:25:46 +00:00
|
|
|
})]
|
|
|
|
},{
|
2015-06-08 12:46:19 +00:00
|
|
|
methods: [new web3._extend.Method({
|
2015-06-04 10:25:46 +00:00
|
|
|
name: 'getBalance',
|
|
|
|
call: 'eth_getBalance',
|
|
|
|
params: 2,
|
2015-06-08 12:46:19 +00:00
|
|
|
inputFormatter: [web3._extend.utils.toAddress, web3._extend.formatters.inputDefaultBlockNumberFormatter],
|
|
|
|
outputFormatter: web3._extend.formatters.outputBigNumberFormatter
|
2015-06-04 10:25:46 +00:00
|
|
|
})]
|
|
|
|
},{
|
|
|
|
property: 'admin',
|
2015-06-08 12:46:19 +00:00
|
|
|
properties: [new web3._extend.Property({
|
2015-06-04 10:25:46 +00:00
|
|
|
name: 'gasPrice',
|
|
|
|
getter: 'eth_gasPrice',
|
2015-06-08 12:46:19 +00:00
|
|
|
outputFormatter: web3._extend.formatters.outputBigNumberFormatter
|
2015-06-04 10:25:46 +00:00
|
|
|
})],
|
2015-06-08 12:46:19 +00:00
|
|
|
methods: [new web3._extend.Method({
|
2015-06-04 10:25:46 +00:00
|
|
|
name: 'getBalance',
|
|
|
|
call: 'eth_getBalance',
|
|
|
|
params: 2,
|
2015-06-08 12:46:19 +00:00
|
|
|
inputFormatter: [web3._extend.utils.toAddress, web3._extend.formatters.inputDefaultBlockNumberFormatter],
|
|
|
|
outputFormatter: web3._extend.formatters.outputBigNumberFormatter
|
2015-06-04 10:25:46 +00:00
|
|
|
})]
|
|
|
|
}];
|
|
|
|
|
|
|
|
describe('web3', function () {
|
2015-06-08 12:46:19 +00:00
|
|
|
describe('_extend', function () {
|
2015-06-04 10:25:46 +00:00
|
|
|
tests.forEach(function (test, index) {
|
|
|
|
it('test no: ' + index, function () {
|
2015-06-08 12:46:19 +00:00
|
|
|
web3._extend(test);
|
2015-06-04 10:25:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
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]);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|