Skip to content

Commit

Permalink
refactor(tests): Use fork gas calc functions
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed Oct 31, 2024
1 parent c83a0e2 commit 3e2ec92
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
9 changes: 5 additions & 4 deletions tests/osaka/eip7692_eof_v1/eip7069_extcall/test_gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import pytest

from ethereum_test_forks import Fork
from ethereum_test_tools import Alloc, Environment, StateTestFiller
from ethereum_test_tools.eof.v1 import Container
from ethereum_test_tools.vm.opcode import Opcodes as Op
from ethereum_test_types.helpers import cost_memory_bytes

from .. import EOF_FORK_NAME
from ..gas_test import gas_test
Expand Down Expand Up @@ -114,6 +114,7 @@ def state_env() -> Environment:
def test_ext_calls_gas(
state_test: StateTestFiller,
pre: Alloc,
fork: Fork,
state_env: Environment,
opcode: Op,
pre_setup: Op,
Expand All @@ -126,7 +127,7 @@ def test_ext_calls_gas(
address_target = (
pre.fund_eoa(0) if new_account else pre.deploy_contract(Container.Code(Op.STOP))
)

cost_memory_bytes = fork.memory_expansion_gas_calculator()
gas_test(
state_test,
state_env,
Expand All @@ -137,8 +138,8 @@ def test_ext_calls_gas(
+ Op.PUSH20(address_target),
subject_code=opcode,
tear_down_code=Op.STOP,
cold_gas=cold_gas + cost_memory_bytes(mem_expansion_bytes, 0),
warm_gas=warm_gas + cost_memory_bytes(mem_expansion_bytes, 0),
cold_gas=cold_gas + cost_memory_bytes(new_bytes=mem_expansion_bytes),
warm_gas=warm_gas + cost_memory_bytes(new_bytes=mem_expansion_bytes),
)


Expand Down
7 changes: 4 additions & 3 deletions tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import pytest

from ethereum_test_forks import Fork
from ethereum_test_tools import Alloc, Environment, StateTestFiller, compute_eofcreate_address
from ethereum_test_tools.eof.v1 import Container, Section
from ethereum_test_tools.vm.opcode import Opcodes as Op
from ethereum_test_types.helpers import cost_memory_bytes

from .. import EOF_FORK_NAME
from ..gas_test import gas_test
Expand Down Expand Up @@ -115,6 +115,7 @@ def make_factory(initcode: Container):
def test_eofcreate_gas(
state_test: StateTestFiller,
pre: Alloc,
fork: Fork,
value: int,
new_account: bool,
mem_expansion_bytes: int,
Expand All @@ -139,7 +140,7 @@ def test_eofcreate_gas(
code_increment_counter = (
Op.TLOAD(slot_counter) + Op.DUP1 + Op.TSTORE(slot_counter, Op.PUSH1(1) + Op.ADD)
)

cost_memory_bytes = fork.memory_expansion_gas_calculator()
gas_test(
state_test,
Environment(),
Expand All @@ -151,7 +152,7 @@ def test_eofcreate_gas(
subject_code=Op.EOFCREATE[0],
tear_down_code=Op.STOP,
cold_gas=EOFCREATE_GAS
+ cost_memory_bytes(mem_expansion_bytes, 0)
+ cost_memory_bytes(new_bytes=mem_expansion_bytes)
+ initcode_hashing_cost
+ initcode_execution_cost
+ deployed_code_cost,
Expand Down
28 changes: 13 additions & 15 deletions tests/prague/eip7702_set_code_tx/test_gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import pytest

from ethereum_test_forks import Fork
from ethereum_test_tools import (
EOA,
AccessList,
Expand All @@ -28,7 +29,6 @@
Storage,
Transaction,
TransactionException,
eip_2028_transaction_data_cost,
extend_with_defaults,
)

Expand Down Expand Up @@ -681,6 +681,7 @@ def gas_test_parameter_args(
def test_gas_cost(
state_test: StateTestFiller,
pre: Alloc,
fork: Fork,
authorization_list_with_properties: List[AuthorizationWithProperties],
authorization_list: List[AuthorizationTuple],
data: bytes,
Expand All @@ -690,15 +691,13 @@ def test_gas_cost(
"""
Test gas at the execution start of a set-code transaction in multiple scenarios.
"""
intrinsic_gas = (
21_000
+ eip_2028_transaction_data_cost(data)
+ 1900 * sum(len(al.storage_keys) for al in access_list)
+ 2400 * len(access_list)
)
# Calculate the intrinsic gas cost of the authorizations, by default the
# full empty account cost is charged for each authorization.
intrinsic_gas += Spec.PER_EMPTY_ACCOUNT_COST * len(authorization_list_with_properties)
intrinsic_gas = fork.transaction_intrinsic_cost_calculator()(
calldata=data,
access_list=access_list,
authorization_count=len(authorization_list),
)

discounted_authorizations = 0
seen_authority = set()
Expand Down Expand Up @@ -934,6 +933,7 @@ def test_account_warming(
def test_intrinsic_gas_cost(
state_test: StateTestFiller,
pre: Alloc,
fork: Fork,
authorization_list: List[AuthorizationTuple],
data: bytes,
access_list: List[AccessList],
Expand All @@ -944,15 +944,13 @@ def test_intrinsic_gas_cost(
Test sending a transaction with the exact intrinsic gas required and also insufficient
gas.
"""
intrinsic_gas = (
21_000
+ eip_2028_transaction_data_cost(data)
+ 1900 * sum(len(al.storage_keys) for al in access_list)
+ 2400 * len(access_list)
)
# Calculate the intrinsic gas cost of the authorizations, by default the
# full empty account cost is charged for each authorization.
intrinsic_gas += Spec.PER_EMPTY_ACCOUNT_COST * len(authorization_list)
intrinsic_gas = fork.transaction_intrinsic_cost_calculator()(
calldata=data,
access_list=access_list,
authorization_count=len(authorization_list),
)

tx_gas = intrinsic_gas
if not valid:
Expand Down

0 comments on commit 3e2ec92

Please sign in to comment.