Skip to content

Commit f6922d2

Browse files
committed
test: Add unit tests for system call execution
1 parent 547f9ed commit f6922d2

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

test/unittests/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ target_sources(
4646
state_new_account_address_test.cpp
4747
state_precompiles_test.cpp
4848
state_rlp_test.cpp
49+
state_system_call_test.cpp
4950
state_transition.hpp
5051
state_transition.cpp
5152
state_transition_block_test.cpp
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// evmone: Fast Ethereum Virtual Machine implementation
2+
// Copyright 2023 The evmone Authors.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
#include <evmone/evmone.h>
6+
#include <gtest/gtest.h>
7+
#include <test/state/state.hpp>
8+
#include <test/utils/bytecode.hpp>
9+
10+
using namespace evmc;
11+
using namespace evmone::state;
12+
13+
TEST(state_system_call, non_existient)
14+
{
15+
evmc::VM vm;
16+
State state;
17+
18+
system_call(state, {}, EVMC_CANCUN, vm);
19+
20+
EXPECT_EQ(state.get_accounts().size(), 0);
21+
}
22+
23+
TEST(state_system_call, sstore_timestamp)
24+
{
25+
static constexpr auto BeaconRootsAddress = 0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02_address;
26+
27+
evmc::VM vm{evmc_create_evmone()};
28+
const BlockInfo block{.number = 1, .timestamp = 404};
29+
State state;
30+
state.insert(BeaconRootsAddress, {.code = sstore(OP_NUMBER, OP_TIMESTAMP)});
31+
32+
system_call(state, block, EVMC_CANCUN, vm);
33+
34+
ASSERT_EQ(state.get_accounts().size(), 1);
35+
EXPECT_EQ(state.get(BeaconRootsAddress).nonce, 0);
36+
EXPECT_EQ(state.get(BeaconRootsAddress).balance, 0);
37+
const auto& storage = state.get(BeaconRootsAddress).storage;
38+
ASSERT_EQ(storage.size(), 1);
39+
EXPECT_EQ(storage.at(0x01_bytes32).current, 404);
40+
}

0 commit comments

Comments
 (0)