@pytest.mark.parametrize("exceed_gas_refund_limit",[pytest.param(True),pytest.param(False),],)@pytest.mark.valid_from("Osaka")deftest_maximum_gas_refund(state_test:StateTestFiller,pre:Alloc,fork:Fork,exceed_gas_refund_limit:bool,)->None:"""Test the maximum gas refund behavior according to EIP-3529."""gas_costs=fork.gas_costs()tx_gas_limit_cap=fork.transaction_gas_limit_cap()asserttx_gas_limit_capisnotNone,"Fork does not have a transaction gas limit cap"max_refund_quotient=fork.max_refund_quotient()storage=Storage()# Base Operation: SSTORE(slot, 0)iteration_cost=gas_costs.G_STORAGE_RESET+gas_costs.G_BASE+gas_costs.G_VERY_LOWgas_refund=gas_costs.R_STORAGE_CLEAR# EIP-3529: Reduction in refundsstorage_count=tx_gas_limit_cap//iteration_costgas_used=storage_count*iteration_costmaximum_gas_refund=gas_used//max_refund_quotientgas_refund_count=maximum_gas_refund//gas_refund# Base case: operations that fit within the refund limititeration_count=min(storage_count,gas_refund_count+int(exceed_gas_refund_limit))assertiteration_cost*iteration_count<=tx_gas_limit_cap,("Iteration cost exceeds tx gas limit cap")opcode=sum((Op.SSTORE(storage.store_next(0),Op.PUSH0)for_inrange(iteration_count)),Bytecode(),)assertlen(opcode)<=fork.max_code_size(),"code size exceeds max code size"contract=pre.deploy_contract(code=opcode,storage={Hash(i):Hash(1)foriinrange(iteration_count)},)tx=Transaction(to=contract,sender=pre.fund_eoa(),gas_limit=tx_gas_limit_cap,)post={contract:Account(storage=storage)}state_test(pre=pre,post=post,tx=tx)