forked from sebs/etherscan-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmethods-test.js
301 lines (276 loc) · 8.2 KB
/
methods-test.js
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
'use strict';
const assert = require('chai').assert;
const init = require('../.').init;
describe('api', function() {
describe('account', function() {
it('getminedblocks', function(done){
var api = init();
var txlist = api.account.getminedblocks('0x9dd134d14d1e65f84b706d6f205cd5b1cd03a46b');
txlist.then(function(res){
assert.ok(res);
done();
});
});
/**
* @deprecated by Etherscan
* https://etherscan.io/apis#tokens
*/
// it('tokenbalance by name', function (done) {
// var api = init();
//
// var supply = api.account.tokenbalance(
// '0x4366ddc115d8cf213c564da36e64c8ebaa30cdbd',
// 'DGD'
// );
// supply.then(function (res) {
// assert.ok(res.result);
// done();
// });
// });
it('tokenbalance by address', function(done) {
var api = init();
var supply = api.account.tokenbalance('0xe04f27eb70e025b78871a2ad7eabe85e61212761', false, '0x57d90b64a1a57749b0f932f1a3395792e12e7055');
supply.then(function(res){
assert.ok(res);
done();
});
});
it('txlist', function(done){
var api = init();
var txlist = api.account.txlist('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae');
txlist.then(function(res){
assert.ok(res);
done();
});
});
it('txlistinternal by hash', function(done){
var api = init();
var txlist = api.account.txlistinternal('0x40eb908387324f2b575b4879cd9d7188f69c8fc9d87c901b9e2daaea4b442170');
txlist.then(function(res){
assert.ok(res);
done();
}).catch(done);
});
it('txlistinternal by address', function(done){
var api = init();
var txlist = api.account.txlistinternal(null, '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae');
txlist.then(function(res) {
assert.ok(res);
done();
});
});
it('balance', function(done){
var api = init();
var balance = api.account.balance('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae');
balance.then(function(res){
assert.ok(res);
done();
});
});
it('balance multi', function(done){
var api = init();
var balance = api.account.balance(['0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae']);
balance.then(function(res){
assert.ok(res);
done();
});
});
it('tokentx', function(done){
var api = init();
var txlist = api.account.tokentx(
'0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae',
'0x6beb418fc6e1958204ac8baddcf109b8e9694966',
1, 'latest', 'asc'
);
txlist.then(function(res){
assert.ok(res);
done();
});
});
});
describe('stats', function(){
it('ethsupply', function(done){
var api = init();
var supply = api.stats.ethsupply();
supply.then(function(res){
assert.ok(res);
done();
});
});
it('tokensupply by tokenname', function(done){
var api = init();
var supply = api.stats.tokensupply('MKR');
supply.then(function(res){
assert.ok(res);
done();
});
});
it('tokensupply by address', function(done){
var api = init();
var supply = api.stats.tokensupply(null, '0x57d90b64a1a57749b0f932f1a3395792e12e7055');
supply.then(function(res){
assert.ok(res);
done();
}).catch(done);
});
it('ethprice', function(done){
var api = init();
var price = api.stats.ethprice();
price.then(function(res){
assert.ok(res);
done();
}).catch(done);
});
});
it('block.getblockreward', function(done){
var api = init();
var blockreward = api.block.getblockreward();
blockreward.then(function(res){
assert.ok(res);
done();
});
});
it('transaction.getstatus', function(done){
var api = init();
var status = api.transaction.getstatus('0x15f8e5ea1079d9a0bb04a4c58ae5fe7654b5b2b4463375ff7ffb490aa0032f3a');
status.then(function(res){
assert.ok(res);
done();
});
});
// test for bug #31
// see https://github.com/sebs/etherscan-api/issues/31
it('contract.getabi for a contract that is not verified by etherscan: error', function(done){
var api = init('test', 'ropsten', 10000);
var abi = api.contract.getabi('0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413');
abi.then(function(){
assert.false(true, 'should not be a success');
}).catch(err=> {
assert.equal(err, 'Contract source code not verified');
done();
});
});
describe('proxy', function() {
it('proxy.eth_blockNumber', function(done){
var api = init();
var res = api.proxy.eth_blockNumber();
res.then(function(res){
assert.ok(res);
done();
});
});
it('proxy.eth_getBlockByNumber', function(done){
var api = init();
var res = api.proxy.eth_getBlockByNumber('0x10d4f');
res.then(function(res){
assert.ok(res);
done();
});
});
it('proxy.eth_getUncleByBlockNumberAndIndex', function(done){
var api = init();
var res = api.proxy.eth_getUncleByBlockNumberAndIndex('0x210A9B', '0x0');
res.then(function(res){
assert.ok(res);
done();
});
});
it('proxy.eth_getBlockTransactionCountByNumber', function(done){
var api = init();
var res = api.proxy.eth_getBlockTransactionCountByNumber('0x10FB78');
res.then(function(res){
assert.ok(res);
done();
});
});
it('proxy.eth_getTransactionByHash', function(done){
var api = init();
var res = api.proxy.eth_getTransactionByHash('0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1');
res.then(function(res){
assert.ok(res);
done();
});
});
it('proxy.eth_getTransactionByBlockNumberAndIndex', function(done){
var api = init();
var res = api.proxy.eth_getTransactionByBlockNumberAndIndex('0x10d4f', '0x0');
res.then(function(res){
assert.ok(res);
done();
});
});
it('proxy.eth_getTransactionCount', function(done){
var api = init();
var res = api.proxy.eth_getTransactionCount('0x2910543af39aba0cd09dbb2d50200b3e800a63d2');
res.then(function(res){
assert.ok(res);
done();
});
});
xit('proxy.eth_sendRawTransaction', function(done){
var api = init();
var res = api.proxy.eth_sendRawTransaction('0xf904808000831cfde080');
res.then(function(res){
assert.ok(res);
done();
});
});
it('proxy.eth_getTransactionReceipt', function(done){
var api = init();
var res = api.proxy.eth_getTransactionReceipt('0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1');
res.then(function(res){
assert.ok(res);
done();
});
});
it('proxy.eth_call', function(done){
var api = init();
var res = api.proxy.eth_call(
'0xAEEF46DB4855E25702F8237E8f403FddcaF931C0',
'0x70a08231000000000000000000000000e16359506c028e51f16be38986ec5746251e9724',
'latest'
);
res.then(function(res){
assert.ok(res);
done();
});
});
it('proxy.eth_getCode', function(done){
var api = init();
var res = api.proxy.eth_getCode('0xf75e354c5edc8efed9b59ee9f67a80845ade7d0c', 'latest');
res.then(function(res){
assert.ok(res);
done();
});
});
it('proxy.eth_getStorageAt', function(done){
var api = init();
var res = api.proxy.eth_getStorageAt('0x6e03d9cce9d60f3e9f2597e13cd4c54c55330cfd', '0x0', 'latest');
res.then(function(res){
assert.ok(res);
done();
});
});
it('proxy.eth_gasPrice', function(done){
var api = init();
var res = api.proxy.eth_gasPrice();
res.then(function(res){
assert.ok(res);
done();
});
});
xit('proxy.eth_estimateGas', function(done){
var api = init();
var res = api.proxy.eth_estimateGas(
'0xf0160428a8552ac9bb7e050d90eeade4ddd52843',
'0xff22',
'0x051da038cc',
'0xffffff'
);
res.then(function(res){
assert.ok(res);
done();
});
});
});
});