Skip to content

test_balance_within_block()

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

Generate fixtures for these test cases for Bogota with:

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

Test withdrawal balance increase within the same block in a contract call.

Source code in tests/shanghai/eip4895_withdrawals/test_withdrawals.py
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
def test_balance_within_block(
    blockchain_test: BlockchainTestFiller, pre: Alloc
) -> None:
    """
    Test withdrawal balance increase within the same block in a contract call.
    """
    save_balance_on_block_number = Op.SSTORE(
        Op.NUMBER,
        Op.BALANCE(Op.CALLDATALOAD(0)),
    )
    sender = pre.fund_eoa()
    recipient = pre.fund_eoa(ONE_GWEI)
    contract_address = pre.deploy_contract(save_balance_on_block_number)

    blocks = [
        Block(
            txs=[
                Transaction(
                    sender=sender,
                    to=contract_address,
                    data=Hash(recipient, left_padding=True),
                )
            ],
            withdrawals=[
                Withdrawal(
                    index=0,
                    validator_index=0,
                    address=recipient,
                    amount=1,
                )
            ],
        ),
        Block(
            txs=[
                Transaction(
                    sender=sender,
                    to=contract_address,
                    data=Hash(recipient, left_padding=True),
                )
            ]
        ),
    ]

    post = {
        contract_address: Account(
            storage={
                1: ONE_GWEI,
                2: 2 * ONE_GWEI,
            }
        )
    }

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

Parametrized Test Cases

This test generates 1 parametrized test case across 6 forks.