Skip to content

Commit

Permalink
test: Add test for nonce bump in case of invalid EOF initcode
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Apr 12, 2023
1 parent 5bd9cc2 commit d350363
Show file tree
Hide file tree
Showing 2 changed files with 31 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 @@ -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
Expand Down
30 changes: 30 additions & 0 deletions test/unittests/state_transition_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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: Correction of this address is not verified.
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 + tx.max_priority_gas_price) * static_cast<uint64_t>(*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;
}

0 comments on commit d350363

Please sign in to comment.