-
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?
V3 transactions in outside execution tests for argent #1554
Conversation
* Added new argent contract v0.4.0 that supports transactions v3 (casm, json and abi) * Registered new factory for argent v040 injection in tests * Updated tests logic * Added new test that checks for new type of errors (Reentrancy introduced in argent v0.4.0) * Refacttored account creation logic in tests. I tried to keep changes to minimum, but could not help myself to introduce refactoring of a test account creation logic. For some reason those accounts were populated through dependency injection factories, which is ok, but at some point one factory got responsible for all possible types of accounts through same factory which over time got bloated with crotches. I moved all the crotch logic into `AccountToBeDeployedDetailsFactory` and want to propose to get rid of that class completely (well not in this PR) replacing it with obvious calls, like create_specific_account(), prepay_account(), this will make code straighforward and easy to read. Currently to understand what is happening in a particular test one need to hop through 3-5 layers of constructor injection calls. Fixes: 1546
@franciszekjob there might a minor fix for test. It will be one line maximum. Besides that good for review. |
tests on networks do not work, still. 8 ( |
@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 |
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.
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
I think yes. But I see your suggest. Removing.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Please use execute_v3
.
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.
Huh! How did those sneak in?! Thank you for catching.
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.
What's the reason of this change?
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 knew you would ask so provided extensive reasoning in the PR description. Will do this once more.
Short answer: I needed to customize argent account creation logic, i.e. constructor_calldata parameter.
Long answer:
Current logic is the following:
calldata = [keypair.public_key] for keypair that is generated behind the scene. If flag argent_calldata
is set to True, then additional 0 is appended. The thing is argent changed the constructor further. Now to unset guardian you need to pass 1 for 0.4.0 and passing public_key is not enough, it is now wrapped with option so should be prepended with 0. So one way to do solve the task was to pass argent_version
into the AccountToBeDeployedDetailsFactory
.
But while trying to undestand what happens on AccountToBeDeployedDetailsFactory
creation I realised that code in get_deploy_account_details
, does not reflect nor the method name nor documentation and flow is very obscure, so I took liberty to split it into 3 methods - contract address generation, contract creation, contract prepayment. This helped me to clearly define the logic and collect all the crotchy
logic within AccountToBeDeployedDetailsFactory
DI factory. The original flow is saved.
starknet_py/tests/e2e/utils.py
Outdated
@@ -16,13 +16,28 @@ | |||
AccountToBeDeployedDetails = Tuple[int, KeyPair, int, int] | |||
|
|||
|
|||
async def get_deploy_account_details( | |||
*, | |||
def new_address( |
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.
That should be private function, _new_address
.
@baitcode thanks for quick replies 😄 will respond later today. |
Closes: #1546
Introduced changes
I tried to keep changes to minimum, but could not help myself to introduce refactoring of a test account creation logic. For some reason those accounts were populated through dependency injection factories, which is ok, but at some point one factory got responsible for all possible types of accounts through same factory which over time got bloated with crotches.
I moved all the crotch logic into
AccountToBeDeployedDetailsFactory
and want to propose to get rid of that class completely (well not in this PR) replacing it with obvious calls, like create_specific_account(), prepay_account(), this will make code straighforward and easy to read. Currently to understand what is happening in a particular test one need to hop through 3-5 layers of constructor injection calls.