Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit db1f3c4

Browse files
committed
test helper test.method.js extended with the possibility to pass custom default options and eth.getBalance tests extended with a defaultBlock fallback case
1 parent 2c3b9d1 commit db1f3c4

File tree

2 files changed

+65
-14
lines changed

2 files changed

+65
-14
lines changed

test/eth.getBalance.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,74 +10,83 @@ var tests = [{
1010
formattedArgs: ['0x000000000000000000000000000000000000012d', '0x2'],
1111
result: '0x31981',
1212
formattedResult: '203137',
13-
call: 'eth_'+ method
14-
},{
13+
call: 'eth_' + method
14+
}, {
1515
args: ['0x000000000000000000000000000000000000012d', '0x1'],
1616
formattedArgs: ['0x000000000000000000000000000000000000012d', '0x1'],
1717
result: '0x31981',
1818
formattedResult: '203137',
19-
call: 'eth_'+ method
19+
call: 'eth_' + method
2020
}, {
2121
args: ['0x000000000000000000000000000000000000012d', 0x1],
2222
formattedArgs: ['0x000000000000000000000000000000000000012d', '0x1'],
2323
result: '0x31981',
2424
formattedResult: '203137',
25-
call: 'eth_'+ method
25+
call: 'eth_' + method
2626
}, {
2727
args: ['0x000000000000000000000000000000000000012d'],
2828
formattedArgs: ['0x000000000000000000000000000000000000012d', eth.defaultBlock],
2929
result: '0x31981',
3030
formattedResult: '203137',
31-
call: 'eth_'+ method
31+
call: 'eth_' + method
3232
}, {
3333
args: ['0XDBDBDB2CBD23B783741E8D7FCF51E459B497E4A6', 0x1],
3434
formattedArgs: ['0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6', '0x1'],
3535
result: '0x31981',
3636
formattedResult: '203137',
37-
call: 'eth_'+ method
37+
call: 'eth_' + method
3838
}, {
3939
args: ['0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', 0x1], // checksum address
4040
formattedArgs: ['0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6', '0x1'],
4141
result: '0x31981',
4242
formattedResult: '203137',
43-
call: 'eth_'+ method
43+
call: 'eth_' + method
4444
},
45-
{
45+
{
4646
args: ['0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6', 0x1],
4747
formattedArgs: ['0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6', '0x1'],
4848
result: '0x31981',
4949
formattedResult: '203137',
50-
call: 'eth_'+ method
50+
call: 'eth_' + method
5151
}, {
5252
args: ['dbdbdb2cbd23b783741e8d7fcf51e459b497e4a6', 0x1],
5353
formattedArgs: ['0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6', '0x1'],
5454
result: '0x31981',
5555
formattedResult: '203137',
56-
call: 'eth_'+ method
56+
call: 'eth_' + method
5757
}, {
5858
args: ['0x000000000000000000000000000000000000012d', 0x1],
5959
formattedArgs: ['0x000000000000000000000000000000000000012d', '0x1'],
6060
result: '0x31981',
6161
formattedResult: '203137',
62-
call: 'eth_'+ method
62+
call: 'eth_' + method
6363
}, {
6464
args: ['0x000000000000000000000000000000000000012d'],
6565
formattedArgs: ['0x000000000000000000000000000000000000012d', 'latest'],
6666
result: '0x31981',
6767
formattedResult: '203137',
68-
call: 'eth_'+ method
68+
call: 'eth_' + method
6969
}, {
7070
args: ['000000000000000000000000000000000000012d'],
7171
formattedArgs: ['0x000000000000000000000000000000000000012d', 'latest'],
7272
result: '0x31981',
7373
formattedResult: '203137',
74-
call: 'eth_'+ method
74+
call: 'eth_' + method
7575
}, {
7676
args: ['XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS'], // iban address
7777
formattedArgs: ['0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', 'latest'],
7878
result: '0x31981',
7979
formattedResult: '203137',
80-
call: 'eth_'+ method
80+
call: 'eth_' + method
81+
}, {
82+
args: ['0x000000000000000000000000000000000000012d'],
83+
formattedArgs: ['0x000000000000000000000000000000000000012d', '0x1'],
84+
result: '0x31981',
85+
formattedResult: '203137',
86+
call: 'eth_' + method,
87+
defaultOptions: [
88+
['defaultBlock', 1]
89+
]
8190
}];
8291

8392
testMethod.runTests('eth', method, tests);

test/helpers/test.method.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,20 @@ var runTests = function (obj, method, tests) {
104104
w3 = web3[obj];
105105
}
106106

107+
if (test.defaultOptions) {
108+
test.defaultOptions.forEach(function(option) {
109+
w3[option[0]] = option[1];
110+
});
111+
}
112+
107113
assert.throws(function(){ w3[method].apply(w3, args); });
108114
} else {
115+
if (test.defaultOptions) {
116+
test.defaultOptions.forEach(function(option) {
117+
w3[option[0]] = option[1];
118+
});
119+
}
120+
109121
assert.throws(function(){ web3[method].apply(web3, args); });
110122
}
111123

@@ -120,8 +132,20 @@ var runTests = function (obj, method, tests) {
120132
w3 = web3[obj];
121133
}
122134

135+
if (test.defaultOptions) {
136+
test.defaultOptions.forEach(function(option) {
137+
w3[option[0]] = option[1];
138+
});
139+
}
140+
123141
result = w3[method].apply(w3, args);
124142
} else {
143+
if (test.defaultOptions) {
144+
test.defaultOptions.forEach(function(option) {
145+
w3[option[0]] = option[1];
146+
});
147+
}
148+
125149
result = web3[method].apply(web3, args);
126150
}
127151

@@ -186,6 +210,12 @@ var runTests = function (obj, method, tests) {
186210
w3 = web3[obj];
187211
}
188212

213+
if (test.defaultOptions) {
214+
test.defaultOptions.forEach(function(option) {
215+
w3[option[0]] = option[1];
216+
});
217+
}
218+
189219
assert.throws(function(){ w3[method].apply(w3, args); });
190220
} else {
191221
assert.throws(function(){ web3[method].apply(web3, args); });
@@ -209,8 +239,20 @@ var runTests = function (obj, method, tests) {
209239
w3 = web3[obj];
210240
}
211241

242+
if (test.defaultOptions) {
243+
test.defaultOptions.forEach(function(option) {
244+
w3[option[0]] = option[1];
245+
});
246+
}
247+
212248
w3[method].apply(w3, args);
213249
} else {
250+
if (test.defaultOptions) {
251+
test.defaultOptions.forEach(function(option) {
252+
w3[option[0]] = option[1];
253+
});
254+
}
255+
214256
web3[method].apply(web3, args);
215257
}
216258
}

0 commit comments

Comments
 (0)