-
Notifications
You must be signed in to change notification settings - Fork 18
feat(edsl): add uint8-backed enum support #2248
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
Open
Th0rgal
wants to merge
5
commits into
main
Choose a base branch
from
feat/enum-support-2088
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f448cc5
feat(edsl): add uint8-backed enum support
Th0rgal 30ec7fb
fix(tests): generate valid enum fixtures
Th0rgal dbd1eec
fix(edsl): preserve enum validation and storage types
Th0rgal 05cf76c
fix(tests): scope enum calldata decoding to inputs
Th0rgal fb5bbc1
fix(edsl): close enum boundary validation gaps
Th0rgal 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
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,94 @@ | ||
| import Contracts.Common | ||
|
|
||
| namespace Contracts.Smoke.EnumFeatureTest | ||
|
|
||
| open Compiler.CompilationModel | ||
| open Verity hiding pure bind | ||
| open Verity.EVM.Uint256 | ||
|
|
||
| verity_contract MacroEnumUsage where | ||
| enums | ||
| enum Status { Pending, Active, Closed } | ||
|
|
||
| storage | ||
| status : Status := slot 0 | ||
| statuses : Uint256 → Status := slot 1 | ||
|
|
||
| errors | ||
| error InvalidStatus(Status) | ||
|
|
||
| event_defs | ||
| event StatusChanged(@indexed previous : Status, current : Status) | ||
|
|
||
| function identity (value : Status) : Status := do | ||
| return value | ||
|
|
||
| function active () : Status := do | ||
| return Status.Active | ||
|
|
||
| function castStatus (value : Uint256) : Status := do | ||
| let casted ← Status(value) | ||
| return casted | ||
|
|
||
| function setStatus (value : Status) : Unit := do | ||
| setStorage status value | ||
|
|
||
| function getStatus () : Status := do | ||
| let value ← getStorage status | ||
| return value | ||
|
|
||
| function setStatusAt (key : Uint256, value : Status) : Unit := do | ||
| setMappingUint statuses key value | ||
|
|
||
| function getStatusAt (key : Uint256) : Status := do | ||
| let value ← getMappingUint statuses key | ||
| return value | ||
|
|
||
| def identityUsesUint8Abi : Bool := | ||
| (match MacroEnumUsage.identity_model.params with | ||
| | [{ ty, .. }] => paramTypeToSolidityString ty == "uint8" | ||
| | _ => false) && | ||
| MacroEnumUsage.identity_model.returns == [ParamType.uint8] | ||
|
|
||
| example : identityUsesUint8Abi = true := by native_decide | ||
|
|
||
| def eventAndErrorUseUint8Abi : Bool := | ||
| MacroEnumUsage.spec.events.any (fun ev => | ||
| match ev with | ||
| | { name := "StatusChanged", params := | ||
| [{ name := "previous", ty := ParamType.uint8, kind := EventParamKind.indexed }, | ||
| { name := "current", ty := ParamType.uint8, kind := EventParamKind.unindexed }] } => true | ||
| | _ => false) && | ||
| MacroEnumUsage.spec.errors.any (fun err => | ||
| match err with | ||
| | { name := "InvalidStatus", params := [ParamType.uint8] } => true | ||
| | _ => false) | ||
|
|
||
| example : eventAndErrorUseUint8Abi = true := by native_decide | ||
|
|
||
| def memberConstantIsOne : Bool := MacroEnumUsage.Status.Active == 1 | ||
|
|
||
| example : memberConstantIsOne = true := by native_decide | ||
|
|
||
| def castAcceptsLastMember : Bool := | ||
| match MacroEnumUsage.castStatus 2 defaultState with | ||
| | .success value _ => value == 2 | ||
| | .revert _ _ => false | ||
|
|
||
| example : castAcceptsLastMember = true := by native_decide | ||
|
|
||
| def castRejectsOutOfRange : Bool := | ||
| match MacroEnumUsage.castStatus 3 defaultState with | ||
| | .success _ _ => false | ||
| | .revert _ _ => true | ||
|
|
||
| example : castRejectsOutOfRange = true := by native_decide | ||
|
|
||
| def enumParamRejectsOutOfRange : Bool := | ||
| match MacroEnumUsage.identity 3 defaultState with | ||
| | .success _ _ => false | ||
| | .revert _ _ => true | ||
|
|
||
| example : enumParamRejectsOutOfRange = true := by native_decide | ||
|
|
||
| end Contracts.Smoke.EnumFeatureTest |
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
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
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
Oops, something went wrong.
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.