Skip to content

Commit 90f4f80

Browse files
committed
test: Add unit tests for EIP-6780
1 parent 612d896 commit 90f4f80

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

test/unittests/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ target_sources(
5151
state_transition_block_test.cpp
5252
state_transition_create_test.cpp
5353
state_transition_eof_test.cpp
54+
state_transition_selfdestruct_test.cpp
5455
state_transition_trace_test.cpp
5556
state_transition_transient_storage_test.cpp
5657
state_transition_tx_test.cpp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// evmone: Fast Ethereum Virtual Machine implementation
2+
// Copyright 2023 The evmone Authors.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
#include "../utils/bytecode.hpp"
6+
#include "state_transition.hpp"
7+
8+
using namespace evmc::literals;
9+
using namespace evmone::test;
10+
11+
TEST_F(state_transition, selfdestruct_shanghai)
12+
{
13+
rev = EVMC_SHANGHAI;
14+
tx.to = To;
15+
pre.insert(*tx.to, {.balance = 0x4e, .code = selfdestruct(0xbe_address)});
16+
17+
expect.post[To].exists = false;
18+
expect.post[0xbe_address].balance = 0x4e;
19+
}
20+
21+
TEST_F(state_transition, selfdestruct_cancun)
22+
{
23+
rev = EVMC_CANCUN;
24+
tx.to = To;
25+
pre.insert(*tx.to, {.balance = 0x4e, .code = selfdestruct(0xbe_address)});
26+
27+
expect.post[To].balance = 0;
28+
expect.post[0xbe_address].balance = 0x4e;
29+
}
30+
31+
TEST_F(state_transition, selfdestruct_to_self_cancun)
32+
{
33+
rev = EVMC_CANCUN;
34+
tx.to = To;
35+
pre.insert(*tx.to, {.balance = 0x4e, .code = selfdestruct(To)});
36+
37+
expect.post[To].balance = 0x4e;
38+
}
39+
40+
TEST_F(state_transition, selfdestruct_same_tx_cancun)
41+
{
42+
rev = EVMC_CANCUN;
43+
tx.value = 0x4e;
44+
tx.data = selfdestruct(0xbe_address);
45+
pre.get(Sender).balance += 0x4e;
46+
47+
expect.post[0xbe_address].balance = 0x4e;
48+
}

0 commit comments

Comments
 (0)