From f0caaa87747b36af7694501b468b337402ece0ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Fri, 10 Mar 2023 21:34:42 +0100 Subject: [PATCH] test: Add test for nonce bump in case of invalid EOF initcode --- test/unittests/CMakeLists.txt | 1 + test/unittests/state_transition_test.cpp | 29 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 test/unittests/state_transition_test.cpp diff --git a/test/unittests/CMakeLists.txt b/test/unittests/CMakeLists.txt index 87f51c1e33..cfa733e06d 100644 --- a/test/unittests/CMakeLists.txt +++ b/test/unittests/CMakeLists.txt @@ -38,6 +38,7 @@ target_sources( state_rlp_test.cpp state_transition.hpp state_transition.cpp + state_transition_test.cpp statetest_loader_block_info_test.cpp statetest_loader_test.cpp statetest_loader_tx_test.cpp diff --git a/test/unittests/state_transition_test.cpp b/test/unittests/state_transition_test.cpp new file mode 100644 index 0000000000..43ab6a74db --- /dev/null +++ b/test/unittests/state_transition_test.cpp @@ -0,0 +1,29 @@ +// 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, eof_invalid_initcode) +{ + // TODO: It is not verified if the address is correct. + static constexpr auto create_address = 0x864bbda5c698ac34b47a9ea3bd4228802cc5ce3b_address; + + pre.get(*tx.to).code = eof1_bytecode(create() + push(1) + OP_SSTORE + OP_STOP, 3); + pre.get(*tx.to).storage[0x01_bytes32] = {.current = 0x01_bytes32, .original = 0x01_bytes32}; + + EXPECT_EQ(pre.get(tx.sender).balance, 1000000'001); + + expect.gas_used = 985407; + + expect.post[tx.sender].nonce = pre.get(tx.sender).nonce + 1; + expect.post[tx.sender].balance = + pre.get(tx.sender).balance - block.base_fee * static_cast(*expect.gas_used); + expect.post[*tx.to].nonce = pre.get(*tx.to).nonce + 1; // CREATE caller's nonce must be bumped + expect.post[*tx.to].storage[0x01_bytes32] = 0x00_bytes32; // CREATE must fail + expect.post[create_address].exists = false; +}