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

Migrate account #616

Closed
wants to merge 65 commits into from

Conversation

ericnordelo
Copy link
Member

@ericnordelo ericnordelo commented May 4, 2023

Fixes #547

PR Checklist

  • Tests
  • Tried the feature on a public network
  • Documentation

Copy link
Collaborator

@andrew-fleming andrew-fleming left a comment

Choose a reason for hiding this comment

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

Excellent work on the account and tests! I left some comments, suggestions, and questions

src/openzeppelin/account.cairo Outdated Show resolved Hide resolved
src/openzeppelin/utils.cairo Show resolved Hide resolved
src/openzeppelin/account.cairo Outdated Show resolved Hide resolved
src/openzeppelin/tests/test_account.cairo Outdated Show resolved Hide resolved
src/openzeppelin/tests/test_account.cairo Outdated Show resolved Hide resolved
src/openzeppelin/tests/test_account.cairo Show resolved Hide resolved
src/openzeppelin/account.cairo Outdated Show resolved Hide resolved
src/openzeppelin/account.cairo Outdated Show resolved Hide resolved
src/openzeppelin/tests/test_account.cairo Outdated Show resolved Hide resolved
src/openzeppelin/tests/test_account.cairo Outdated Show resolved Hide resolved
src/openzeppelin/account.cairo Outdated Show resolved Hide resolved
src/openzeppelin/account.cairo Outdated Show resolved Hide resolved
src/openzeppelin/account.cairo Outdated Show resolved Hide resolved
src/openzeppelin/account.cairo Outdated Show resolved Hide resolved
src/openzeppelin/account.cairo Outdated Show resolved Hide resolved
src/openzeppelin/tests/test_account.cairo Show resolved Hide resolved
#[available_gas(2000000)]
fn test_multicall() {
let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA()));
let erc20 = deploy_erc20(account.contract_address, 1000);
Copy link
Contributor

Choose a reason for hiding this comment

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

if we decide to drop the account deployment, we can simply use a const address for minting, then we can set it as tx sender

Copy link
Member Author

Choose a reason for hiding this comment

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

Following on this comment, personally, I wouldn't say I like the idea of removing the deployment of the account, to me is getting further away from the actual flow, and in some cases, we can't.

Copy link
Contributor

Choose a reason for hiding this comment

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

in which cases we can't? agree that we're departing from the flow, but i'm not sure deploying is getting us closer. maybe i'll understand your point by looking at the cases we can't, but otherwise it doesn't seem to be adding much value.

Copy link
Member Author

Choose a reason for hiding this comment

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

execute as stated in this comment.

Copy link
Member Author

@ericnordelo ericnordelo May 17, 2023

Choose a reason for hiding this comment

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

IMO the complexity added on top is pretty small, and at least having the entry point executed by a syscall using the setup_dispatcher (setting the contract_address and the caller_address automatically) is less error-prone (even when is still quite far from the real flow, is closer). But there is a line ofc, we can use direct calls (instead of the dispatcher) for simple logic like Account::_is_valid_signature, which is not an entry point or using context, but we need to use dispatcher to test interactions like execute, I cannot say exactly what we should use in the middle, but for me looks better using dispatcher for entry points like validate, even when we could use direct calls.

If you feel we should be using direct calls for this I will update accordingly.

Copy link
Contributor

Choose a reason for hiding this comment

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

no, it's okay. let's then make this explicit by stating that we deploy contracts when call_contract_syscall is involved since target contracts need to be registered and sometimes to know the caller's address.

similar to what came up in the constructor vs initializer discussion, i think the main distinction between presets and libraries is that we intend to deploy the former and not the latter, so it's ok to test module's functions directly as long as deployment is not needed. therefore i would favor not deploying for all cases but the ones where call_contract_syscall is involved. would you agree with that?

src/openzeppelin/tests/test_account.cairo Outdated Show resolved Hide resolved
src/openzeppelin/tests/test_account.cairo Outdated Show resolved Hide resolved
src/openzeppelin/tests/test_account.cairo Outdated Show resolved Hide resolved
Copy link
Contributor

@martriay martriay left a comment

Choose a reason for hiding this comment

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

very good job! i subscribe to many of Andrew's comments, adding my own

src/openzeppelin/account.cairo Outdated Show resolved Hide resolved
src/openzeppelin/account.cairo Outdated Show resolved Hide resolved
src/openzeppelin/tests/test_account.cairo Show resolved Hide resolved
src/openzeppelin/tests/test_account.cairo Outdated Show resolved Hide resolved
Copy link
Collaborator

@andrew-fleming andrew-fleming left a comment

Choose a reason for hiding this comment

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

Great work! I left a few questions and comments, but I think we're looking good :)

src/openzeppelin/account.cairo Outdated Show resolved Hide resolved
src/openzeppelin/tests/test_account.cairo Show resolved Hide resolved
src/openzeppelin/tests/test_account.cairo Outdated Show resolved Hide resolved
src/openzeppelin/account.cairo Outdated Show resolved Hide resolved
//

#[internal]
fn _assert_only_self() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm curious about this as well. Perhaps, saving the underscore function only for internal functions that bear the same name would be appropriate e.g.

#[view]
fn is_valid_signature(){}

#[internal]
fn assert_only_self(){}

#[internal]
fn _is_valid_signature(){}

