-
Notifications
You must be signed in to change notification settings - Fork 13
/
test.js
370 lines (340 loc) · 11.1 KB
/
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
const rpcClass = require('monero-rpc-client');
const WALLET_ADDRESS = '46sKRpY9ULrhA7QVWxZ1VPWmTeU56CBfUNeCey5xDRsBMXnxP5fyBvYWYTH5xEnPuUJtiHcJNHJZ9fgsfkxbAS2zVhS7DBm';
const NODE_ADDRESS = 'http://node.moneroworld.com:18089';
const rpc = new rpcClass(NODE_ADDRESS, true);
const chai = require('chai');
const expect = chai.expect;
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
describe('rpcClient', () => {
it('should instantiate correctly with 1 parameter', () => {
const rpc = new rpcClass('MyNodeAddress');
expect(rpc).to.have.property('nodeAddress', 'MyNodeAddress');
expect(rpc).to.have.property('deserializeJSON', true);
});
it('should instantiate correctly with 2 parameters, deserializeJSON set to true', () => {
const rpc = new rpcClass('MyNodeAddress', true);
expect(rpc).to.have.property('nodeAddress', 'MyNodeAddress');
expect(rpc).to.have.property('deserializeJSON', true);
});
it('should instantiate correctly with 2 parameters, deserializeJSON set to false', () => {
const rpc = new rpcClass('MyNodeAddress', false);
expect(rpc).to.have.property('nodeAddress', 'MyNodeAddress');
expect(rpc).to.have.property('deserializeJSON', false);
});
})
describe('_buildJSONRPCReq()', () => {
it('should successfully build a request for RPC method without parameters', () => {
const rpc = new rpcClass("MyNodeAddress");
const req = rpc._buildJSONRPCReq('getblockcount', undefined)
const expectedReq = {
url: 'MyNodeAddress/json_rpc',
body: '{"jsonrpc":"2.0","id":"0","method":"getblockcount"}'
};
expect(req).to.deep.equal(expectedReq);
});
it('should successfully build a request for RPC method with parameters', () => {
const rpc = new rpcClass("MyNodeAddress1");
const req = rpc._buildJSONRPCReq('on_getblockhash', [1000])
const expectedReq = {
url: 'MyNodeAddress1/json_rpc',
body: '{"jsonrpc":"2.0","id":"0","method":"on_getblockhash","params":[1000]}'
};
expect(req).to.deep.equal(expectedReq);
});
});
describe('_buildOtherRPCReq()', () => {
it('should successfully build a request for Other RPC method without parameters', () => {
const rpc = new rpcClass("MyNodeAddress");
const req = rpc._buildOtherRPCReq('getheight', undefined)
const expectedReq = {
url: 'MyNodeAddress/getheight',
};
expect(req).to.deep.equal(expectedReq);
});
it('should successfully build a request for Other RPC method with parameters', () => {
const rpc = new rpcClass("MyNodeAddress1");
const req = rpc._buildOtherRPCReq('gettransactions',
{txs_hashes: ["d6e48158472848e6687173a91ae6eebfa3e1d778e65252ee99d7515d63090408"]})
const expectedReq = {
url: 'MyNodeAddress1/gettransactions',
body: '{"txs_hashes":["d6e48158472848e6687173a91ae6eebfa3e1d778e65252ee99d7515d63090408"]}'
};
expect(req).to.deep.equal(expectedReq);
});
});
describe('getBlockCount()', () => {
it('should retrieve block count', () => {
return expect(rpc.getBlockCount())
.to
.eventually
.contain('"status": "OK"')
.and
.contain('"count":');
});
});
describe('onGetblockHash()', () => {
it('should retrieve block hash', () => {
return expect(rpc.onGetBlockHash(1000))
.to
.eventually
.contain('"result"');
});
});
describe('getBlockTemplate()', () => {
/**
* Successfuly calls
*/
it('should retrieve block template with object argument', () => {
const args = ({
wallet_address: WALLET_ADDRESS,
reserve_size: 8
});
return expect(rpc.getBlockTemplate(args))
.to
.eventually
.contain('"status": "OK"')
.and
.contain('"blocktemplate_blob"');
});
/**
* Unsuccesful calls
*/
it('should NOT retrieve block template with a non-object argument', () => {
return expect(rpc.getBlockTemplate(''))
.to
.be
.rejected;
});
// `wallet_address` field
it('should NOT retrieve block template with missing `wallet_address` field', () => {
return expect(rpc.getBlockTemplate({reserve_size: 8}))
.to
.be
.rejected;
});
it('should NOT retrieve block template with empty `wallet_address` field', () => {
return expect(rpc.getBlockTemplate({wallet_address: '', reserve_size: 8}))
.to
.be
.rejected;
});
it('should NOT retrieve block template with wrong `wallet_address` field', () => {
return expect(rpc.getBlockTemplate({wallet_address: 12345678, reserve_size: 8}))
.to
.be
.rejected;
});
// `reserve_size` field
it('should NOT retrieve block template with missing `reserve_size` field', () => {
return expect(rpc.getBlockTemplate({wallet_address: WALLET_ADDRESS}))
.to
.be
.rejected;
});
it('should NOT retrieve block template with wrong `reserve_size` field', () => {
return expect(rpc.getBlockTemplate(
{
wallet_address: WALLET_ADDRESS,
reserve_size: 'Im the wrong type'
}))
.to
.be
.rejected;
});
});
/**
* @TODO: build blob data
*/
//describe('submitBlock()', () => {
// it('should successfully submit block', () => {
// return expect(rpc.submitBlock('blob data here'))
// .to
// .eventually
// .contain('"status": "OK"');
// });
//});
describe('getLastBlockHeader()', () => {
it('should successfully retrieve last block header', () => {
return expect(rpc.getLastBlockHeader())
.to
.eventually
.contain('"status": "OK"')
.and
.contain('"block_header"');
});
});
describe('getBlockHeaderByHash()', () => {
it('should successfully retrieve the block header referenced by its hash object', () => {
const args = {hash: 'e22cf75f39ae720e8b71b3d120a5ac03f0db50bba6379e2850975b4859190bc6'};
return expect(rpc.getBlockHeaderByHash(args))
.to
.eventually
.contain('"status": "OK"')
.and
.contain('"block_header"');
});
});
describe('getBlockHeaderByHeight()', () => {
it('should successfully retrieve the block header referenced by its height', () => {
const args = {height: 912345};
return expect(rpc.getBlockHeaderByHeight(args))
.to
.eventually
.contain('"status": "OK"')
.and
.contain('"block_header"');
});
});
describe('getBlock()', () => {
it('should successfully retrieve the block referenced by its height', () => {
const args = {height: 912345};
return expect(rpc.getBlock(args))
.to
.eventually
.contain('"status": "OK"')
.and
.contain('"block_header"')
.and
.contain('"json":');
});
});
/**
* @TODO: find why it doesnt work. Maybe moneronode doesnt allow this method?
*/
//describe('getConnections()', () => {
// it('should successfully retrieve connections info', () => {
// return expect(rpc.getConnections())
// .to
// .eventually
// .contain('"status": "OK"')
// .and
// .contain('connections');
// });
//});
//
describe('getInfo()', () => {
it('should successfully retrieve information about the network', () => {
return expect(rpc.getInfo())
.to
.eventually
.contain('"status": "OK"')
.and
.contain('top_block_hash');
});
});
describe('hardForkInfo()', () => {
it('should successfully retrieve hard fork info', () => {
return expect(rpc.hardForkInfo())
.to
.eventually
.contain('earliest_height');
});
});
/**
* Not possible to test this with moneroworld (make sense)
*/
//describe('setBans()', () => {
// it('should successfully bans a list of ips for a set duration', () => {
// const bans = {
// ip: 12.12.12.12,
// ban: true,
// seconds: 1000
// };
// return expect(rpc.setBans(bans))
// .to
// .eventually
// .contain('"status": "OK"');
// });
//});
/**
* Not possible to test this with moneroworld (make sense)
*/
//describe('getBans()', () => {
// it('should successfully retrieve list of banned nodes', () => {
// return expect(rpc.getBans())
// .to
// .eventually
// .contain('bans')
// .and
// .contain('"status": "OK"');
// });
//});
describe('getHeight()', () => {
it('should successfully retrieve the current height', () => {
return expect(rpc.getHeight())
.to
.eventually
.contain('height')
.and
.contain('"status": "OK"');
});
});
describe('getTransactions()', () => {
it('should successfully retrieve a few transactions by hash with JSON', () => {
const txs_hashes = ["d6e48158472848e6687173a91ae6eebfa3e1d778e65252ee99d7515d63090408"];
const decode_as_json = true;
return expect(rpc.getTransactions({txs_hashes, decode_as_json}))
.to
.eventually
.contain("txs_as_hex")
.and
.contain('txs_as_json')
.and
.contain('"status": "OK"');
});
it('should successfully retrieve a few transactions by hash', () => {
const txs_hashes = ["d6e48158472848e6687173a91ae6eebfa3e1d778e65252ee99d7515d63090408"];
const decode_as_json = false;
return expect(rpc.getTransactions({txs_hashes, decode_as_json}))
.to
.eventually
.contain('txs_as_hex')
.and
.contain('"status": "OK"');
});
});
describe('isKeyImageSpent()', () => {
it('should successfully retrieve the spend status of an array of key images', () => {
const key_images = ["8d1bd8181bf7d857bdb281e0153d84cd55a3fcaa57c3e570f4a49f935850b5e3","7319134bfc50668251f5b899c66b005805ee255c136f0e1cecbb0f3a912e09d4"];
return expect(rpc.isKeyImageSpent({key_images}))
.to
.eventually
.contain('spent_status')
.and
.contain('"status": "OK"');
});
});
/**
* @TODO: Build a tx_as_hex to test
*/
//describe('sendRawTransaction()', () => {
// it('should successfully send a raw transaction', () => {
// const tx_as_hex = "ae634..";
// return expect(rpc.sendRawTransaction({tx_as_hex}))
// .to
// .eventually
// .contain('"status": "OK"');
// });
//});
describe('getTransactionPool()', () => {
it('should successfully retrieve the transaction pool', () => {
return expect(rpc.getTransactionPool())
.to
.eventually
.contain('transactions')
.and
.contain('"status": "OK"');
});
});
/**
* Cannot test this with moneroworld"
*/
//describe('stop_daemon', () => {
// it('should successfully stop the daemon', () => {
// return expect(rpc.stopDaemon())
// .to
// .eventually
// .contain('"status": "OK"');
// });
//;