-
Notifications
You must be signed in to change notification settings - Fork 355
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
Migrate account #616
Conversation
Co-authored-by: Andrew Fleming <fleming-andrew@protonmail.com> Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
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.
Excellent work on the account and tests! I left some comments, suggestions, and questions
#[available_gas(2000000)] | ||
fn test_multicall() { | ||
let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); | ||
let erc20 = deploy_erc20(account.contract_address, 1000); |
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.
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
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.
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.
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.
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.
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.
execute
as stated in this comment.
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.
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.
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.
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?
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.
very good job! i subscribe to many of Andrew's comments, adding my own
…o feat/test-account
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.
Great work! I left a few questions and comments, but I think we're looking good :)
src/openzeppelin/account.cairo
Outdated
// | ||
|
||
#[internal] | ||
fn _assert_only_self() { |
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 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?
Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>
Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>
let account = setup_dispatcher(Option::None(())); | ||
let public_key: felt252 = account.get_public_key(); | ||
assert(public_key == PUBLIC_KEY(), 'Should return public key'); |
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 simplification can both make tests easier to read and effectively simpler in execution
#[available_gas(2000000)] | ||
fn test_multicall() { | ||
let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); | ||
let erc20 = deploy_erc20(account.contract_address, 1000); |
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.
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.
#[test] | ||
#[available_gas(2000000)] | ||
fn test_execute() { | ||
test_execute_with_version(Option::None(())); |
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 about moving the setup_dispatcher
version setting in here? or do we need it in other tests as well?
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.
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)
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.
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
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.
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?
#[test] | ||
#[available_gas(2000000)] | ||
fn test_execute() { | ||
test_execute_with_version(Option::None(())); |
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.
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); |
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.
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?
Superseded by #620. Thanks @ericnordelo for the great work! |
Fixes #547
PR Checklist