Skip to content

Commit

Permalink
generate beacon account in bc version of tests on Cancun
Browse files Browse the repository at this point in the history
  • Loading branch information
winsvega committed Mar 5, 2024
1 parent 0abe77b commit c07f2a5
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 6 deletions.
12 changes: 12 additions & 0 deletions retesteth/testStructures/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,4 +472,16 @@ void checkEmptyStorages(spState _state)
}
}

spAccountBase makeBeaconAccount()
{
spDataObject accountData;
(*accountData).setKey(teststruct::C_FH20_BEACON.asString());
(*accountData)["balance"] = "0x00";
(*accountData)["code"] = "0x3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff015500";
(*accountData)["nonce"] = "0x01";
(*accountData).atKeyPointer("storage") = sDataObject(DataType::Object);
spAccountBase acc(new State::Account(accountData));
return acc;
}

} // namespace teststruct
1 change: 1 addition & 0 deletions retesteth/testStructures/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@ spFH20 convertSecretToPublic(VALUE const& _secret);

void checkEmptyStorages(spState _state);
bool checkEmptyAccounts(spState _state);
spAccountBase makeBeaconAccount();

} // namespace teststruct
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,17 @@ spDataObject BlockchainTestFillerRunner::makeNewBCTestForNet(FORK const& _net)
TestBlockchainManager BlockchainTestFillerRunner::makeTestChainManager(teststruct::FORK const& _net)
{
ETH_DC_MESSAGEC(DC::RPC, "FILL GENESIS INFO: ", LogColor::LIME);
return TestBlockchainManager(m_test.Env(), m_test.Pre(), m_test.sealEngine(), _net);
std::vector<spAccountBase> additionalAccounts;

if (test::compareFork(_net, test::CMP::ge, FORK("Cancun"))
&& !m_test.Pre().hasAccount(teststruct::C_FH20_BEACON))
{
ETH_DC_MESSAGE(DC::RPC, "Retesteth inserts beacon root account into the pre state!");
additionalAccounts.emplace_back(makeBeaconAccount());
}

auto blockchains = TestBlockchainManager(m_test.Env(), m_test.Pre(), m_test.sealEngine(), _net, additionalAccounts);
return blockchains;
}

void BlockchainTestFillerRunner::makeGenesis(spDataObject& _filledTest, TestBlockchainManager& _testchain) const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ namespace blockchainfiller
// _env, _pre, _engine, _network
TestBlockchainManager::TestBlockchainManager(
BlockchainTestFillerEnv const& _genesisEnv,
State const& _genesisPre, SealEngine _engine, FORK const& _network)
State const& _genesisPre, SealEngine _engine, FORK const& _network,
std::vector<spAccountBase> const& _additionalPreAccounts)
: m_session(RPCSession::instance(TestOutputHelper::getThreadID())),
m_sDefaultChainName(BlockchainTestFillerBlock::defaultChainName()),
m_genesisEnv(_genesisEnv),
m_genesisPre(_genesisPre),
m_sealEngine(_engine),
m_sDefaultChainNet(_network)
{
for (auto const& acc : _additionalPreAccounts)
m_genesisPre.addAccount(acc);
m_wasAtLeastOneFork = false;
// m_sCurrentChainName is unknown at this point. the first block of the test defines it
// but we want genesis to be generated anyway before that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class TestBlockchainManager
// _env, _pre, _engine, _network
TestBlockchainManager(
BlockchainTestFillerEnv const& _genesisEnv,
State const& _genesisPre, SealEngine _engine, FORK const& _network);
State const& _genesisPre, SealEngine _engine, FORK const& _network,
std::vector<spAccountBase> const& _additionalPreAccounts);

