Skip to content

Commit

Permalink
new(tests): EOF - EIP-7069: Test EXTCALL creation gas charge (#1025)
Browse files Browse the repository at this point in the history
* Test EXTCALL creation gas charge

Test the creation gas charge of a contract when the contract was called
and remained "empty."

Signed-off-by: Danno Ferrin <[email protected]>

* add "prelude code"

Signed-off-by: Danno Ferrin <[email protected]>

* Apply suggestions from code review

---------

Signed-off-by: Danno Ferrin <[email protected]>
Co-authored-by: Mario Vega <[email protected]>
  • Loading branch information
shemnon and marioevz authored Jan 23, 2025
1 parent f6297b2 commit b1772fc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/osaka/eip7692_eof_v1/eip7069_extcall/test_gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pytest

from ethereum_test_base_types import Address
from ethereum_test_forks import Fork
from ethereum_test_tools import Alloc, Environment, StateTestFiller
from ethereum_test_tools.eof.v1 import Container
Expand Down Expand Up @@ -185,3 +186,35 @@ def test_transfer_gas_is_cleared(
+ push_gas,
out_of_gas_testing=False,
)


@pytest.mark.parametrize("opcode", [Op.EXTCALL, Op.EXTDELEGATECALL, Op.EXTSTATICCALL])
def test_late_account_create(
state_test: StateTestFiller,
pre: Alloc,
state_env: Environment,
opcode: Op,
):
"""
Test EXTCALL to a non-existent account after another EXT*CALL has called it and not
created it.
"""
empty_address = Address(0xDECAFC0DE)

gas_test(
state_test,
state_env,
pre,
prelude_code=Op.BALANCE(address=empty_address),
setup_code=opcode(address=empty_address)
+ Op.PUSH1(1)
+ Op.PUSH0
+ Op.PUSH0
+ Op.PUSH20(empty_address),
subject_code=Op.EXTCALL,
subject_balance=5,
tear_down_code=Op.STOP,
cold_gas=WARM_ACCOUNT_ACCESS_GAS + CALL_WITH_VALUE_GAS + ACCOUNT_CREATION_GAS,
warm_gas=WARM_ACCOUNT_ACCESS_GAS + CALL_WITH_VALUE_GAS,
out_of_gas_testing=False,
)
4 changes: 4 additions & 0 deletions tests/osaka/eip7692_eof_v1/gas_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def gas_test(
subject_balance: int = 0,
oog_difference: int = 1,
out_of_gas_testing: bool = True,
*,
prelude_code: Bytecode | None = None,
):
"""
Create State Test to check the gas cost of a sequence of EOF code.
Expand Down Expand Up @@ -72,6 +74,8 @@ def gas_test(
code=(
# warm subject and baseline without executing
(Op.BALANCE(address_subject) + Op.POP + Op.BALANCE(address_baseline) + Op.POP)
# run any "prelude" code that may have universal side effects
+ prelude_code
# Baseline gas run
+ (
Op.GAS
Expand Down

0 comments on commit b1772fc

Please sign in to comment.