1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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]);
});
});
});
});
});
|