-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
100 additions
and
74 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
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,43 @@ | ||
// evmone: Fast Ethereum Virtual Machine implementation | ||
// Copyright 2023 The evmone Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "state_transition.hpp" | ||
|
||
namespace evmone::test | ||
{ | ||
void state_transition::TearDown() | ||
{ | ||
auto& state = pre; | ||
const auto res = evmone::state::transition(state, block, tx, EVMC_CANCUN, vm); | ||
ASSERT_TRUE(holds_alternative<TransactionReceipt>(res)) | ||
<< std::get<std::error_code>(res).message(); | ||
const auto& receipt = std::get<TransactionReceipt>(res); | ||
|
||
EXPECT_EQ(receipt.status, expect.status); | ||
if (expect.gas_used.has_value()) | ||
{ | ||
EXPECT_EQ(receipt.gas_used, *expect.gas_used); | ||
} | ||
|
||
for (const auto& [a, e] : expect.post) | ||
{ | ||
const auto p = state.find(a); | ||
if (!e.exists) | ||
{ | ||
// TODO: Add printing for address and bytes32. | ||
EXPECT_EQ(p, nullptr) << "account " << hex(a) << " should not exist"; | ||
} | ||
else | ||
{ | ||
ASSERT_NE(p, nullptr) << "account " << hex(a) << " should exist"; | ||
EXPECT_EQ(p->nonce, e.nonce); | ||
|
||
for (const auto& [k, v] : e.storage) | ||
{ | ||
EXPECT_EQ(p->storage.at(k).current, v); | ||
} | ||
} | ||
} | ||
} | ||
} // namespace evmone::test |
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,53 @@ | ||
// evmone: Fast Ethereum Virtual Machine implementation | ||
// Copyright 2023 The evmone Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
#pragma once | ||
|
||
#include <evmone/evmone.h> | ||
#include <gtest/gtest.h> | ||
#include <test/state/host.hpp> | ||
|
||
namespace evmone::test | ||
{ | ||
using namespace evmone::state; | ||
|
||
class state_transition : public testing::Test | ||
{ | ||
protected: | ||
static constexpr auto Sender = 0x8e4d_address; | ||
static constexpr auto To = 0xc0de_address; | ||
|
||
static inline evmc::VM vm{evmc_create_evmone()}; | ||
|
||
struct ExpectedAccount | ||
{ | ||
bool exists = true; | ||
uint64_t nonce = 0; | ||
std::unordered_map<evmc::bytes32, evmc::bytes32> storage; | ||
}; | ||
|
||
struct Expectation | ||
{ | ||
evmc_status_code status = EVMC_SUCCESS; | ||
std::optional<int64_t> gas_used; | ||
|
||
std::unordered_map<evmc::address, ExpectedAccount> post; | ||
}; | ||
|
||
|
||
BlockInfo block{.gas_limit = 1'000'000}; | ||
Transaction tx{.gas_limit = block.gas_limit, .sender = Sender, .to = To}; | ||
|
||
State pre; | ||
Expectation expect; | ||
|
||
state_transition() | ||
{ | ||
pre.insert(tx.sender, {.nonce = 1}); | ||
pre.insert(*tx.to, {.nonce = 1}); | ||
} | ||
|
||
void TearDown() override; | ||
}; | ||
|
||
} // namespace evmone::test |
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