Skip to content

test_balance_within_block()

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

Generate fixtures for these test cases for Shanghai with:

Shanghai only:

fill -v tests/shanghai/eip4895_withdrawals/test_withdrawals.py::test_balance_within_block --fork=Shanghai --evm-bin=/path/to/evm-tool-dev-version

For all forks up to and including Shanghai:

fill -v tests/shanghai/eip4895_withdrawals/test_withdrawals.py::test_balance_within_block --until=Shanghai

Test Withdrawal balance increase within the same block, inside contract call.

Source code in tests/shanghai/eip4895_withdrawals/test_withdrawals.py
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
217
218
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
def test_balance_within_block(blockchain_test: BlockchainTestFiller, pre: Alloc):
    """
    Test Withdrawal balance increase within the same block,
    inside 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,
                    gas_limit=100000,
                    to=contract_address,
                    data=Hash(recipient),
                )
            ],
            withdrawals=[
                Withdrawal(
                    index=0,
                    validator_index=0,
                    address=recipient,
                    amount=1,
                )
            ],
        ),
        Block(
            txs=[
                Transaction(
                    sender=sender,
                    gas_limit=100000,
                    to=contract_address,
                    data=Hash(recipient),
                )
            ]
        ),
    ]

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

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