Skip to content

Commit 48ec2d0

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 73edd9d commit 48ec2d0

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

web3/_utils/module_testing/eth_module.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,11 @@ async def test_async_sign_authorization_and_send_raw_set_code_transaction(
739739
}
740740
signed_auth = keyfile_account.sign_authorization(auth)
741741

742+
# get current math counter and increase it only in the delegation by n
743+
math_counter = await async_math_contract.functions.counter().call()
744+
built_tx = await async_math_contract.functions.incrementCounter(
745+
math_counter + 1337
746+
).build_transaction({})
742747
txn: TxParams = {
743748
"chainId": chain_id,
744749
"to": keyfile_account.address,
@@ -747,7 +752,7 @@ async def test_async_sign_authorization_and_send_raw_set_code_transaction(
747752
"nonce": nonce,
748753
"maxPriorityFeePerGas": Wei(10**9),
749754
"maxFeePerGas": Wei(10**9),
750-
"data": HexBytes("0x"),
755+
"data": built_tx["data"],
751756
"authorizationList": [signed_auth],
752757
}
753758

@@ -758,6 +763,13 @@ async def test_async_sign_authorization_and_send_raw_set_code_transaction(
758763

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

762774
assert len(get_tx["authorizationList"]) == 1
763775
get_auth = get_tx["authorizationList"][0]
@@ -3861,6 +3873,11 @@ def test_sign_authorization_and_send_raw_set_code_transaction(
38613873
}
38623874
signed_auth = keyfile_account.sign_authorization(auth)
38633875

3876+
# get current math counter and increase it only in the delegation by n
3877+
math_counter = math_contract.functions.counter().call()
3878+
data = math_contract.functions.incrementCounter(
3879+
math_counter + 1337
3880+
).build_transaction({})["data"]
38643881
txn: TxParams = {
38653882
"chainId": chain_id,
38663883
"to": keyfile_account.address,
@@ -3869,7 +3886,7 @@ def test_sign_authorization_and_send_raw_set_code_transaction(
38693886
"nonce": nonce,
38703887
"maxPriorityFeePerGas": Wei(10**9),
38713888
"maxFeePerGas": Wei(10**9),
3872-
"data": HexBytes("0x"),
3889+
"data": data,
38733890
"authorizationList": [signed_auth],
38743891
}
38753892

@@ -3880,6 +3897,12 @@ def test_sign_authorization_and_send_raw_set_code_transaction(
38803897

38813898
code = w3.eth.get_code(keyfile_account.address)
38823899
assert code.to_0x_hex() == f"0xef0100{math_contract.address[2:].lower()}"
3900+
delegated = w3.eth.contract(
3901+
address=keyfile_account.address, abi=math_contract.abi
3902+
)
3903+
# assert the math counter is increased by 1337 only in delegated acct
3904+
assert math_contract.functions.counter().call() == math_counter
3905+
assert delegated.functions.counter().call() == math_counter + 1337
38833906

38843907
assert len(get_tx["authorizationList"]) == 1
38853908
get_auth = get_tx["authorizationList"][0]
@@ -3890,7 +3913,7 @@ def test_sign_authorization_and_send_raw_set_code_transaction(
38903913
assert isinstance(get_auth["r"], HexBytes)
38913914
assert isinstance(get_auth["s"], HexBytes)
38923915

3893-
# reset code
3916+
# reset storage value and code
38943917
reset_auth = {
38953918
"chainId": chain_id,
38963919
"address": "0x" + ("00" * 20),

0 commit comments

Comments
 (0)