IMO it's a simple convention to follow. What do you guys think?

ericnordelo and others added 2 commits May 16, 2023 23:32
Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>
Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>
src/openzeppelin/account.cairo Outdated Show resolved Hide resolved
src/openzeppelin/token/erc20.cairo Show resolved Hide resolved
src/openzeppelin/tests/test_account.cairo Show resolved Hide resolved
src/openzeppelin/tests/test_account.cairo Outdated Show resolved Hide resolved
src/openzeppelin/account.cairo Outdated Show resolved Hide resolved
Comment on lines 103 to 105
let account = setup_dispatcher(Option::None(()));
let public_key: felt252 = account.get_public_key();
assert(public_key == PUBLIC_KEY(), 'Should return public key');
Copy link
Contributor

Choose a reason for hiding this comment

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

i think simplification can both make tests easier to read and effectively simpler in execution

src/openzeppelin/tests/test_account.cairo Show resolved Hide resolved
#[available_gas(2000000)]
fn test_multicall() {
let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA()));
let erc20 = deploy_erc20(account.contract_address, 1000);
Copy link
Contributor

Choose a reason for hiding this comment

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

in which cases we can't? agree that we're departing from the flow, but i'm not sure deploying is getting us closer. maybe i'll understand your point by looking at the cases we can't, but otherwise it doesn't seem to be adding much value.

src/openzeppelin/tests/test_account.cairo Show resolved Hide resolved
#[test]
#[available_gas(2000000)]
fn test_execute() {
test_execute_with_version(Option::None(()));
Copy link
Contributor

Choose a reason for hiding this comment

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

what about moving the setup_dispatcher version setting in here? or do we need it in other tests as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

The version is part of the context that setup_dispatcher is initializing to make the calls in tests closer to reality. Is true that we can test validate_deploy (for ex.) without setting the correct transaction version, but IMO this is more error-prone because we can easier forget to set this context on a test that passes because of that. I think setting the basic context in setup_dispatcher, and using setup_dispatcher when possible is a better pattern than direct calls with incorrect context (as before to mention that there is a line, but for me most tests should use setup_dispatcher instead of direct calls)

Copy link
Contributor

Choose a reason for hiding this comment

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

but isn't tx version only used in __execute__ where tests are already mindful of it? i agree with you in spirit (approximate to reality, minimize error-prone approaches) but in practice we end up:

  • splitting the version setting between the setup function and these test cases
  • adding an if in the test body
  • and we have a quirky Option::None() in here

i don't feel that strongly about this, so if you do then i'm ok with keeping it as it is

Copy link
Collaborator

@andrew-fleming andrew-fleming left a comment

Choose a reason for hiding this comment

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

Looking very nice! On top of the open discussions, I just left a few small questions. Also, they recently released a new version of cairo. What do you think about bumping up the cairo submodule to the release commit since it's a bit more meaningful?

src/openzeppelin/account/account.cairo Show resolved Hide resolved
src/openzeppelin/account/account.cairo Show resolved Hide resolved
src/openzeppelin/tests/test_account.cairo Show resolved Hide resolved
src/openzeppelin/tests/test_account.cairo Show resolved Hide resolved
src/openzeppelin/tests/test_account.cairo Show resolved Hide resolved
src/openzeppelin/tests/test_account.cairo Show resolved Hide resolved
src/openzeppelin/tests/test_account.cairo Show resolved Hide resolved
src/openzeppelin/tests/test_account.cairo Show resolved Hide resolved
#[test]
#[available_gas(2000000)]
fn test_execute() {
test_execute_with_version(Option::None(()));
Copy link
Contributor

Choose a reason for hiding this comment

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

but isn't tx version only used in __execute__ where tests are already mindful of it? i agree with you in spirit (approximate to reality, minimize error-prone approaches) but in practice we end up:

  • splitting the version setting between the setup function and these test cases
  • adding an if in the test body
  • and we have a quirky Option::None() in here

i don't feel that strongly about this, so if you do then i'm ok with keeping it as it is

#[available_gas(2000000)]
fn test_multicall() {
let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA()));
let erc20 = deploy_erc20(account.contract_address, 1000);
Copy link
Contributor

Choose a reason for hiding this comment

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

no, it's okay. let's then make this explicit by stating that we deploy contracts when call_contract_syscall is involved since target contracts need to be registered and sometimes to know the caller's address.

similar to what came up in the constructor vs initializer discussion, i think the main distinction between presets and libraries is that we intend to deploy the former and not the latter, so it's ok to test module's functions directly as long as deployment is not needed. therefore i would favor not deploying for all cases but the ones where call_contract_syscall is involved. would you agree with that?

src/openzeppelin/account/account.cairo Show resolved Hide resolved
src/openzeppelin/account/account.cairo Show resolved Hide resolved
src/openzeppelin/tests/test_account.cairo Show resolved Hide resolved
src/openzeppelin/account/interface.cairo Show resolved Hide resolved
@martriay martriay changed the title Migrate account with new test features Migrate account May 23, 2023
@andrew-fleming andrew-fleming mentioned this pull request May 23, 2023
3 tasks
@martriay
Copy link
Contributor

Superseded by #620. Thanks @ericnordelo for the great work!

@martriay martriay closed this May 23, 2023
@ericnordelo ericnordelo deleted the feat/test-account branch September 22, 2023 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

migrate basic account contract
3 participants