-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
statetest: Implement state test runner
- Loading branch information
Showing
4 changed files
with
62 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,5 @@ target_sources( | |
statetest.hpp | ||
statetest.cpp | ||
statetest_loader.cpp | ||
statetest_runner.cpp | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// evmone: Fast Ethereum Virtual Machine implementation | ||
// Copyright 2022 The evmone Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "../state/mpt_hash.hpp" | ||
#include "../state/rlp.hpp" | ||
#include "statetest.hpp" | ||
#include <gtest/gtest.h> | ||
|
||
namespace evmone::state | ||
{ | ||
/// Defines how to RLP-encode a Log. This is only needed to compute "logs hash". | ||
inline bytes rlp_encode(const Log& log) | ||
{ | ||
return rlp::encode_tuple(log.addr, log.topics, log.data); | ||
} | ||
} // namespace evmone::state | ||
|
||
namespace evmone::test | ||
{ | ||
void run_state_test(const StateTransitionTest& test, evmc::VM& vm) | ||
{ | ||
for (const auto& [rev, cases] : test.cases) | ||
{ | ||
for (size_t case_index = 0; case_index != cases.size(); ++case_index) | ||
{ | ||
SCOPED_TRACE(std::string{evmc::to_string(rev)} + '/' + std::to_string(case_index)); | ||
// if (rev != EVMC_FRONTIER) | ||
// continue; | ||
// if (case_index != 3) | ||
// continue; | ||
|
||
const auto& expected = cases[case_index]; | ||
const auto tx = test.multi_tx.get(expected.indexes); | ||
auto state = test.pre_state; | ||
|
||
const auto tx_logs = state::transition(state, test.block, tx, rev, vm); | ||
if (tx_logs.has_value()) | ||
EXPECT_EQ(keccak256(rlp::encode(*tx_logs)), expected.logs_hash); | ||
else | ||
EXPECT_TRUE(expected.exception); | ||
|
||
EXPECT_EQ(state::mpt_hash(state.get_accounts()), expected.state_hash); | ||
} | ||
} | ||
} | ||
} // namespace evmone::test |