Skip to content

test_use_value_in_contract()

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

Generate fixtures for these test cases for Bogota with:

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

Test sending value from contract that has not received a withdrawal.

Source code in tests/shanghai/eip4895_withdrawals/test_withdrawals.py
def test_use_value_in_contract(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
) -> None:
    """Test sending value from contract that has not received a withdrawal."""
    sender = pre.fund_eoa()
    recipient = pre.fund_eoa(1)

    contract_address = pre.deploy_contract(
        Op.SSTORE(
            Op.NUMBER,
            Op.CALL(address=recipient, value=1000000000),
        )
    )
    (tx_0, tx_1) = (
        Transaction(
            sender=sender,
            value=0,
            to=contract_address,
        )
        for _ in range(2)
    )

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

    blocks = [
        Block(
            txs=[tx_0],
            withdrawals=[withdrawal],
        ),
        Block(
            txs=[tx_1],  # Same tx again, just increase nonce
        ),
    ]
    post = {
        contract_address: Account(
            storage={
                0x1: 0x0,  # Call fails on the first attempt
                0x2: 0x1,  # Succeeds on the second attempt
            }
        ),
        recipient: Account(
            balance=ONE_GWEI + 1,
        ),
    }

    blockchain_test(pre=pre, post=post, blocks=blocks)

Parametrized Test Cases

This test generates 1 parametrized test case across 6 forks.