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

Commit c51f10c

Browse files
committed
Implemented tests for "debug_accountRange"
1 parent 41fa567 commit c51f10c

File tree

3 files changed

+72
-3
lines changed

3 files changed

+72
-3
lines changed

src/libData/AccountStore/AccountStore.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,8 +884,8 @@ std::vector<std::array<zbyte, 40>> AccountStore::GetAccountAddresses(unsigned lo
884884
//TODO: Implement input sanitisation before locking
885885
std::lock_guard<std::mutex> g(m_mutexCache);
886886
auto start = pageNumber * pageSize >= m_cache.size() ? m_cache.end() : m_cache.begin() + (pageNumber * pageSize);
887-
wasMore = (pageNumber + 1) * pageSize >= m_cache.size();
888-
auto end = wasMore ? m_cache.end() : m_cache.begin() + ((pageNumber + 1) * pageSize);
887+
wasMore = (pageNumber + 1) * pageSize < m_cache.size();
888+
auto end = wasMore ? m_cache.begin() + ((pageNumber + 1) * pageSize) : m_cache.end();
889889

890890
std::vector<std::array<zbyte, 40>> slice(end - start);
891891
std::copy(start, end, slice.begin());

src/libServer/EthRpcMethods.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ Json::Value EthRpcMethods::GetDebugAccountRange(unsigned long pageNumber, unsign
12191219
jsonAddresses.append(address);
12201220
}
12211221

1222-
response["Addresses"] = jsonAddresses;
1222+
response["addresses"] = jsonAddresses;
12231223
response["wasMore"] = wasMore;
12241224

12251225
return response;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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

Comments
 (0)