// Perform block generation logic by parsing the filler file section
std::vector<spDataObject> parseBlockFromFiller(BlockchainTestFillerBlock const& _block, bool _generateUncles);
Expand Down
13 changes: 11 additions & 2 deletions retesteth/testSuites/statetests/StateTestChainRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@ void StateTestChainRunner::prepareChainParams(FORK const& _network)
{
TestInfo errorInfo("test_setChainParams: " + _network.asString(), m_test.testName());
TestOutputHelper::get().setCurrentTestInfo(errorInfo);
auto const p = test::teststruct::prepareChainParams(_network, SealEngine::NoProof, m_test.Pre(), m_test.Env(), ParamsContext::StateTests);
if (compareFork(_network, CMP::ge, FORK("Cancun"))
&& !m_test.Pre().hasAccount(C_FH20_BEACON))
{
ETH_DC_MESSAGE(DC::RPC, "Retesteth inserts beacon root contract into pre!");
m_statePre = spState(new State(m_test.Pre()));
(*m_statePre).addAccount(makeBeaconAccount());
}
else
m_statePre.null();
auto const p = test::teststruct::prepareChainParams(_network, SealEngine::NoProof, m_statePre.isEmpty() ? m_test.Pre() : m_statePre, m_test.Env(), ParamsContext::StateTests);
m_session.test_setChainParams(p);
}

Expand Down Expand Up @@ -114,7 +123,7 @@ void StateTestChainRunner::initBlockchainTestData()
(*m_aBlockchainTest).atKeyPointer("_info") = m_test.Info().rawData();
EthGetBlockBy genesisBlock(m_session.eth_getBlockByNumber(0, Request::FULLOBJECTS));
(*m_aBlockchainTest).atKeyPointer("genesisBlockHeader") = genesisBlock.header()->asDataObject();
(*m_aBlockchainTest).atKeyPointer("pre") = m_test.Pre().asDataObject();
(*m_aBlockchainTest).atKeyPointer("pre") = m_statePre.isEmpty() ? m_test.Pre().asDataObject() : m_statePre->asDataObject();
(*m_aBlockchainTest)["sealEngine"] = sealEngineToStr(SealEngine::NoProof);
(*m_aBlockchainTest)["genesisRLP"] = genesisBlock.getRLPHeaderTransactions().asString();
}
Expand Down
2 changes: 1 addition & 1 deletion retesteth/testSuites/statetests/StateTestChainRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class StateTestChainRunner : public StateTestFillerRunner

private:
spDataObject m_aBlockchainTest;

spState m_statePre;
};

}
28 changes: 28 additions & 0 deletions web/evmone_coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
# Produce lcov html coverage report on evmone for the tests in folder BASE and PATCH
# Make a diff between BASE and PATCH highlighting what new coverage is done by PATCH compared to BASE
# And what coverage is now missing by PATCH compared to BASE
# Results are stored in RESULT variable
# Tests TYPE = BlockchainTests | GeneralStateTests

BASE=$1
PATCH=$2
RESULT=$3
TYPE=$4
BUILD="/evmone/build"

retesteth -t $TYPE -- --testfile $BASE --clients evmone
lcov --capture --directory $BUILD --output-file $BUILD/coverage.lcov --ignore-errors mismatch --exclude="$HOME/.hunter/*" --exclude="$PWD/_deps/*" --exclude="11"
lcov --zerocounters --directory $BUILD
genhtml $BUILD/coverage.lcov --output-directory $RESULT/BASE --title BASE_COVERAGE
cp $BUILD/coverage.lcov $RESULT/coverage_base.lcov

retesteth -t $TYPE -- --testfile $PATCH --clients evmone
lcov --capture --directory $BUILD --output-file $BUILD/coverage.lcov --ignore-errors mismatch --exclude="$HOME/.hunter/*" --exclude="$PWD/_deps/*" --exclude="11"
lcov --zerocounters --directory $BUILD
genhtml $BUILD/coverage.lcov --output-directory $RESULT/PATCH --title PATCH_COVERAGE
cp $BUILD/coverage.lcov $RESULT/coverage_patch.lcov

genhtml $RESULT/coverage_patch.lcov --baseline-file $RESULT/coverage_base.lcov --output-directory $RESULT/DIFF --title DIFF_COVERAGE

#find . -name "*.gcda" -o -name "*.gcno" -exec rm -f {} +

0 comments on commit c07f2a5

Please sign in to comment.