Skip to content

Commit

Permalink
Merge pull request #1778 from skalenetwork/bug/SKALED-1714-testeth-in…
Browse files Browse the repository at this point in the history
…-historic

Bug/skaled 1714 testeth in historic
  • Loading branch information
kladkogex authored Jan 15, 2024
2 parents fc5b582 + 0921108 commit 15cb6a8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ jobs:
ccache --show-stats
- name: Build dependencies
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
export CC=gcc-9
export CXX=g++-9
Expand All @@ -134,6 +133,7 @@ jobs:
rm -f ./libwebsockets-from-git.tar.gz
./build.sh DEBUG=1 PARALLEL_COUNT=$(nproc)
cd ..
- name: Configure all
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
Expand Down Expand Up @@ -282,7 +282,7 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.info

- name: Configure all as historic
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
Expand Down Expand Up @@ -310,3 +310,9 @@ jobs:
- name: Print ccache stats after full historic build
run : |
ccache --show-stats
- name: Testeth historic
run : |
cd build/test
export NO_NTP_CHECK=1
export NO_ULIMIT_CHECK=1
./testeth -t JsonRpcSuite -- --express --verbosity 4
8 changes: 7 additions & 1 deletion libweb3jsonrpc/Eth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ void GappedTransactionIndexCache::ensureCached( BlockNumber _bn,
_readLock.unlock();
_writeLock.lock();

unsigned realBn = _bn;
if ( _bn == LatestBlock )
realBn = client.number();
else if ( _bn == PendingBlock )
realBn = client.number() + 1; // TODO test this case and decide

assert( real2gappedCache.size() <= cacheSize );
if ( real2gappedCache.size() >= cacheSize ) {
real2gappedCache.erase( real2gappedCache.begin() );
Expand All @@ -89,7 +95,7 @@ void GappedTransactionIndexCache::ensureCached( BlockNumber _bn,
pair< h256, unsigned > loc = client.transactionLocation( th );

// ignore transactions with 0 gas usage OR different location!
if ( diff == 0 || client.numberFromHash( loc.first ) != _bn || loc.second != realIndex )
if ( diff == 0 || client.numberFromHash( loc.first ) != realBn || loc.second != realIndex )
continue;

// cache it
Expand Down
43 changes: 33 additions & 10 deletions test/unittests/libweb3jsonrpc/jsonrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3099,15 +3099,36 @@ BOOST_AUTO_TEST_CASE( skip_invalid_transactions ) {
#ifdef HISTORIC_STATE
// 3 check that historic node sees only 3 txns

string explicitNumberStr = to_string(fixture.client->number());

// 1 Block
Json::Value block = fixture.rpcClient->eth_getBlockByNumber("latest", "false");

string bh = block["hash"].asString();

// 2 transaction count
Json::Value cnt = fixture.rpcClient->eth_getBlockTransactionCountByNumber("latest");
BOOST_REQUIRE_EQUAL(cnt.asString(), "0x3");
cnt = fixture.rpcClient->eth_getBlockTransactionCountByNumber(explicitNumberStr);
BOOST_REQUIRE_EQUAL(cnt.asString(), "0x3");
cnt = fixture.rpcClient->eth_getBlockTransactionCountByHash(bh);
BOOST_REQUIRE_EQUAL(cnt.asString(), "0x3");


BOOST_REQUIRE_EQUAL(block["transactions"].size(), 3);
BOOST_REQUIRE_EQUAL(block["transactions"][0]["transactionIndex"], "0x0");
BOOST_REQUIRE_EQUAL(block["transactions"][1]["transactionIndex"], "0x1");
BOOST_REQUIRE_EQUAL(block["transactions"][2]["transactionIndex"], "0x2");

// same with explicit number
block = fixture.rpcClient->eth_getBlockByNumber(explicitNumberStr, "false");

BOOST_REQUIRE_EQUAL(block["transactions"].size(), 3);
BOOST_REQUIRE_EQUAL(block["transactions"][0]["transactionIndex"], "0x0");
BOOST_REQUIRE_EQUAL(block["transactions"][1]["transactionIndex"], "0x1");
BOOST_REQUIRE_EQUAL(block["transactions"][2]["transactionIndex"], "0x2");

// 2 receipts
// 3 receipts
Json::Value r1,r3,r4;
BOOST_REQUIRE_NO_THROW(r1 = fixture.rpcClient->eth_getTransactionReceipt(toJS(h1)));
BOOST_REQUIRE_THROW (fixture.rpcClient->eth_getTransactionReceipt(toJS(h2)), jsonrpc::JsonRpcException);
Expand All @@ -3118,16 +3139,24 @@ BOOST_AUTO_TEST_CASE( skip_invalid_transactions ) {
BOOST_REQUIRE_EQUAL(r3["transactionIndex"], "0x1");
BOOST_REQUIRE_EQUAL(r4["transactionIndex"], "0x2");

// 3 transaction by index
// 4 transaction by index
Json::Value t0 = fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex("latest", "0");
Json::Value t1 = fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex("latest", "1");
Json::Value t2 = fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex("latest", "2");
BOOST_REQUIRE_EQUAL(jsToFixed<32>(t0["hash"].asString()), h1);
BOOST_REQUIRE_EQUAL(jsToFixed<32>(t1["hash"].asString()), h3);
BOOST_REQUIRE_EQUAL(jsToFixed<32>(t2["hash"].asString()), h4);

// same with explicit block number

t0 = fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex(explicitNumberStr, "0");
t1 = fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex(explicitNumberStr, "1");
t2 = fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex(explicitNumberStr, "2");
BOOST_REQUIRE_EQUAL(jsToFixed<32>(t0["hash"].asString()), h1);
BOOST_REQUIRE_EQUAL(jsToFixed<32>(t1["hash"].asString()), h3);
BOOST_REQUIRE_EQUAL(jsToFixed<32>(t2["hash"].asString()), h4);

string bh = r1["blockHash"].asString();
BOOST_REQUIRE_EQUAL(bh, r1["blockHash"].asString());

t0 = fixture.rpcClient->eth_getTransactionByBlockHashAndIndex(bh, "0");
t1 = fixture.rpcClient->eth_getTransactionByBlockHashAndIndex(bh, "1");
Expand All @@ -3137,15 +3166,9 @@ BOOST_AUTO_TEST_CASE( skip_invalid_transactions ) {
BOOST_REQUIRE_EQUAL(jsToFixed<32>(t1["hash"].asString()), h3);
BOOST_REQUIRE_EQUAL(jsToFixed<32>(t2["hash"].asString()), h4);

// 4 transaction by hash
// 5 transaction by hash
BOOST_REQUIRE_THROW (fixture.rpcClient->eth_getTransactionByHash(toJS(h2)), jsonrpc::JsonRpcException);

// 5 transaction count
Json::Value cnt = fixture.rpcClient->eth_getBlockTransactionCountByNumber("latest");
BOOST_REQUIRE_EQUAL(cnt.asString(), "0x3");
cnt = fixture.rpcClient->eth_getBlockTransactionCountByHash(bh);
BOOST_REQUIRE_EQUAL(cnt.asString(), "0x3");

// send it successfully

// make money
Expand Down

0 comments on commit 15cb6a8

Please sign in to comment.