Skip to content

Commit

Permalink
test: Add EIP-3198 unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed May 28, 2021
1 parent 505eb74 commit 502148a
Show file tree
Hide file tree
Showing 2 changed files with 35 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 @@ -14,6 +14,7 @@ add_executable(evmone-unittests
evm_test.cpp
evm_calls_test.cpp
evm_eip2929_test.cpp
evm_eip3198_basefee_test.cpp
evm_state_test.cpp
evm_other_test.cpp
evmone_test.cpp
Expand Down
34 changes: 34 additions & 0 deletions test/unittests/evm_eip3198_basefee_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// evmone: Fast Ethereum Virtual Machine implementation
// Copyright 2021 The evmone Authors.
// SPDX-License-Identifier: Apache-2.0

/// This file contains EVM unit tests for EIP-3198 "BASEFEE opcode"
/// https://eips.ethereum.org/EIPS/eip-3198

#include "evm_fixture.hpp"

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

TEST_P(evm, basefee_pre_london)
{
rev = EVMC_BERLIN;
const auto code = bytecode{OP_BASEFEE};

execute(code);
EXPECT_STATUS(EVMC_UNDEFINED_INSTRUCTION);
}

TEST_P(evm, basefee_nominal_case)
{
// https://eips.ethereum.org/EIPS/eip-3198#nominal-case
rev = EVMC_LONDON;
host.tx_context.block_base_fee = evmc::bytes32{7};

execute(bytecode{} + OP_BASEFEE + OP_STOP);
EXPECT_GAS_USED(EVMC_SUCCESS, 2);

execute(bytecode{} + OP_BASEFEE + ret_top());
EXPECT_GAS_USED(EVMC_SUCCESS, 17);
EXPECT_OUTPUT_INT(7);
}

0 comments on commit 502148a

Please sign in to comment.