Skip to content
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

Open
wants to merge 3 commits into
base: development
Choose a base branch
from

Conversation

baitcode
Copy link
Contributor

Closes: #1546

Introduced changes

  • 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.

* 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
@baitcode
Copy link
Contributor Author

@franciszekjob there might a minor fix for test. It will be one line maximum. Besides that good for review.

@baitcode
Copy link
Contributor Author

baitcode commented Jan 14, 2025

tests on networks do not work, still. 8 (

Comment on lines 17 to 34
@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
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Comment on lines 176 to 185
assert any(
[
await argent_account_v040.supports_interface(
OutsideExecutionInterfaceID.V1
),
await argent_account_v040.supports_interface(
OutsideExecutionInterfaceID.V2
),
]
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed?

Copy link
Contributor Author

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use execute_v3.

Copy link
Contributor Author

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.

Copy link
Collaborator

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?

Copy link
Contributor Author

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.

@@ -16,13 +16,28 @@
AccountToBeDeployedDetails = Tuple[int, KeyPair, int, int]


async def get_deploy_account_details(
*,
def new_address(
Copy link
Collaborator

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.

@franciszekjob
Copy link
Collaborator

@baitcode thanks for quick replies 😄 will respond later today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove skipping of test_account_outside_execution_any_caller
2 participants