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

Add Account preset #803

Merged
merged 36 commits into from
Nov 10, 2023
Merged

Conversation

ericnordelo
Copy link
Member

@ericnordelo ericnordelo commented Oct 30, 2023

Partially fixes #804

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

ericnordelo and others added 22 commits January 21, 2023 00:19
Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>
…rdelo/cairo-contracts into feat/migrate-account-to-component
Co-authored-by: Martín Triay <martriay@gmail.com>
…rdelo/cairo-contracts into feat/migrate-account-to-component
@ericnordelo ericnordelo changed the title Add account preset Add Account preset Oct 30, 2023
@ericnordelo ericnordelo mentioned this pull request Oct 30, 2023
3 tasks
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, Eric! I left a suggestion and small question. I think we should include a mention and a link in the docs—maybe just in the Account section for now. When we have more, we can consider including a list in the README like we did with cairo v0. Wdyt?

src/presets/account.cairo Outdated Show resolved Hide resolved
src/presets/account.cairo Show resolved Hide resolved
ericnordelo and others added 3 commits November 7, 2023 13:30
Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>
@ericnordelo
Copy link
Member Author

I think we should include a mention and a link in the docs—maybe just in the Account section for now. When we have more, we can consider including a list in the README like we did with cairo v0. Wdyt?

I added a section in the API Reference for presets, I think that's (arguably) more compliant with the doc framework we are trying to target, and then users can follow which implementations the preset is embedding, the constructor, and so on. Let me know what you think. I'd like keeping the tutorial section as clean as possible from references.

@ericnordelo ericnordelo requested a review from martriay November 7, 2023 13:03
@ericnordelo ericnordelo mentioned this pull request Nov 7, 2023
3 tasks
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 job on adding the presets in the API! I think it works really well. In another review (whoops), I left a suggestion and agreed on the idea of elaborating a little bit on the account component. Both are optional. Other than that, LGTM we also need to include the class hash as discussed earlier :)

docs/modules/ROOT/pages/api/account.adoc 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 nice job! I'm not sure how I feel about the preset test copying that much code from the component's suite. Should the new differences (helpers, reordering tests) be integrated into the component's tests?

I think it make sense for both suites to share most of the test cases, is there any chance we could reuse the module's for the preset? that'd be a step further in our plans of offering tests to our users.

@@ -10,7 +10,7 @@ Reference of interfaces, presets, and utilities related to account contracts.

[.contract]
[[ISRC6]]
=== `++ISRC6++` link:https://github.com/OpenZeppelin/cairo-contracts/blob/release-v0.8.0-beta.0/src/account/interface.cairo#L12[{github-icon},role=heading-link]
=== `++ISRC6++` link:https://github.com/OpenZeppelin/cairo-contracts/blob/release-v0.8.0-beta.0/src/account/interface.cairo[{github-icon},role=heading-link]
Copy link
Contributor

Choose a reason for hiding this comment

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

don't we want to update the line number? by the way, these links are broken across the API page, in Account Component and Preset.

I also realized IDeclarer, IDeployer, as well as camel only traits are not documented, only the impls

Copy link
Member Author

Choose a reason for hiding this comment

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

don't we want to update the line number?

I think ew shouldn't, because that's very hard to maintain, when updating a file we would need to look in the doc if a line was affected, and I don't think is worth the benefit. Maybe I'm wrong.

by the way, these links are broken across the API page, in Account Component and Preset.

The only link I see broken is the one for the preset, because that file is not in 0.8.0-beta.0, which will be fixed after releasing (maybe I should update to the X.Y.Z until that point? ). Are there other broken links?

I also realized IDeclarer, IDeployer, as well as camel only traits are not documented, only the impls.

true

Copy link
Member Author

Choose a reason for hiding this comment

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

I also realized IDeclarer, IDeployer, as well as camel only traits are not documented, only the impls.

Do you think it is worth adding them? That would make the API Reference grow bigger without adding much real value IMO (in this particular case).

Copy link
Contributor

@martriay martriay Nov 10, 2023

Choose a reason for hiding this comment

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

I think ew shouldn't, because that's very hard to maintain, when updating a file we would need to look in the doc if a line was affected, and I don't think is worth the benefit. Maybe I'm wrong.

