Skip to content

Commit

Permalink
test: Option to check state root hash
Browse files Browse the repository at this point in the history
Add option to check the expected post state MPT root hash
of the state_transition tests.
  • Loading branch information
chfast committed Feb 2, 2024
1 parent 1580602 commit fd1e894
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/unittests/state_transition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ void state_transition::TearDown()
}
}

if (expect.state_hash)
{
EXPECT_EQ(mpt_hash(state.get_accounts()), *expect.state_hash);
}

for (const auto& [addr, _] : state.get_accounts())
{
EXPECT_TRUE(expect.post.contains(addr)) << "unexpected account " << addr;
Expand Down
2 changes: 2 additions & 0 deletions test/unittests/state_transition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class state_transition : public testing::Test
/// The expected post-execution state.
std::unordered_map<address, ExpectedAccount> post;

std::optional<hash256> state_hash;

/// The expected EVM execution trace. If not empty transaction execution will be performed
/// with tracing enabled and the output compared.
std::string_view trace;
Expand Down
11 changes: 11 additions & 0 deletions test/unittests/state_transition_create_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ TEST_F(state_transition, create2_factory)
expect.post[create_address].code = bytes{0xFE};
}

TEST_F(state_transition, create_tx_empty)
{
// The default transaction without "to" address is a create transaction.

expect.post[compute_create_address(Sender, pre.get(Sender).nonce)] = {
.nonce = 1, .code = bytes{}};

// Example of checking the expected the post state MPT root hash.
expect.state_hash = 0x8ae438f7a4a14dbc25410dfaa12e95e7b36f311ab904b4358c3b544e06df4c50_bytes32;
}

TEST_F(state_transition, create_tx)
{
tx.data = mstore8(0, push(0xFE)) + ret(0, 1);
Expand Down

0 comments on commit fd1e894

Please sign in to comment.