Skip to content

test_use_value_in_contract()

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

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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
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.