Skip to content

test_use_value_in_contract()

Documentation for tests/shanghai/eip4895_withdrawals/test_withdrawals.py::test_use_value_in_contract@verkle@v0.0.5.

Generate fixtures for these test cases for Shanghai with:

Shanghai only:

fill -v tests/shanghai/eip4895_withdrawals/test_withdrawals.py::test_use_value_in_contract --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_use_value_in_contract --until=Shanghai

Test sending value from contract that has not received a withdrawal

Source code in tests/shanghai/eip4895_withdrawals/test_withdrawals.py
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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
def test_use_value_in_contract(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
):
    """
    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,
            gas_limit=100_000,
            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)