-
Notifications
You must be signed in to change notification settings - Fork 396
Enable missing components in macros #1635
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -308,6 +308,14 @@ fn add_per_component_warnings(code: &str, component_info: &ComponentInfo) -> Vec | |
| warnings.push(warning); | ||
| } | ||
| } | ||
| AllowedComponents::ERC1155Supply => { | ||
| let hook_called = code.contains("erc1155_supply.after_update(") | ||
| || code.contains("ERC1155SupplyInternalImpl::after_update("); | ||
| if !hook_called { | ||
| let warning = Diagnostic::warn(warnings::ERC1155_SUPPLY_HOOKS_MISSING); | ||
| warnings.push(warning); | ||
| } | ||
| } | ||
|
Comment on lines
+311
to
+318
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| AllowedComponents::Upgradeable => { | ||
| // Check that the upgrade function is called | ||
| let upgrade_function_called = code.contains("self.upgradeable.upgrade"); | ||
|
|
@@ -324,6 +332,14 @@ fn add_per_component_warnings(code: &str, component_info: &ComponentInfo) -> Vec | |
| warnings.push(warning); | ||
| } | ||
| } | ||
| AllowedComponents::ERC721Enumerable => { | ||
| let hook_called = code.contains("erc721_enumerable.before_update(") | ||
| || code.contains("ERC721EnumerableInternalImpl::before_update("); | ||
| if !hook_called { | ||
| let warning = Diagnostic::warn(warnings::ERC721_ENUMERABLE_HOOKS_MISSING); | ||
| warnings.push(warning); | ||
| } | ||
| } | ||
| _ => {} | ||
| } | ||
| warnings | ||
|
|
||
50 changes: 50 additions & 0 deletions
50
...tests/snapshots/openzeppelin_macros__tests__test_with_components__with_erc20_wrapper.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| --- | ||
| source: src/tests/test_with_components.rs | ||
| expression: result | ||
| snapshot_kind: text | ||
| --- | ||
| TokenStream: | ||
|
|
||
| #[starknet::contract] | ||
| pub mod MyToken { | ||
| use openzeppelin_token::erc20::{DefaultConfig, ERC20HooksEmptyImpl}; | ||
| use starknet::ContractAddress; | ||
| #[storage] | ||
| pub struct Storage { | ||
| #[substorage(v0)] | ||
| pub erc20: ERC20Component::Storage, | ||
| #[substorage(v0)] | ||
| pub erc20_wrapper: ERC20WrapperComponent::Storage, | ||
| } | ||
| #[constructor] | ||
| fn constructor(ref self: ContractState, underlying: ContractAddress) { | ||
| self.erc20.initializer("MyToken", "MTK"); | ||
| self.erc20_wrapper.initializer(underlying); | ||
| } | ||
| use openzeppelin_token::erc20::ERC20Component; | ||
| use openzeppelin_token::erc20::extensions::erc20_wrapper::ERC20WrapperComponent; | ||
|
|
||
| component!(path: ERC20Component, storage: erc20, event: ERC20Event); | ||
| component!(path: ERC20WrapperComponent, storage: erc20_wrapper, event: ERC20WrapperEvent); | ||
|
|
||
| impl ERC20InternalImpl = ERC20Component::InternalImpl<ContractState>; | ||
| impl ERC20WrapperInternalImpl = ERC20WrapperComponent::InternalImpl<ContractState>; | ||
|
|
||
| #[event] | ||
| #[derive(Drop, starknet::Event)] | ||
| enum Event { | ||
| #[flat] | ||
| ERC20Event: ERC20Component::Event, | ||
| #[flat] | ||
| ERC20WrapperEvent: ERC20WrapperComponent::Event, | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Diagnostics: | ||
|
|
||
| None | ||
|
|
||
| AuxData: | ||
|
|
||
| None |
56 changes: 56 additions & 0 deletions
56
.../openzeppelin_macros__tests__test_with_components__with_erc20_wrapper_no_initializer.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| --- | ||
| source: src/tests/test_with_components.rs | ||
| expression: result | ||
| snapshot_kind: text | ||
| --- | ||
| TokenStream: | ||
|
|
||
| #[starknet::contract] | ||
| pub mod MyToken { | ||
| use openzeppelin_token::erc20::{DefaultConfig, ERC20HooksEmptyImpl}; | ||
| use starknet::ContractAddress; | ||
| #[storage] | ||
| pub struct Storage { | ||
| #[substorage(v0)] | ||
| pub erc20: ERC20Component::Storage, | ||
| #[substorage(v0)] | ||
| pub erc20_wrapper: ERC20WrapperComponent::Storage, | ||
| } | ||
| #[constructor] | ||
| fn constructor(ref self: ContractState) { | ||
| self.erc20.initializer("MyToken", "MTK"); | ||
| } | ||
| use openzeppelin_token::erc20::ERC20Component; | ||
| use openzeppelin_token::erc20::extensions::erc20_wrapper::ERC20WrapperComponent; | ||
|
|
||
| component!(path: ERC20Component, storage: erc20, event: ERC20Event); | ||
| component!(path: ERC20WrapperComponent, storage: erc20_wrapper, event: ERC20WrapperEvent); | ||
|
|
||
| impl ERC20InternalImpl = ERC20Component::InternalImpl<ContractState>; | ||
| impl ERC20WrapperInternalImpl = ERC20WrapperComponent::InternalImpl<ContractState>; | ||
|
|
||
| #[event] | ||
| #[derive(Drop, starknet::Event)] | ||
| enum Event { | ||
| #[flat] | ||
| ERC20Event: ERC20Component::Event, | ||
| #[flat] | ||
| ERC20WrapperEvent: ERC20WrapperComponent::Event, | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Diagnostics: | ||
|
|
||
| ==== | ||
| Warning: It looks like the initializers for the following components are missing: | ||
|
|
||
| ERC20Wrapper | ||
|
|
||
| This may lead to unexpected behavior. | ||
| We recommend adding the corresponding initializer calls to the constructor. | ||
| ==== | ||
|
|
||
| AuxData: | ||
|
|
||
| None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
.../openzeppelin_macros__tests__test_with_components__with_erc721_enumerable_with_hooks.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| --- | ||
| source: src/tests/test_with_components.rs | ||
| expression: result | ||
| snapshot_kind: text | ||
| --- | ||
| TokenStream: | ||
|
|
||
| #[starknet::contract] | ||
| pub mod MyContract { | ||
| use openzeppelin_token::erc721::ERC721Component; | ||
| use starknet::ContractAddress; | ||
| #[storage] | ||
| pub struct Storage { | ||
| #[substorage(v0)] | ||
| pub erc721_enumerable: ERC721EnumerableComponent::Storage, | ||
| } | ||
| #[constructor] | ||
| fn constructor(ref self: ContractState) { | ||
| self.erc721_enumerable.initializer(); | ||
| } | ||
| impl ERC721HooksImpl of ERC721Component::ERC721HooksTrait<ContractState> { | ||
| fn before_update( | ||
| ref self: ERC721Component::ComponentState<ContractState>, | ||
| to: ContractAddress, | ||
| token_id: u256, | ||
| auth: ContractAddress, | ||
| ) { | ||
| let mut contract_state = self.get_contract_mut(); | ||
| contract_state.erc721_enumerable.before_update(to, token_id); | ||
| } | ||
| } | ||
| use openzeppelin_token::erc721::extensions::ERC721EnumerableComponent; | ||
|
|
||
| component!( | ||
| path: ERC721EnumerableComponent, storage: erc721_enumerable, event: ERC721EnumerableEvent, | ||
| ); | ||
|
|
||
| impl ERC721EnumerableInternalImpl = ERC721EnumerableComponent::InternalImpl<ContractState>; | ||
|
|
||
| #[event] | ||
| #[derive(Drop, starknet::Event)] | ||
| enum Event { | ||
| #[flat] | ||
| ERC721EnumerableEvent: ERC721EnumerableComponent::Event, | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Diagnostics: | ||
|
|
||
| None | ||
|
|
||
| AuxData: | ||
|
|
||
| None |
57 changes: 57 additions & 0 deletions
57
...ests/snapshots/openzeppelin_macros__tests__test_with_components__with_erc721_wrapper.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| --- | ||
| source: src/tests/test_with_components.rs | ||
| expression: result | ||
| snapshot_kind: text | ||
| --- | ||
| TokenStream: | ||
|
|
||
| #[starknet::contract] | ||
| pub mod MyToken { | ||
| use openzeppelin_token::erc721::ERC721HooksEmptyImpl; | ||
| use starknet::ContractAddress; | ||
| #[storage] | ||
| pub struct Storage { | ||
| #[substorage(v0)] | ||
| pub erc721: ERC721Component::Storage, | ||
| #[substorage(v0)] | ||
| pub src5: SRC5Component::Storage, | ||
| #[substorage(v0)] | ||
| pub erc721_wrapper: ERC721WrapperComponent::Storage, | ||
| } | ||
| #[constructor] | ||
| fn constructor(ref self: ContractState, underlying: ContractAddress) { | ||
| self.erc721.initializer("MyToken", "MTK", ""); | ||
| self.erc721_wrapper.initializer(underlying); | ||
| } | ||
| use openzeppelin_introspection::src5::SRC5Component; | ||
| use openzeppelin_token::erc721::ERC721Component; | ||
| use openzeppelin_token::erc721::extensions::erc721_wrapper::ERC721WrapperComponent; | ||
|
|
||
| component!(path: ERC721Component, storage: erc721, event: ERC721Event); | ||
| component!(path: SRC5Component, storage: src5, event: SRC5Event); | ||
| component!(path: ERC721WrapperComponent, storage: erc721_wrapper, event: ERC721WrapperEvent); | ||
|
|
||
| impl ERC721InternalImpl = ERC721Component::InternalImpl<ContractState>; | ||
| impl SRC5InternalImpl = SRC5Component::InternalImpl<ContractState>; | ||
| impl ERC721WrapperInternalImpl = ERC721WrapperComponent::InternalImpl<ContractState>; | ||
|
|
||
| #[event] | ||
| #[derive(Drop, starknet::Event)] | ||
| enum Event { | ||
| #[flat] | ||
| ERC721Event: ERC721Component::Event, | ||
| #[flat] | ||
| SRC5Event: SRC5Component::Event, | ||
| #[flat] | ||
| ERC721WrapperEvent: ERC721WrapperComponent::Event, | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Diagnostics: | ||
|
|
||
| None | ||
|
|
||
| AuxData: | ||
|
|
||
| None |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.