Skip to content

Commit bf5711c

Browse files
committed
test: Add tests for gas refund in SELFDESTRUCT
1 parent 715aa42 commit bf5711c

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

test/unittests/evm_state_test.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,28 @@ TEST_P(evm, selfdestruct_with_balance)
397397
host.recorded_account_accesses.clear();
398398
}
399399

400+
TEST_P(evm, selfdestruct_gas_refund)
401+
{
402+
rev = EVMC_BERLIN; // The last revision with gas refund.
403+
const auto code = selfdestruct(0xbe);
404+
execute(code);
405+
EXPECT_GAS_USED(EVMC_SUCCESS, 7603); // Cold access to 0xbe.
406+
EXPECT_EQ(result.gas_refund, 24000);
407+
408+
// Second selfdestruct of the same account.
409+
execute(code);
410+
EXPECT_GAS_USED(EVMC_SUCCESS, 5003); // Warm access to 0xbe.
411+
EXPECT_EQ(result.gas_refund, 0); // No refund.
412+
}
413+
414+
TEST_P(evm, selfdestruct_no_gas_refund)
415+
{
416+
rev = EVMC_LONDON; // Since London there is no gas refund.
417+
execute(selfdestruct(0xbe));
418+
EXPECT_GAS_USED(EVMC_SUCCESS, 7603);
419+
EXPECT_EQ(result.gas_refund, 0);
420+
}
421+
400422

401423
TEST_P(evm, blockhash)
402424
{

test/unittests/evm_storage_test.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
/// This file contains EVM unit tests that access or modify the contract storage.
66

77
#include "evm_fixture.hpp"
8+
#include <array>
89

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

0 commit comments

Comments
 (0)