From 634837b02fe0f45c9d6b540df430759646244ffa Mon Sep 17 00:00:00 2001 From: lucac-zilliqa Date: Tue, 22 Aug 2023 18:45:28 +0200 Subject: [PATCH 1/7] Implemented filling cache from TrieDB --- src/libData/AccountStore/AccountStore.cpp | 24 ++++++++++++++++++++++ src/libData/AccountStore/AccountStore.h | 8 ++++++++ src/libServer/EthRpcMethods.cpp | 25 +++++++++++++++++++++++ src/libServer/EthRpcMethods.h | 8 ++++++++ src/libServer/IsolatedServer.cpp | 5 +++++ 5 files changed, 70 insertions(+) diff --git a/src/libData/AccountStore/AccountStore.cpp b/src/libData/AccountStore/AccountStore.cpp index 6b393a5e48..1092af51f2 100644 --- a/src/libData/AccountStore/AccountStore.cpp +++ b/src/libData/AccountStore/AccountStore.cpp @@ -19,6 +19,7 @@ #include #include +#include "common/Common.h" #include "libData/AccountStore/AccountStore.h" #include "libData/AccountStore/services/evm/EvmClient.h" #include "libScilla/ScillaClient.h" @@ -843,3 +844,26 @@ void AccountStore::PrintAccountState() { AccountStoreBase::PrintAccountState(); LOG_GENERAL(INFO, "State Root: " << GetStateRootHash()); } + +void AccountStore::FillAddressCache(){ + std::lock(m_mutexTrie, m_mutexDB, m_mutexCache); + std::lock_guard lock1(m_mutexTrie, std::adopt_lock); + std::lock_guard lock2(m_mutexDB, std::adopt_lock); + std::lock_guard lock3(m_mutexCache, std::adopt_lock); + + m_cache.clear(); + + for(auto it = m_state.begin(); it != m_state.end(); ++it){ + std::pairitem = it.at(); + std::array arr; + std::copy(item.first.begin(), item.first.end(), arr.begin()); + m_cache.push_back(arr); + } +} + +void AccountStore::PrintAddressCache(){ + for (const std::array& entry : m_cache) { + std::string address(entry.begin(), entry.end()); + LOG_GENERAL(INFO, "Address: " << address); + } +} diff --git a/src/libData/AccountStore/AccountStore.h b/src/libData/AccountStore/AccountStore.h index 38ebd9610c..023000bd9f 100644 --- a/src/libData/AccountStore/AccountStore.h +++ b/src/libData/AccountStore/AccountStore.h @@ -23,9 +23,11 @@ #include #include #include +#include #include #include "AccountStoreBase.h" +#include "common/Common.h" #include "common/Constants.h" #include "common/Hashes.h" #include "depends/libTrie/TrieDB.h" @@ -75,6 +77,10 @@ class AccountStore : public AccountStoreBase { rpc::UnixDomainSocketServer m_scillaIPCServerConnector; + //cache storing the addresses in m_state + std::vector> m_cache; + std::mutex m_mutexCache; + AccountStore(); ~AccountStore(); @@ -243,6 +249,8 @@ class AccountStore : public AccountStoreBase { bool UpdateStateTrieAll(); void PrintAccountState() override; + void FillAddressCache(); + void PrintAddressCache(); }; #endif // ZILLIQA_SRC_LIBDATA_ACCOUNTSTORE_ACCOUNTSTORE_H_ diff --git a/src/libServer/EthRpcMethods.cpp b/src/libServer/EthRpcMethods.cpp index ffb356edc0..3f28e60f10 100644 --- a/src/libServer/EthRpcMethods.cpp +++ b/src/libServer/EthRpcMethods.cpp @@ -236,6 +236,11 @@ void EthRpcMethods::Init(LookupServer *lookupServer) { jsonrpc::JSON_STRING, NULL), &EthRpcMethods::GetEthMiningI); + m_lookupServer->bindAndAddExternalMethod( + jsonrpc::Procedure("debug_accountRange", jsonrpc::PARAMS_BY_POSITION, + jsonrpc::JSON_STRING, NULL), + &EthRpcMethods::GetDebugAccountRangeI); + m_lookupServer->bindAndAddExternalMethod( jsonrpc::Procedure("eth_coinbase", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), @@ -1188,6 +1193,26 @@ Json::Value EthRpcMethods::GetEthMining() { return Json::Value(false); } +Json::Value EthRpcMethods::GetDebugAccountRange() { + INC_CALLS(GetInvocationsCounter()); + + try { + unique_lock lock( + AccountStore::GetInstance().GetPrimaryMutex()); + + AccountStore::GetInstance().FillAddressCache(); + AccountStore::GetInstance().PrintAddressCache(); + + return Json::Value("this worked."); + } catch (const JsonRpcException &je) { + LOG_GENERAL(INFO, "[Error] getting balance" << je.GetMessage()); + throw je; + } catch (exception &e) { + LOG_GENERAL(INFO, "[Error]" << e.what()); + throw JsonRpcException(ServerBase::RPC_MISC_ERROR, "Unable To Process"); + } +} + std::string EthRpcMethods::GetEthCoinbase() { INC_CALLS(GetInvocationsCounter()); diff --git a/src/libServer/EthRpcMethods.h b/src/libServer/EthRpcMethods.h index d2c170c451..69d43ee34b 100644 --- a/src/libServer/EthRpcMethods.h +++ b/src/libServer/EthRpcMethods.h @@ -24,6 +24,7 @@ #include "libMediator/Mediator.h" #include "libMetrics/Api.h" #include "libUtils/GasConv.h" +#include "libUtils/Logger.h" class LookupServer; @@ -265,6 +266,12 @@ class EthRpcMethods { response = this->GetEthMining(); } + inline virtual void GetDebugAccountRangeI(const Json::Value& /*request*/, + Json::Value& response) { + LOG_MARKER_CONTITIONAL(LOG_SC); + response = this->GetDebugAccountRange(); + } + /** * @brief Handles json rpc 2.0 request on method: eth_coinbase. * Returns the client coinbase address. The coinbase address is the @@ -729,6 +736,7 @@ class EthRpcMethods { Json::Value GetEthUncleCount(); Json::Value GetEthUncleBlock(); Json::Value GetEthMining(); + Json::Value GetDebugAccountRange(); std::string GetEthCoinbase(); Json::Value GetNetListening(); std::string GetNetPeerCount(); diff --git a/src/libServer/IsolatedServer.cpp b/src/libServer/IsolatedServer.cpp index 70cba84b9e..cccbd520b1 100644 --- a/src/libServer/IsolatedServer.cpp +++ b/src/libServer/IsolatedServer.cpp @@ -219,6 +219,11 @@ void IsolatedServer::BindAllEvmMethods() { jsonrpc::JSON_STRING, NULL), &LookupServer::GetEthMiningI); + AbstractServer::bindAndAddMethod( + jsonrpc::Procedure("debug_accountRange", jsonrpc::PARAMS_BY_POSITION, + jsonrpc::JSON_STRING, NULL), + &LookupServer::GetDebugAccountRangeI); + AbstractServer::bindAndAddMethod( jsonrpc::Procedure("eth_getUncleByBlockHashAndIndex", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, From e29a521a4d74590ed632c25cedd8e59752d511ba Mon Sep 17 00:00:00 2001 From: lucac-zilliqa Date: Tue, 22 Aug 2023 19:17:46 +0200 Subject: [PATCH 2/7] Implemented filling cache on update to Trie DB --- src/libData/AccountStore/AccountStore.cpp | 14 +++++++++++-- src/libServer/EthRpcMethods.cpp | 25 ++++++++++++++++++++++- src/libServer/EthRpcMethods.h | 7 +++++++ src/libServer/IsolatedServer.cpp | 5 +++++ 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/libData/AccountStore/AccountStore.cpp b/src/libData/AccountStore/AccountStore.cpp index 1092af51f2..007266907f 100644 --- a/src/libData/AccountStore/AccountStore.cpp +++ b/src/libData/AccountStore/AccountStore.cpp @@ -788,8 +788,18 @@ bool AccountStore::UpdateStateTrie(const Address &address, return false; } - std::lock_guard g(m_mutexTrie); - m_state.insert(DataConversion::StringToCharArray(address.hex()), rawBytes); + std::lock(m_mutexTrie, m_mutexCache); + std::lock_guard lock1(m_mutexTrie, std::adopt_lock); + std::lock_guard lock2(m_mutexCache, std::adopt_lock); + + + zbytes z = DataConversion::StringToCharArray(address.hex()); + if(!m_state.contains(z)){ + std::array arr; + std::copy(z.begin(), z.end(), arr.begin()); + m_cache.push_back(arr); + } + m_state.insert(z, rawBytes); return true; } diff --git a/src/libServer/EthRpcMethods.cpp b/src/libServer/EthRpcMethods.cpp index 3f28e60f10..179daad116 100644 --- a/src/libServer/EthRpcMethods.cpp +++ b/src/libServer/EthRpcMethods.cpp @@ -241,6 +241,11 @@ void EthRpcMethods::Init(LookupServer *lookupServer) { jsonrpc::JSON_STRING, NULL), &EthRpcMethods::GetDebugAccountRangeI); + m_lookupServer->bindAndAddExternalMethod( + jsonrpc::Procedure("debug_printCache", jsonrpc::PARAMS_BY_POSITION, + jsonrpc::JSON_STRING, NULL), + &EthRpcMethods::PrintCacheContentsI); + m_lookupServer->bindAndAddExternalMethod( jsonrpc::Procedure("eth_coinbase", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), @@ -1201,7 +1206,6 @@ Json::Value EthRpcMethods::GetDebugAccountRange() { AccountStore::GetInstance().GetPrimaryMutex()); AccountStore::GetInstance().FillAddressCache(); - AccountStore::GetInstance().PrintAddressCache(); return Json::Value("this worked."); } catch (const JsonRpcException &je) { @@ -1213,6 +1217,25 @@ Json::Value EthRpcMethods::GetDebugAccountRange() { } } +Json::Value EthRpcMethods::PrintCacheContents() { + INC_CALLS(GetInvocationsCounter()); + + try { + unique_lock lock( + AccountStore::GetInstance().GetPrimaryMutex()); + + AccountStore::GetInstance().PrintAddressCache(); + + return Json::Value("Printed contents in log."); + } catch (const JsonRpcException &je) { + LOG_GENERAL(INFO, "[Error] getting balance" << je.GetMessage()); + throw je; + } catch (exception &e) { + LOG_GENERAL(INFO, "[Error]" << e.what()); + throw JsonRpcException(ServerBase::RPC_MISC_ERROR, "Unable To Process"); + } +} + std::string EthRpcMethods::GetEthCoinbase() { INC_CALLS(GetInvocationsCounter()); diff --git a/src/libServer/EthRpcMethods.h b/src/libServer/EthRpcMethods.h index 69d43ee34b..3e448d3af4 100644 --- a/src/libServer/EthRpcMethods.h +++ b/src/libServer/EthRpcMethods.h @@ -272,6 +272,12 @@ class EthRpcMethods { response = this->GetDebugAccountRange(); } + inline virtual void PrintCacheContentsI(const Json::Value& /*request*/, + Json::Value& response) { + LOG_MARKER_CONTITIONAL(LOG_SC); + response = this->PrintCacheContents(); + } + /** * @brief Handles json rpc 2.0 request on method: eth_coinbase. * Returns the client coinbase address. The coinbase address is the @@ -737,6 +743,7 @@ class EthRpcMethods { Json::Value GetEthUncleBlock(); Json::Value GetEthMining(); Json::Value GetDebugAccountRange(); + Json::Value PrintCacheContents(); std::string GetEthCoinbase(); Json::Value GetNetListening(); std::string GetNetPeerCount(); diff --git a/src/libServer/IsolatedServer.cpp b/src/libServer/IsolatedServer.cpp index cccbd520b1..ffeb9c2ef7 100644 --- a/src/libServer/IsolatedServer.cpp +++ b/src/libServer/IsolatedServer.cpp @@ -224,6 +224,11 @@ void IsolatedServer::BindAllEvmMethods() { jsonrpc::JSON_STRING, NULL), &LookupServer::GetDebugAccountRangeI); + AbstractServer::bindAndAddMethod( + jsonrpc::Procedure("debug_printCache", jsonrpc::PARAMS_BY_POSITION, + jsonrpc::JSON_STRING, NULL), + &LookupServer::PrintCacheContentsI); + AbstractServer::bindAndAddMethod( jsonrpc::Procedure("eth_getUncleByBlockHashAndIndex", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, From fb1bcb8333255c3b24bc2bcedeca56232dc6157f Mon Sep 17 00:00:00 2001 From: lucac-zilliqa Date: Wed, 23 Aug 2023 10:39:11 +0200 Subject: [PATCH 3/7] Added mutex lock to PrintAddressCache --- src/libData/AccountStore/AccountStore.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libData/AccountStore/AccountStore.cpp b/src/libData/AccountStore/AccountStore.cpp index 007266907f..c79149a036 100644 --- a/src/libData/AccountStore/AccountStore.cpp +++ b/src/libData/AccountStore/AccountStore.cpp @@ -872,6 +872,7 @@ void AccountStore::FillAddressCache(){ } void AccountStore::PrintAddressCache(){ + std::lock_guard g(m_mutexCache); for (const std::array& entry : m_cache) { std::string address(entry.begin(), entry.end()); LOG_GENERAL(INFO, "Address: " << address); From 866da25b7f6ad895b7625b96b05b80b13342c416 Mon Sep 17 00:00:00 2001 From: lucac-zilliqa Date: Thu, 24 Aug 2023 12:54:03 +0200 Subject: [PATCH 4/7] Implemented core functionality of API function --- src/libData/AccountStore/AccountStore.cpp | 17 +++++++++++++++-- src/libData/AccountStore/AccountStore.h | 1 + src/libServer/EthRpcMethods.cpp | 15 ++++++++++++--- src/libServer/EthRpcMethods.h | 8 ++++---- src/libServer/IsolatedServer.cpp | 3 ++- 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/libData/AccountStore/AccountStore.cpp b/src/libData/AccountStore/AccountStore.cpp index c79149a036..4f783484fe 100644 --- a/src/libData/AccountStore/AccountStore.cpp +++ b/src/libData/AccountStore/AccountStore.cpp @@ -865,7 +865,7 @@ void AccountStore::FillAddressCache(){ for(auto it = m_state.begin(); it != m_state.end(); ++it){ std::pairitem = it.at(); - std::array arr; + std::array arr; std::copy(item.first.begin(), item.first.end(), arr.begin()); m_cache.push_back(arr); } @@ -873,8 +873,21 @@ void AccountStore::FillAddressCache(){ void AccountStore::PrintAddressCache(){ std::lock_guard g(m_mutexCache); - for (const std::array& entry : m_cache) { + for (const std::array& entry : m_cache) { std::string address(entry.begin(), entry.end()); LOG_GENERAL(INFO, "Address: " << address); } + } + +std::vector> AccountStore::GetAccountAddresses(unsigned long pageNumber, unsigned long pageSize, bool &wasMore){ + //TODO: Implement input sanitisation before locking + std::lock_guard g(m_mutexCache); + auto start = pageNumber * pageSize >= m_cache.size() ? m_cache.end() : m_cache.begin() + (pageNumber * pageSize); + wasMore = (pageNumber + 1) * pageSize >= m_cache.size(); + auto end = wasMore ? m_cache.end() : m_cache.begin() + ((pageNumber + 1) * pageSize); + + std::vector> slice(end - start); + std::copy(start, end, slice.begin()); + return slice; +} diff --git a/src/libData/AccountStore/AccountStore.h b/src/libData/AccountStore/AccountStore.h index 023000bd9f..2cc09eaf69 100644 --- a/src/libData/AccountStore/AccountStore.h +++ b/src/libData/AccountStore/AccountStore.h @@ -251,6 +251,7 @@ class AccountStore : public AccountStoreBase { void PrintAccountState() override; void FillAddressCache(); void PrintAddressCache(); + std::vector> GetAccountAddresses(unsigned long pageNumber, unsigned long pageSize, bool &wasMore); }; #endif // ZILLIQA_SRC_LIBDATA_ACCOUNTSTORE_ACCOUNTSTORE_H_ diff --git a/src/libServer/EthRpcMethods.cpp b/src/libServer/EthRpcMethods.cpp index 179daad116..2b458184ed 100644 --- a/src/libServer/EthRpcMethods.cpp +++ b/src/libServer/EthRpcMethods.cpp @@ -238,7 +238,8 @@ void EthRpcMethods::Init(LookupServer *lookupServer) { m_lookupServer->bindAndAddExternalMethod( jsonrpc::Procedure("debug_accountRange", jsonrpc::PARAMS_BY_POSITION, - jsonrpc::JSON_STRING, NULL), + jsonrpc::JSON_STRING, "param01", jsonrpc::JSON_INTEGER, "param02", jsonrpc::JSON_INTEGER, + NULL), &EthRpcMethods::GetDebugAccountRangeI); m_lookupServer->bindAndAddExternalMethod( @@ -1198,15 +1199,23 @@ Json::Value EthRpcMethods::GetEthMining() { return Json::Value(false); } -Json::Value EthRpcMethods::GetDebugAccountRange() { +Json::Value EthRpcMethods::GetDebugAccountRange(unsigned long pageNumber, unsigned long pageSize) { INC_CALLS(GetInvocationsCounter()); try { unique_lock lock( AccountStore::GetInstance().GetPrimaryMutex()); - + //TODO: Remove this line AccountStore::GetInstance().FillAddressCache(); + //TODO: Add input sanitation + bool wasMore = false; + auto addresses = AccountStore::GetInstance().GetAccountAddresses(pageNumber,pageSize, wasMore); + + for (const std::array& entry : addresses) { + std::string address(entry.begin(), entry.end()); + LOG_GENERAL(INFO, "Address: " << address); + } return Json::Value("this worked."); } catch (const JsonRpcException &je) { LOG_GENERAL(INFO, "[Error] getting balance" << je.GetMessage()); diff --git a/src/libServer/EthRpcMethods.h b/src/libServer/EthRpcMethods.h index 3e448d3af4..fa5ef1c322 100644 --- a/src/libServer/EthRpcMethods.h +++ b/src/libServer/EthRpcMethods.h @@ -266,10 +266,10 @@ class EthRpcMethods { response = this->GetEthMining(); } - inline virtual void GetDebugAccountRangeI(const Json::Value& /*request*/, + inline virtual void GetDebugAccountRangeI(const Json::Value& request, Json::Value& response) { - LOG_MARKER_CONTITIONAL(LOG_SC); - response = this->GetDebugAccountRange(); + LOG_MARKER_CONTITIONAL(LOG_SC); + response = this->GetDebugAccountRange(request[0u].asInt64(), request[1u].asInt64()); } inline virtual void PrintCacheContentsI(const Json::Value& /*request*/, @@ -742,7 +742,7 @@ class EthRpcMethods { Json::Value GetEthUncleCount(); Json::Value GetEthUncleBlock(); Json::Value GetEthMining(); - Json::Value GetDebugAccountRange(); + Json::Value GetDebugAccountRange(unsigned long pageNumber, unsigned long pageSize); Json::Value PrintCacheContents(); std::string GetEthCoinbase(); Json::Value GetNetListening(); diff --git a/src/libServer/IsolatedServer.cpp b/src/libServer/IsolatedServer.cpp index ffeb9c2ef7..1ca54574ab 100644 --- a/src/libServer/IsolatedServer.cpp +++ b/src/libServer/IsolatedServer.cpp @@ -221,7 +221,8 @@ void IsolatedServer::BindAllEvmMethods() { AbstractServer::bindAndAddMethod( jsonrpc::Procedure("debug_accountRange", jsonrpc::PARAMS_BY_POSITION, - jsonrpc::JSON_STRING, NULL), + jsonrpc::JSON_STRING, "param01", jsonrpc::JSON_INTEGER, "param02", jsonrpc::JSON_INTEGER, + NULL), &LookupServer::GetDebugAccountRangeI); AbstractServer::bindAndAddMethod( From 41fa5670520d63434d2b529e8016282551f260f8 Mon Sep 17 00:00:00 2001 From: lucac-zilliqa Date: Thu, 24 Aug 2023 17:01:56 +0200 Subject: [PATCH 5/7] Implemeted returning response of debug_accountRange --- src/libServer/EthRpcMethods.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/libServer/EthRpcMethods.cpp b/src/libServer/EthRpcMethods.cpp index 2b458184ed..0ea3e5d9ff 100644 --- a/src/libServer/EthRpcMethods.cpp +++ b/src/libServer/EthRpcMethods.cpp @@ -1211,12 +1211,18 @@ Json::Value EthRpcMethods::GetDebugAccountRange(unsigned long pageNumber, unsign //TODO: Add input sanitation bool wasMore = false; auto addresses = AccountStore::GetInstance().GetAccountAddresses(pageNumber,pageSize, wasMore); + Json::Value response = Json::objectValue; + Json::Value jsonAddresses = Json::arrayValue; + + for (const std::array& entry : addresses) { + std::string address(entry.begin(), entry.end()); + jsonAddresses.append(address); + } - for (const std::array& entry : addresses) { - std::string address(entry.begin(), entry.end()); - LOG_GENERAL(INFO, "Address: " << address); - } - return Json::Value("this worked."); + response["Addresses"] = jsonAddresses; + response["wasMore"] = wasMore; + + return response; } catch (const JsonRpcException &je) { LOG_GENERAL(INFO, "[Error] getting balance" << je.GetMessage()); throw je; From c51f10c72b38ca73f7e0e0c807a8d8d8949fa713 Mon Sep 17 00:00:00 2001 From: lucac-zilliqa Date: Tue, 29 Aug 2023 13:40:52 +0200 Subject: [PATCH 6/7] Implemented tests for "debug_accountRange" --- src/libData/AccountStore/AccountStore.cpp | 4 +- src/libServer/EthRpcMethods.cpp | 2 +- .../test/otterscan/debug_accountRange.ts | 69 +++++++++++++++++++ 3 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 tests/EvmAcceptanceTests/test/otterscan/debug_accountRange.ts diff --git a/src/libData/AccountStore/AccountStore.cpp b/src/libData/AccountStore/AccountStore.cpp index 4f783484fe..e8a65db38a 100644 --- a/src/libData/AccountStore/AccountStore.cpp +++ b/src/libData/AccountStore/AccountStore.cpp @@ -884,8 +884,8 @@ std::vector> AccountStore::GetAccountAddresses(unsigned lo //TODO: Implement input sanitisation before locking std::lock_guard g(m_mutexCache); auto start = pageNumber * pageSize >= m_cache.size() ? m_cache.end() : m_cache.begin() + (pageNumber * pageSize); - wasMore = (pageNumber + 1) * pageSize >= m_cache.size(); - auto end = wasMore ? m_cache.end() : m_cache.begin() + ((pageNumber + 1) * pageSize); + wasMore = (pageNumber + 1) * pageSize < m_cache.size(); + auto end = wasMore ? m_cache.begin() + ((pageNumber + 1) * pageSize) : m_cache.end(); std::vector> slice(end - start); std::copy(start, end, slice.begin()); diff --git a/src/libServer/EthRpcMethods.cpp b/src/libServer/EthRpcMethods.cpp index 0ea3e5d9ff..f670e61262 100644 --- a/src/libServer/EthRpcMethods.cpp +++ b/src/libServer/EthRpcMethods.cpp @@ -1219,7 +1219,7 @@ Json::Value EthRpcMethods::GetDebugAccountRange(unsigned long pageNumber, unsign jsonAddresses.append(address); } - response["Addresses"] = jsonAddresses; + response["addresses"] = jsonAddresses; response["wasMore"] = wasMore; return response; diff --git a/tests/EvmAcceptanceTests/test/otterscan/debug_accountRange.ts b/tests/EvmAcceptanceTests/test/otterscan/debug_accountRange.ts new file mode 100644 index 0000000000..610beddfb8 --- /dev/null +++ b/tests/EvmAcceptanceTests/test/otterscan/debug_accountRange.ts @@ -0,0 +1,69 @@ +import {assert} from "chai"; +import sendJsonRpcRequest from "../../helpers/JsonRpcHelper"; + +const METHOD = "debug_accountRange"; +describe(`Otterscan api tests: ${METHOD} #parallel`, function () { + + it("We can get addresses from the node", async function () { + + const PAGE_NUMBER = 0; + const PAGE_SIZE = 9; + + await sendJsonRpcRequest(METHOD, 1, [PAGE_NUMBER,PAGE_SIZE], (result, status) => { + assert.equal(status, 200, "has status code"); + + let jsonObject = result.result; + assert.isNotEmpty(jsonObject.addresses, "Can find addresses of accounts on the node"); + }); + }); + + it("We can see constant ordering between requests", async function () { + const PAGE_NUMBER_1 = 0; + const PAGE_SIZE_1 = 3; + + let shared_address : string; + + await sendJsonRpcRequest(METHOD, 1, [PAGE_NUMBER_1,PAGE_SIZE_1], (result, status) => { + assert.equal(status, 200, "has status code"); + + let jsonObject = result.result; + shared_address = jsonObject.addresses[2]; + }); + + const PAGE_NUMBER_2 = 1; + const PAGE_SIZE_2 = 2; + + await sendJsonRpcRequest(METHOD, 1, [PAGE_NUMBER_2,PAGE_SIZE_2], (result, status) => { + assert.equal(status, 200, "has status code"); + + let jsonObject = result.result; + assert.strictEqual(jsonObject.addresses[0], shared_address, "There is consistent ordering of addresses between requests due to overlap"); + }); + }); + + it("We can view the first address and that there are more to be seen", async function () { + const PAGE_NUMBER = 0; + const PAGE_SIZE = 1; + + await sendJsonRpcRequest(METHOD, 1, [PAGE_NUMBER,PAGE_SIZE], (result, status) => { + assert.equal(status, 200, "has status code"); + + let jsonObject = result.result; + assert.isNotEmpty(jsonObject.addresses, "Can find first addresses of accounts"); + assert.isTrue(jsonObject.wasMore, "Can see that there are more addresses to be fetched"); + }); + }); + + it("We can reach the end of addresses and see that there are no more to be seen", async function () { + const PAGE_NUMBER = 20; + const PAGE_SIZE = 1; + + await sendJsonRpcRequest(METHOD, 1, [PAGE_NUMBER,PAGE_SIZE], (result, status) => { + assert.equal(status, 200, "has status code"); + + let jsonObject = result.result; + assert.isEmpty(jsonObject.addresses, "Can not find addresses outside range of cache"); + assert.isFalse(jsonObject.wasMore, "Can see that there are no more addresses to be fetched"); + }); + }); +}); From 9bf9414b78890c8fd644ee00f0141e47ac6ef0ed Mon Sep 17 00:00:00 2001 From: lucac-zilliqa Date: Tue, 29 Aug 2023 23:16:50 +0200 Subject: [PATCH 7/7] Fixed debug_accountRange out of bounds test --- tests/EvmAcceptanceTests/test/otterscan/debug_accountRange.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/EvmAcceptanceTests/test/otterscan/debug_accountRange.ts b/tests/EvmAcceptanceTests/test/otterscan/debug_accountRange.ts index 610beddfb8..169b6bef82 100644 --- a/tests/EvmAcceptanceTests/test/otterscan/debug_accountRange.ts +++ b/tests/EvmAcceptanceTests/test/otterscan/debug_accountRange.ts @@ -55,7 +55,7 @@ describe(`Otterscan api tests: ${METHOD} #parallel`, function () { }); it("We can reach the end of addresses and see that there are no more to be seen", async function () { - const PAGE_NUMBER = 20; + const PAGE_NUMBER = Number.MAX_SAFE_INTEGER; const PAGE_SIZE = 1; await sendJsonRpcRequest(METHOD, 1, [PAGE_NUMBER,PAGE_SIZE], (result, status) => {