test_bal_extcodesize_and_oog()
Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py::test_bal_extcodesize_and_oog@5c024cbb.
Generate fixtures for these test cases for Amsterdam with:
fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py::test_bal_extcodesize_and_oog --fork Amsterdam
Ensure BAL handles EXTCODESIZE and OOG during EXTCODESIZE appropriately.
Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517 | @pytest.mark.parametrize(
"fails_at_extcodesize",
[True, False],
ids=["oog_at_extcodesize", "successful_extcodesize"],
)
def test_bal_extcodesize_and_oog(
pre: Alloc,
blockchain_test: BlockchainTestFiller,
fork: Fork,
fails_at_extcodesize: bool,
) -> None:
"""
Ensure BAL handles EXTCODESIZE and OOG during EXTCODESIZE appropriately.
"""
alice = pre.fund_eoa()
# Create target contract with some code
target_contract = pre.deploy_contract(code=Op.STOP)
# Create contract that checks target's code size
codesize_checker_code = (
Op.PUSH20(target_contract) # Target contract address
+ Op.EXTCODESIZE(address_warm=False) # Check code size (cold access)
+ Op.STOP
)
codesize_checker = pre.deploy_contract(code=codesize_checker_code)
intrinsic_gas_cost = fork.transaction_intrinsic_cost_calculator()()
tx_gas_limit = intrinsic_gas_cost + codesize_checker_code.gas_cost(fork)
if fails_at_extcodesize:
# subtract 1 gas to ensure OOG at EXTCODESIZE
tx_gas_limit -= 1
tx = Transaction(
sender=alice,
to=codesize_checker,
gas_limit=tx_gas_limit,
)
block = Block(
txs=[tx],
expected_block_access_list=BlockAccessListExpectation(
account_expectations={
codesize_checker: BalAccountExpectation.empty(),
# Target should only appear if EXTCODESIZE succeeded
**(
{target_contract: None}
if fails_at_extcodesize
else {target_contract: BalAccountExpectation.empty()}
),
}
),
)
blockchain_test(
pre=pre,
blocks=[block],
post={
alice: Account(nonce=1),
codesize_checker: Account(),
target_contract: Account(),
},
)
|
Parametrized Test Cases
This test generates 2 parametrized test cases across 1 fork.