Skip to content

Commit

Permalink
test: Add unit tests for EIP-6780
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Nov 24, 2023
1 parent d2ecff0 commit 2d31f5b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ target_sources(
state_transition_block_test.cpp
state_transition_create_test.cpp
state_transition_eof_test.cpp
state_transition_selfdestruct_test.cpp
state_transition_trace_test.cpp
state_transition_transient_storage_test.cpp
state_transition_tx_test.cpp
Expand Down
48 changes: 48 additions & 0 deletions test/unittests/state_transition_selfdestruct_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// evmone: Fast Ethereum Virtual Machine implementation
// Copyright 2023 The evmone Authors.
// SPDX-License-Identifier: Apache-2.0

#include "../utils/bytecode.hpp"
#include "state_transition.hpp"

using namespace evmc::literals;
using namespace evmone::test;

TEST_F(state_transition, selfdestruct_shanghai)
{
rev = EVMC_SHANGHAI;
tx.to = To;
pre.insert(*tx.to, {.balance = 0x4e, .code = selfdestruct(0xbe_address)});

expect.post[To].exists = false;
expect.post[0xbe_address].balance = 0x4e;
}

TEST_F(state_transition, selfdestruct_cancun)
{
rev = EVMC_CANCUN;
tx.to = To;
pre.insert(*tx.to, {.balance = 0x4e, .code = selfdestruct(0xbe_address)});

expect.post[To].balance = 0;
expect.post[0xbe_address].balance = 0x4e;
}

TEST_F(state_transition, selfdestruct_to_self_cancun)
{
rev = EVMC_CANCUN;
tx.to = To;
pre.insert(*tx.to, {.balance = 0x4e, .code = selfdestruct(To)});

expect.post[To].balance = 0x4e;
}

TEST_F(state_transition, selfdestruct_same_tx_cancun)
{
rev = EVMC_CANCUN;
tx.value = 0x4e;
tx.data = selfdestruct(0xbe_address);
pre.get(Sender).balance += 0x4e;

expect.post[0xbe_address].balance = 0x4e;
}

0 comments on commit 2d31f5b

Please sign in to comment.