-
Notifications
You must be signed in to change notification settings - Fork 235
fix(sol-macro-expander): propagate all_derives and extra_derives to periphery SC structs
#1011
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
6 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| //! Comprehensive test for contract-level derives applying to all generated types. | ||
| //! Tests all_derives and extra_derives on contracts with events and errors. | ||
|
|
||
| use alloy_primitives::{Address, U256}; | ||
| use alloy_sol_types::sol; | ||
| use std::{collections::HashSet, hash::Hash}; | ||
|
|
||
| #[test] | ||
| fn test_all_derives() { | ||
| sol! { | ||
| #[sol(all_derives)] | ||
| contract AllDerivesContract { | ||
| function transfer(address to, uint256 amount) external returns (bool); | ||
| event Transfer(address indexed from, address indexed to, uint256 value); | ||
| error InsufficientBalance(uint256 requested, uint256 available); | ||
| } | ||
| } | ||
|
|
||
| use AllDerivesContract::*; | ||
|
|
||
| let event1 = Transfer { from: Address::ZERO, to: Address::ZERO, value: U256::from(50) }; | ||
| let event2 = Transfer { from: Address::ZERO, to: Address::ZERO, value: U256::from(50) }; | ||
| let events_enum1 = AllDerivesContractEvents::Transfer(event1); | ||
| let events_enum2 = AllDerivesContractEvents::Transfer(event2); | ||
|
|
||
| let error1 = InsufficientBalance { requested: U256::from(100), available: U256::from(50) }; | ||
| let error2 = InsufficientBalance { requested: U256::from(100), available: U256::from(50) }; | ||
| let errors_enum1 = AllDerivesContractErrors::InsufficientBalance(error1); | ||
| let errors_enum2 = AllDerivesContractErrors::InsufficientBalance(error2); | ||
|
|
||
| // Test PartialEq and Debug | ||
| assert_eq!(errors_enum1, errors_enum2); | ||
| assert_eq!(events_enum1, events_enum2); | ||
|
|
||
| // Test Hash and Eq derives | ||
| let mut events_set = HashSet::new(); | ||
| events_set.insert(events_enum1); | ||
| events_set.insert(events_enum2); | ||
| // Should not increase size since they're equal | ||
| assert_eq!(events_set.len(), 1); | ||
|
|
||
| let mut errors_set = HashSet::new(); | ||
| errors_set.insert(errors_enum1); | ||
| errors_set.insert(errors_enum2); | ||
| // Should not increase size since they're equal | ||
| assert_eq!(errors_set.len(), 1); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_extra_derives() { | ||
| sol! { | ||
| #[sol(extra_derives(PartialEq, Eq, Hash, Debug))] | ||
| contract ExtraDerivesContract { | ||
| function transfer(address to, uint256 amount) external returns (bool); | ||
| event Transfer(address indexed from, address indexed to, uint256 value); | ||
| error InsufficientBalance(uint256 requested, uint256 available); | ||
| } | ||
| } | ||
|
|
||
| use ExtraDerivesContract::*; | ||
|
|
||
| let event1 = Transfer { from: Address::ZERO, to: Address::ZERO, value: U256::from(50) }; | ||
| let event2 = Transfer { from: Address::ZERO, to: Address::ZERO, value: U256::from(50) }; | ||
| let events_enum1 = ExtraDerivesContractEvents::Transfer(event1); | ||
| let events_enum2 = ExtraDerivesContractEvents::Transfer(event2); | ||
|
|
||
| let error1 = InsufficientBalance { requested: U256::from(100), available: U256::from(50) }; | ||
| let error2 = InsufficientBalance { requested: U256::from(100), available: U256::from(50) }; | ||
| let errors_enum1 = ExtraDerivesContractErrors::InsufficientBalance(error1); | ||
| let errors_enum2 = ExtraDerivesContractErrors::InsufficientBalance(error2); | ||
|
|
||
| // Test PartialEq and Debug | ||
| assert_eq!(errors_enum1, errors_enum2); | ||
| assert_eq!(events_enum1, events_enum2); | ||
|
|
||
| // Test Hash and Eq derives | ||
| let mut events_set = HashSet::new(); | ||
| events_set.insert(events_enum1); | ||
| events_set.insert(events_enum2); | ||
| // Should not increase size since they're equal | ||
| assert_eq!(events_set.len(), 1); | ||
|
|
||
| let mut errors_set = HashSet::new(); | ||
| errors_set.insert(errors_enum1); | ||
| errors_set.insert(errors_enum2); | ||
| // Should not increase size since they're equal | ||
| assert_eq!(errors_set.len(), 1); | ||
| } |
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.
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 see, this just moves the location and add thes derives
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.
Yeah, it uses the flushed
cx.