Skip to content

Commit 66f872c

Browse files
committed
Test a more interesting test case for 7702:
- Change the storage of the EOA in the same transaction by delegating to the ``math_contract`` and calling increment counter on itself.
1 parent 1999e72 commit 66f872c

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

web3/_utils/module_testing/eth_module.py

+26-3
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,11 @@ async def test_async_sign_authorization_and_send_raw_set_code_transaction(
742742
}
743743
signed_auth = keyfile_account.sign_authorization(auth)
744744

745+
# get current math counter and increase it only in the delegation by n
746+
math_counter = await async_math_contract.functions.counter().call()
747+
built_tx = await async_math_contract.functions.incrementCounter(
748+
math_counter + 1337
749+
).build_transaction({})
745750
txn: TxParams = {
746751
"chainId": chain_id,
747752
"to": keyfile_account.address,
@@ -750,7 +755,7 @@ async def test_async_sign_authorization_and_send_raw_set_code_transaction(
750755
"nonce": nonce,
751756
"maxPriorityFeePerGas": Wei(10**9),
752757
"maxFeePerGas": Wei(10**9),
753-
"data": HexBytes("0x"),
758+
"data": built_tx["data"],
754759
"authorizationList": [signed_auth],
755760
}
756761

@@ -761,6 +766,13 @@ async def test_async_sign_authorization_and_send_raw_set_code_transaction(
761766

762767
code = await async_w3.eth.get_code(keyfile_account.address)
763768
assert code.to_0x_hex() == f"0xef0100{async_math_contract.address[2:].lower()}"
769+
delegated = async_w3.eth.contract(
770+
address=keyfile_account.address, abi=async_math_contract.abi
771+
)
772+
# assert the math counter is increased by 1337 only in delegated acct
773+
assert await async_math_contract.functions.counter().call() == math_counter
774+
delegated_call = await delegated.functions.counter().call()
775+
assert delegated_call == math_counter + 1337
764776

765777
assert len(get_tx["authorizationList"]) == 1
766778
get_auth = get_tx["authorizationList"][0]
@@ -3868,6 +3880,11 @@ def test_sign_authorization_and_send_raw_set_code_transaction(
38683880
}
38693881
signed_auth = keyfile_account.sign_authorization(auth)
38703882

3883+
# get current math counter and increase it only in the delegation by n
3884+
math_counter = math_contract.functions.counter().call()
3885+
data = math_contract.functions.incrementCounter(
3886+
math_counter + 1337
3887+
).build_transaction({})["data"]
38713888
txn: TxParams = {
38723889
"chainId": chain_id,
38733890
"to": keyfile_account.address,
@@ -3876,7 +3893,7 @@ def test_sign_authorization_and_send_raw_set_code_transaction(
38763893
"nonce": nonce,
38773894
"maxPriorityFeePerGas": Wei(10**9),
38783895
"maxFeePerGas": Wei(10**9),
3879-
"data": HexBytes("0x"),
3896+
"data": data,
38803897
"authorizationList": [signed_auth],
38813898
}
38823899

@@ -3887,6 +3904,12 @@ def test_sign_authorization_and_send_raw_set_code_transaction(
38873904

38883905
code = w3.eth.get_code(keyfile_account.address)
38893906
assert code.to_0x_hex() == f"0xef0100{math_contract.address[2:].lower()}"
3907+
delegated = w3.eth.contract(
3908+
address=keyfile_account.address, abi=math_contract.abi
3909+
)
3910+
# assert the math counter is increased by 1337 only in delegated acct
3911+
assert math_contract.functions.counter().call() == math_counter
3912+
assert delegated.functions.counter().call() == math_counter + 1337
38903913

38913914
assert len(get_tx["authorizationList"]) == 1
38923915
get_auth = get_tx["authorizationList"][0]
@@ -3897,7 +3920,7 @@ def test_sign_authorization_and_send_raw_set_code_transaction(
38973920
assert isinstance(get_auth["r"], HexBytes)
38983921
assert isinstance(get_auth["s"], HexBytes)
38993922

3900-
# reset code
3923+
# reset storage value and code
39013924
reset_auth = {
39023925
"chainId": chain_id,
39033926
"address": "0x" + ("00" * 20),

0 commit comments

Comments
 (0)