|
| 1 | +import {assert} from "chai"; |
| 2 | +import sendJsonRpcRequest from "../../helpers/JsonRpcHelper"; |
| 3 | + |
| 4 | +const METHOD = "debug_accountRange"; |
| 5 | +describe(`Otterscan api tests: ${METHOD} #parallel`, function () { |
| 6 | + |
| 7 | + it("We can get addresses from the node", async function () { |
| 8 | + |
| 9 | + const PAGE_NUMBER = 0; |
| 10 | + const PAGE_SIZE = 9; |
| 11 | + |
| 12 | + await sendJsonRpcRequest(METHOD, 1, [PAGE_NUMBER,PAGE_SIZE], (result, status) => { |
| 13 | + assert.equal(status, 200, "has status code"); |
| 14 | + |
| 15 | + let jsonObject = result.result; |
| 16 | + assert.isNotEmpty(jsonObject.addresses, "Can find addresses of accounts on the node"); |
| 17 | + }); |
| 18 | + }); |
| 19 | + |
| 20 | + it("We can see constant ordering between requests", async function () { |
| 21 | + const PAGE_NUMBER_1 = 0; |
| 22 | + const PAGE_SIZE_1 = 3; |
| 23 | + |
| 24 | + let shared_address : string; |
| 25 | + |
| 26 | + await sendJsonRpcRequest(METHOD, 1, [PAGE_NUMBER_1,PAGE_SIZE_1], (result, status) => { |
| 27 | + assert.equal(status, 200, "has status code"); |
| 28 | + |
| 29 | + let jsonObject = result.result; |
| 30 | + shared_address = jsonObject.addresses[2]; |
| 31 | + }); |
| 32 | + |
| 33 | + const PAGE_NUMBER_2 = 1; |
| 34 | + const PAGE_SIZE_2 = 2; |
| 35 | + |
| 36 | + await sendJsonRpcRequest(METHOD, 1, [PAGE_NUMBER_2,PAGE_SIZE_2], (result, status) => { |
| 37 | + assert.equal(status, 200, "has status code"); |
| 38 | + |
| 39 | + let jsonObject = result.result; |
| 40 | + assert.strictEqual(jsonObject.addresses[0], shared_address, "There is consistent ordering of addresses between requests due to overlap"); |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + it("We can view the first address and that there are more to be seen", async function () { |
| 45 | + const PAGE_NUMBER = 0; |
| 46 | + const PAGE_SIZE = 1; |
| 47 | + |
| 48 | + await sendJsonRpcRequest(METHOD, 1, [PAGE_NUMBER,PAGE_SIZE], (result, status) => { |
| 49 | + assert.equal(status, 200, "has status code"); |
| 50 | + |
| 51 | + let jsonObject = result.result; |
| 52 | + assert.isNotEmpty(jsonObject.addresses, "Can find first addresses of accounts"); |
| 53 | + assert.isTrue(jsonObject.wasMore, "Can see that there are more addresses to be fetched"); |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + it("We can reach the end of addresses and see that there are no more to be seen", async function () { |
| 58 | + const PAGE_NUMBER = 20; |
| 59 | + const PAGE_SIZE = 1; |
| 60 | + |
| 61 | + await sendJsonRpcRequest(METHOD, 1, [PAGE_NUMBER,PAGE_SIZE], (result, status) => { |
| 62 | + assert.equal(status, 200, "has status code"); |
| 63 | + |
| 64 | + let jsonObject = result.result; |
| 65 | + assert.isEmpty(jsonObject.addresses, "Can not find addresses outside range of cache"); |
| 66 | + assert.isFalse(jsonObject.wasMore, "Can see that there are no more addresses to be fetched"); |
| 67 | + }); |
| 68 | + }); |
| 69 | +}); |
0 commit comments