Skip to content

Commit

Permalink
test: Add tests for gas refund in SELFDESTRUCT
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Aug 18, 2022
1 parent 715aa42 commit bf5711c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/unittests/evm_state_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,28 @@ TEST_P(evm, selfdestruct_with_balance)
host.recorded_account_accesses.clear();
}

TEST_P(evm, selfdestruct_gas_refund)
{
rev = EVMC_BERLIN; // The last revision with gas refund.
const auto code = selfdestruct(0xbe);
execute(code);
EXPECT_GAS_USED(EVMC_SUCCESS, 7603); // Cold access to 0xbe.
EXPECT_EQ(result.gas_refund, 24000);

// Second selfdestruct of the same account.
execute(code);
EXPECT_GAS_USED(EVMC_SUCCESS, 5003); // Warm access to 0xbe.
EXPECT_EQ(result.gas_refund, 0); // No refund.
}

TEST_P(evm, selfdestruct_no_gas_refund)
{
rev = EVMC_LONDON; // Since London there is no gas refund.
execute(selfdestruct(0xbe));
EXPECT_GAS_USED(EVMC_SUCCESS, 7603);
EXPECT_EQ(result.gas_refund, 0);
}


TEST_P(evm, blockhash)
{
Expand Down
1 change: 1 addition & 0 deletions test/unittests/evm_storage_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/// This file contains EVM unit tests that access or modify the contract storage.

#include "evm_fixture.hpp"
#include <array>

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

0 comments on commit bf5711c

Please sign in to comment.