From 502148a176244689765d5ebcaf062129f293b3bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Fri, 28 May 2021 15:54:15 +0200 Subject: [PATCH] test: Add EIP-3198 unit tests --- test/unittests/CMakeLists.txt | 1 + test/unittests/evm_eip3198_basefee_test.cpp | 34 +++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 test/unittests/evm_eip3198_basefee_test.cpp diff --git a/test/unittests/CMakeLists.txt b/test/unittests/CMakeLists.txt index 54940c2b56..a7e60aa506 100644 --- a/test/unittests/CMakeLists.txt +++ b/test/unittests/CMakeLists.txt @@ -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 diff --git a/test/unittests/evm_eip3198_basefee_test.cpp b/test/unittests/evm_eip3198_basefee_test.cpp new file mode 100644 index 0000000000..74607b489c --- /dev/null +++ b/test/unittests/evm_eip3198_basefee_test.cpp @@ -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); +}