Skip to content

test_newly_created_contract()

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

Generate fixtures for these test cases for Bogota with:

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

Test withdrawing to a newly created contract.

Source code in tests/shanghai/eip4895_withdrawals/test_withdrawals.py
@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 6 forks.