Skip to content

test_newly_created_contract()

Documentation for tests/shanghai/eip4895_withdrawals/test_withdrawals.py::test_newly_created_contract@7b8124a7.

Generate fixtures for these test cases for Osaka with:

fill -v tests/shanghai/eip4895_withdrawals/test_withdrawals.py::test_newly_created_contract --fork Osaka

Test withdrawing to a newly created contract.

Source code in tests/shanghai/eip4895_withdrawals/test_withdrawals.py
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
@pytest.mark.parametrize(
    "include_value_in_tx",
    [False, True],
    ids=["without_tx_value", "with_tx_value"],
)
def test_newly_created_contract(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    include_value_in_tx: bool,
) -> None:
    """Test withdrawing to a newly created contract."""
    sender = pre.fund_eoa()
    initcode = Op.RETURN(0, 1)
    tx = Transaction(
        # Transaction sent from the `sender`, that creates a
        # new contract.
        sender=sender,
        gas_limit=1000000,
        to=None,
        value=ONE_GWEI if include_value_in_tx else 0,
        data=initcode,
    )
    created_contract = tx.created_contract

    withdrawal = Withdrawal(
        index=0,
        validator_index=0,
        address=created_contract,
        amount=1,
    )

    created_contract_balance = ONE_GWEI
    if include_value_in_tx:
        created_contract_balance = 2 * ONE_GWEI

    post = {
        created_contract: Account(
            code=Op.STOP,
            balance=created_contract_balance,
        ),
    }

    block = Block(
        txs=[tx],
        withdrawals=[withdrawal],
    )

    blockchain_test(pre=pre, post=post, blocks=[block])

Parametrized Test Cases

This test generates 2 parametrized test cases across 4 forks.