-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
V3 transactions in outside execution tests for argent #1554
base: development
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# asdf | ||
.tool-versions | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,33 +5,49 @@ | |
from starknet_py.constants import ANY_CALLER, OutsideExecutionInterfaceID | ||
from starknet_py.hash.selector import get_selector_from_name | ||
from starknet_py.net.account.account import BaseAccount | ||
from starknet_py.net.client_models import Call, OutsideExecutionTimeBounds | ||
from starknet_py.net.client_models import ( | ||
Call, | ||
OutsideExecutionTimeBounds, | ||
ResourceBounds, | ||
) | ||
from starknet_py.tests.e2e.fixtures.constants import MAX_FEE | ||
from starknet_py.transaction_errors import TransactionRevertedError | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_argent_account_outside_execution_compatibility( | ||
argent_account: BaseAccount, | ||
argent_account_v040: BaseAccount, | ||
): | ||
result = await argent_account.supports_interface(OutsideExecutionInterfaceID.V1) | ||
assert result is True | ||
result = await argent_account.supports_interface(OutsideExecutionInterfaceID.V2) | ||
assert result is False | ||
|
||
result = await argent_account_v040.supports_interface( | ||
OutsideExecutionInterfaceID.V1 | ||
) | ||
assert result is True | ||
result = await argent_account_v040.supports_interface( | ||
OutsideExecutionInterfaceID.V2 | ||
) | ||
assert result is True | ||
|
||
|
||
# TODO (#1546): Remove skip mark | ||
@pytest.mark.skip | ||
@pytest.mark.asyncio | ||
async def test_account_outside_execution_any_caller( | ||
argent_account: BaseAccount, | ||
argent_account_v040: BaseAccount, | ||
account: BaseAccount, | ||
map_contract, | ||
): | ||
|
||
assert any( | ||
[ | ||
await argent_account.supports_interface(OutsideExecutionInterfaceID.V1), | ||
await argent_account.supports_interface(OutsideExecutionInterfaceID.V2), | ||
await argent_account_v040.supports_interface( | ||
OutsideExecutionInterfaceID.V1 | ||
), | ||
await argent_account_v040.supports_interface( | ||
OutsideExecutionInterfaceID.V2 | ||
), | ||
] | ||
) | ||
|
||
|
@@ -41,7 +57,7 @@ async def test_account_outside_execution_any_caller( | |
calldata=[20, 20], | ||
) | ||
|
||
call = await argent_account.sign_outside_execution_call( | ||
call = await argent_account_v040.sign_outside_execution_call( | ||
calls=[ | ||
put_call, | ||
], | ||
|
@@ -52,60 +68,79 @@ async def test_account_outside_execution_any_caller( | |
caller=ANY_CALLER, | ||
) | ||
|
||
tx = await argent_account.execute_v1(calls=[call], max_fee=MAX_FEE) | ||
await argent_account.client.wait_for_tx(tx.transaction_hash) | ||
tx = await account.execute_v3( | ||
calls=[call], | ||
l1_resource_bounds=ResourceBounds( | ||
max_amount=int(1e5), max_price_per_unit=int(1e13) | ||
), | ||
) | ||
await account.client.wait_for_tx(tx.transaction_hash) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_account_outside_execution_for_invalid_caller( | ||
argent_account: BaseAccount, | ||
argent_account_v040: BaseAccount, | ||
account: BaseAccount, | ||
map_contract, | ||
): | ||
assert any( | ||
[ | ||
await argent_account.supports_interface(OutsideExecutionInterfaceID.V1), | ||
await argent_account.supports_interface(OutsideExecutionInterfaceID.V2), | ||
await argent_account_v040.supports_interface( | ||
OutsideExecutionInterfaceID.V1 | ||
), | ||
await argent_account_v040.supports_interface( | ||
OutsideExecutionInterfaceID.V2 | ||
), | ||
] | ||
) | ||
|
||
random_address = 0x1234567890123456789012345678901234567890 | ||
|
||
put_call = Call( | ||
to_addr=map_contract.address, | ||
selector=get_selector_from_name("put"), | ||
calldata=[20, 20], | ||
) | ||
|
||
call = await argent_account.sign_outside_execution_call( | ||
call = await argent_account_v040.sign_outside_execution_call( | ||
calls=[ | ||
put_call, | ||
], | ||
execution_time_bounds=OutsideExecutionTimeBounds( | ||
execute_after=datetime.datetime.now() - datetime.timedelta(hours=1), | ||
execute_before=datetime.datetime.now() + datetime.timedelta(hours=1), | ||
), | ||
caller=account.address, | ||
caller=random_address, | ||
) | ||
|
||
tx = await argent_account.execute_v1(calls=[call], max_fee=MAX_FEE) | ||
tx = await account.execute_v3( | ||
calls=[call], | ||
l1_resource_bounds=ResourceBounds( | ||
max_amount=int(1e5), max_price_per_unit=int(1e13) | ||
), | ||
) | ||
|
||
with pytest.raises(TransactionRevertedError) as err: | ||
await argent_account.client.wait_for_tx(tx.transaction_hash) | ||
await argent_account_v040.client.wait_for_tx(tx.transaction_hash) | ||
|
||
assert "argent/invalid-caller" in err.value.message | ||
|
||
|
||
# TODO (#1546): Remove skip mark | ||
@pytest.mark.skip | ||
@pytest.mark.asyncio | ||
async def test_account_outside_execution_for_impossible_time_bounds( | ||
argent_account: BaseAccount, | ||
argent_account_v040: BaseAccount, | ||
account: BaseAccount, | ||
map_contract, | ||
): | ||
|
||
assert any( | ||
[ | ||
await argent_account.supports_interface(OutsideExecutionInterfaceID.V1), | ||
await argent_account.supports_interface(OutsideExecutionInterfaceID.V2), | ||
await argent_account_v040.supports_interface( | ||
OutsideExecutionInterfaceID.V1 | ||
), | ||
await argent_account_v040.supports_interface( | ||
OutsideExecutionInterfaceID.V2 | ||
), | ||
] | ||
) | ||
|
||
|
@@ -115,7 +150,7 @@ async def test_account_outside_execution_for_impossible_time_bounds( | |
calldata=[20, 20], | ||
) | ||
|
||
call = await argent_account.sign_outside_execution_call( | ||
call = await argent_account_v040.sign_outside_execution_call( | ||
calls=[put_call], | ||
execution_time_bounds=OutsideExecutionTimeBounds( | ||
execute_after=datetime.datetime.now() - datetime.timedelta(days=10), | ||
|
@@ -124,9 +159,49 @@ async def test_account_outside_execution_for_impossible_time_bounds( | |
caller=ANY_CALLER, | ||
) | ||
|
||
tx = await argent_account.execute_v1(calls=[call], max_fee=MAX_FEE) | ||
tx = await account.execute_v1(calls=[call], max_fee=MAX_FEE) | ||
|
||
with pytest.raises(TransactionRevertedError) as err: | ||
await argent_account.client.wait_for_tx(tx.transaction_hash) | ||
await argent_account_v040.client.wait_for_tx(tx.transaction_hash) | ||
|
||
assert "argent/invalid-timestamp" in err.value.message | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_account_outside_execution_by_itself_is_impossible( | ||
argent_account_v040: BaseAccount, | ||
map_contract, | ||
): | ||
|
||
assert any( | ||
[ | ||
await argent_account_v040.supports_interface( | ||
OutsideExecutionInterfaceID.V1 | ||
), | ||
await argent_account_v040.supports_interface( | ||
OutsideExecutionInterfaceID.V2 | ||
), | ||
] | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think yes. But I see your suggest. Removing. |
||
|
||
put_call = Call( | ||
to_addr=map_contract.address, | ||
selector=get_selector_from_name("put"), | ||
calldata=[20, 20], | ||
) | ||
|
||
call = await argent_account_v040.sign_outside_execution_call( | ||
calls=[put_call], | ||
execution_time_bounds=OutsideExecutionTimeBounds( | ||
execute_after=datetime.datetime.now() - datetime.timedelta(days=10), | ||
execute_before=datetime.datetime.now() - datetime.timedelta(days=9), | ||
), | ||
caller=ANY_CALLER, | ||
) | ||
|
||
tx = await argent_account_v040.execute_v1(calls=[call], max_fee=MAX_FEE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh! How did those sneak in?! Thank you for catching. |
||
|
||
with pytest.raises(TransactionRevertedError) as err: | ||
await argent_account_v040.client.wait_for_tx(tx.transaction_hash) | ||
|
||
assert "ReentrancyGuard: reentrant call" in err.value.message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we change this test to be parametrized?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid it's not trivial due to dependency injection. I attempted to reduce amount of statements. please check.