Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Jan 10, 2023
1 parent 657cadc commit 6a43509
Showing 1 changed file with 16 additions and 46 deletions.
62 changes: 16 additions & 46 deletions test/unittests/evm_eip3860_initcode_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,24 @@ inline constexpr size_t initcode_size_limit = 0xc000;
TEST_P(evm, create_initcode_limit)
{
host.call_result.create_address = 0x02_address;
const auto code = create().input(0, calldataload(0)) + ret_top();
for (const auto r : {EVMC_PARIS, EVMC_SHANGHAI})
for (const auto& c : {create().input(0, calldataload(0)) + ret_top(),
create2().input(0, calldataload(0)) + ret_top()})
{
rev = r;
for (const auto s : {initcode_size_limit, initcode_size_limit + 1})
for (const auto r : {EVMC_PARIS, EVMC_SHANGHAI})
{
execute(code, evmc::uint256be{s});
EXPECT_STATUS(EVMC_SUCCESS);
const unsigned expected_output =
rev >= EVMC_SHANGHAI && s > initcode_size_limit ? 0 : 2;
EXPECT_OUTPUT_INT(expected_output);
}
}
}

TEST_P(evm, create2_initcode_limit)
{
host.call_result.create_address = 0x02_address;
const auto code = create2().input(0, calldataload(0)) + ret_top();
for (const auto r : {EVMC_PARIS, EVMC_SHANGHAI})
{
rev = r;
for (const auto s : {initcode_size_limit, initcode_size_limit + 1})
{
execute(code, evmc::uint256be{s});
EXPECT_STATUS(EVMC_SUCCESS);
const unsigned expected_output =
rev >= EVMC_SHANGHAI && s > initcode_size_limit ? 0 : 2;
EXPECT_OUTPUT_INT(expected_output);
rev = r;
for (const auto s : {initcode_size_limit, initcode_size_limit + 1})
{
execute(c, evmc::uint256be{s});
if (rev >= EVMC_SHANGHAI && s > initcode_size_limit)
{
EXPECT_STATUS(EVMC_OUT_OF_GAS);
}
else
{
EXPECT_OUTPUT_INT(2);
}
}
}
}
}
Expand All @@ -67,22 +56,3 @@ TEST_P(evm, create2_initcode_gas_cost)
execute(53518, code, evmc::uint256be{initcode_size_limit});
EXPECT_STATUS(EVMC_OUT_OF_GAS);
}

TEST_P(evm, create2_stack_check)
{
// Checks if CREATE2 properly handles values on EVM stack.
rev = EVMC_SHANGHAI;
host.call_result.create_address = 0xca_address;
const auto code =
push(0x84) + create2().input(0, calldataload(0)).salt(0x42) + sstore(0) + sstore(1);

for (const auto& input : {0xC000_bytes32, 0xC001_bytes32})
{
execute(code, input);
EXPECT_STATUS(EVMC_SUCCESS);
auto& storage = host.accounts[msg.recipient].storage;
EXPECT_EQ(
storage[0x00_bytes32].current, input == 0xC001_bytes32 ? 0x00_bytes32 : 0xca_bytes32);
EXPECT_EQ(storage[0x01_bytes32].current, 0x84_bytes32);
}
}

0 comments on commit 6a43509

Please sign in to comment.