Skip to content

test_bal_7702_delegation_update()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7702.py::test_bal_7702_delegation_update@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7702.py::test_bal_7702_delegation_update --fork Amsterdam

Ensure BAL captures update of existing EOA delegation.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7702.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
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
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
@pytest.mark.parametrize(
    "self_funded",
    [
        pytest.param(False, id="sponsored"),
        pytest.param(True, id="self_funded"),
    ],
)
def test_bal_7702_delegation_update(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
    self_funded: bool,
) -> None:
    """Ensure BAL captures update of existing EOA delegation."""
    alice = pre.fund_eoa()
    bob = pre.fund_eoa(amount=0)

    if not self_funded:
        relayer = pre.fund_eoa()
        sender = relayer
    else:
        sender = alice

    oracle1 = pre.deploy_contract(code=Op.STOP)
    oracle2 = pre.deploy_contract(code=Op.STOP)

    ## Perhaps create a pre-existing delegation,
    ## see `test_bal_7702_delegated_storage_access` since
    ## `test_bal_7702_delegation_create` already tests creation
    tx_create = Transaction(
        sender=sender,
        to=bob,
        value=10,
        gas_limit=1_000_000,
        authorization_list=[
            AuthorizationTuple(
                address=oracle1,
                nonce=1 if self_funded else 0,
                signer=alice,
            )
        ],
    )

    tx_update = Transaction(
        nonce=2 if self_funded else 1,
        sender=sender,
        to=bob,
        value=10,
        gas_limit=1_000_000,
        authorization_list=[
            AuthorizationTuple(
                address=oracle2,
                nonce=3 if self_funded else 1,
                signer=alice,
            )
        ],
    )

    account_expectations = {
        alice: BalAccountExpectation(
            nonce_changes=[
                BalNonceChange(
                    block_access_index=1, post_nonce=2 if self_funded else 1
                ),
                BalNonceChange(
                    block_access_index=2, post_nonce=4 if self_funded else 2
                ),
            ],
            code_changes=[
                BalCodeChange(
                    block_access_index=1,
                    new_code=Spec7702.delegation_designation(oracle1),
                ),
                BalCodeChange(
                    block_access_index=2,
                    new_code=Spec7702.delegation_designation(oracle2),
                ),
            ],
        ),
        bob: BalAccountExpectation(
            balance_changes=[
                BalBalanceChange(block_access_index=1, post_balance=10),
                BalBalanceChange(block_access_index=2, post_balance=20),
            ]
        ),
        # Both delegation targets must not be present in BAL
        # the account is never accessed
        oracle1: None,
        oracle2: None,
    }

    # For sponsored variant, relayer must also be included in BAL
    if not self_funded:
        account_expectations[relayer] = BalAccountExpectation(
            nonce_changes=[
                BalNonceChange(block_access_index=1, post_nonce=1),
                BalNonceChange(block_access_index=2, post_nonce=2),
            ],
        )

    block = Block(
        txs=[tx_create, tx_update],
        expected_block_access_list=BlockAccessListExpectation(
            account_expectations=account_expectations
        ),
    )

    post = {
        # Finally Alice's account should be delegated to oracle2
        alice: Account(
            nonce=4 if self_funded else 2,
            code=Spec7702.delegation_designation(oracle2),
        ),
        # Bob receives 20 wei in total
        bob: Account(balance=20),
    }

    # For sponsored variant, include relayer in post state
    if not self_funded:
        post.update({relayer: Account(nonce=2)})

    blockchain_test(
        pre=pre,
        blocks=[block],
        post=post,
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.