True, but without the line to me it makes no sense to link in each section. I think the best experience for our docs is to have direct links (i find them very useful), probably they should not be updated manually in each PR, we could:

  • check for link health just once before each release, still manual but way less friction and contained
  • build some tool/hook to detect that a linked line of code got modified in a commit and alert us so we update it
  • both

Copy link
Contributor

@martriay martriay Nov 10, 2023

Choose a reason for hiding this comment

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

Do you think it is worth adding them? That would make the API Reference grow bigger without adding much real value IMO (in this particular case).

I'm not sure. I don't think it'll grow much since I expect most of it to be moved from the component and the component ro look similar to the preset. I don't have strong feelings, I just think it's weird to not mention them since they're referenced (e.g. in the impls). I guess it's good for users to know they're available.

Copy link
Contributor

@martriay martriay Nov 10, 2023

Choose a reason for hiding this comment

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

Are there other broken links?

All the source code links, they're not broken links, they're just pointing to the wrong lines.

docs/modules/ROOT/pages/api/account.adoc Outdated Show resolved Hide resolved
src/presets/account.cairo Outdated Show resolved Hide resolved
src/presets/account.cairo Show resolved Hide resolved
src/presets/account.cairo Outdated Show resolved Hide resolved

assert_only_event_owner_added(PUBKEY, ZERO());

assert(Account::PublicKeyImpl::get_public_key(@state) == PUBKEY, 'Should return PUBKEY');
Copy link
Contributor

Choose a reason for hiding this comment

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

small detail, but this is inconsistent with the component's initializer test which reads:

    assert(state.account.get_public_key() == PUBKEY, 'Should return public key');

it's similar with the ISRC5/6 error messages below, they're not normalized across the codebase (e.g. account component) and they probably should. some day 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated

Copy link
Contributor

Choose a reason for hiding this comment

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

although this specific suggestion got accepted, we still need to normalize. i created an issue, we can discuss there if we agree the normalization should be done through constants instead of copying the string each time. bear in mind this is low prio as it's not user facing

src/tests/presets/test_account.cairo Outdated Show resolved Hide resolved
@ericnordelo
Copy link
Member Author

I think it make sense for both suites to share most of the test cases, is there any chance we could reuse the module's for the preset? that'd be a step further in our plans of offering tests to our users.

I don't think we are at that point yet from the available features we have in the test runner. We would need at least to copy-paste the test functions to call internal abstractions (functions probably, or implementations), but that, besides not being pretty, would be hard as well, because the state types they would be receiving are not the same, and Cairo is not a dynamic language. The attempt to achieve that is a lot of effort and a short reward with the version we could accomplish. I think at some point we would be able to do it, just not at this point.

ericnordelo and others added 5 commits November 10, 2023 13:53
Co-authored-by: Martín Triay <martriay@gmail.com>
Co-authored-by: Martín Triay <martriay@gmail.com>
Co-authored-by: Martín Triay <martriay@gmail.com>
@ericnordelo ericnordelo requested a review from martriay November 10, 2023 13:04
@andrew-fleming
Copy link
Collaborator

I think it make sense for both suites to share most of the test cases, is there any chance we could reuse the module's for the preset? that'd be a step further in our plans of offering tests to our users.

I don't think we are at that point yet from the available features we have in the test runner. We would need at least to copy-paste the test functions to call internal abstractions (functions probably, or implementations), but that, besides not being pretty, would be hard as well, because the state types they would be receiving are not the same, and Cairo is not a dynamic language. The attempt to achieve that is a lot of effort and a short reward with the version we could accomplish. I think at some point we would be able to do it, just not at this point.

Yeah, it's tricky. The pattern I came up with just works for tests with dispatchers which, if we're going to have multiple presets, might be worth fleshing out. I'm unsure if it's scalable though, I only tested it with a handful of tests and it's going to need a ton of gas.

#[test]
#[available_gas(200000000000000000)]
fn main() {
    let mut dispatcher = setup_dispatcher();
    test_erc20(dispatcher);
}

fn test_erc20(dispatcher: ERC20ABIDispatcher) {
    test_constructor(dispatcher);
    test_total_supply(dispatcher);
    test_balance_of(dispatcher);
    test_allowance(dispatcher);
    ...
}

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.

Good! We can continue discussion offline or in another issue. This one is good to go, good job @ericnordelo!

@martriay martriay merged commit 7a8231a into OpenZeppelin:main Nov 10, 2023
4 checks passed
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.

Add vanilla presets
3 participants