From 3e2ec92c094e367244b73cdaa09f77f996f80986 Mon Sep 17 00:00:00 2001 From: Mario Vega Date: Thu, 31 Oct 2024 22:43:17 +0000 Subject: [PATCH] refactor(tests): Use `fork` gas calc functions --- .../eip7069_extcall/test_gas.py | 9 +++--- .../eip7620_eof_create/test_gas.py | 7 +++-- tests/prague/eip7702_set_code_tx/test_gas.py | 28 +++++++++---------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/tests/osaka/eip7692_eof_v1/eip7069_extcall/test_gas.py b/tests/osaka/eip7692_eof_v1/eip7069_extcall/test_gas.py index b2417fb711..44c5905449 100644 --- a/tests/osaka/eip7692_eof_v1/eip7069_extcall/test_gas.py +++ b/tests/osaka/eip7692_eof_v1/eip7069_extcall/test_gas.py @@ -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 @@ -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, @@ -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, @@ -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), ) diff --git a/tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_gas.py b/tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_gas.py index e536414a02..f9d01e82f3 100644 --- a/tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_gas.py +++ b/tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_gas.py @@ -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 @@ -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, @@ -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(), @@ -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, diff --git a/tests/prague/eip7702_set_code_tx/test_gas.py b/tests/prague/eip7702_set_code_tx/test_gas.py index 04d86bc39f..a3b6405895 100644 --- a/tests/prague/eip7702_set_code_tx/test_gas.py +++ b/tests/prague/eip7702_set_code_tx/test_gas.py @@ -10,6 +10,7 @@ import pytest +from ethereum_test_forks import Fork from ethereum_test_tools import ( EOA, AccessList, @@ -28,7 +29,6 @@ Storage, Transaction, TransactionException, - eip_2028_transaction_data_cost, extend_with_defaults, ) @@ -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, @@ -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() @@ -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], @@ -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: