-
Notifications
You must be signed in to change notification settings - Fork 433
feat: Update InvariantTest inheritance, add new functions, fix CI [WIP]
#263
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,9 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity >=0.6.2 <0.9.0; | ||
|
|
||
| import {Test} from "./Test.sol"; | ||
|
|
||
| contract InvariantTest is Test { | ||
| pragma experimental ABIEncoderV2; | ||
|
|
||
| contract InvariantTest { | ||
| struct FuzzSelector { | ||
| address addr; | ||
| bytes4[] selectors; | ||
|
|
@@ -15,8 +14,21 @@ contract InvariantTest is Test { | |
| address[] private _targetedContracts; | ||
| address[] private _targetedSenders; | ||
|
|
||
| string[] private _excludedArtifacts; | ||
| string[] private _targetedArtifacts; | ||
|
|
||
| FuzzSelector[] internal _targetedArtifactSelectors; | ||
| FuzzSelector[] internal _targetedSelectors; | ||
|
|
||
| function excludeArtifact(string memory newExcludedArtifact_) internal { | ||
| _excludedArtifacts.push(newExcludedArtifact_); | ||
| } | ||
|
|
||
| function excludeArtifacts() public view returns (string[] memory excludedArtifacts_) { | ||
| require(_excludedArtifacts.length != uint256(0), "NO_EXCLUDED_ARTIFACTS"); | ||
| excludedArtifacts_ = _excludedArtifacts; | ||
| } | ||
|
|
||
| function excludeContract(address newExcludedContract_) internal { | ||
| _excludedContracts.push(newExcludedContract_); | ||
| } | ||
|
|
@@ -35,6 +47,24 @@ contract InvariantTest is Test { | |
| excludedSenders_ = _excludedSenders; | ||
| } | ||
|
|
||
| function targetArtifact(string memory newTargetedArtifact_) internal { | ||
| _targetedArtifacts.push(newTargetedArtifact_); | ||
| } | ||
|
Comment on lines
+50
to
+52
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. @joshieDo do all of these methods dedupe the arrays in forge or should we check for duplicates when adding to the array?
Contributor
Author
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. Good question
Contributor
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. they're deduped yeah.... but to be honest if we're talking about |
||
|
|
||
| function targetArtifacts() public view returns (string[] memory targetedArtifacts_) { | ||
| require(_targetedArtifacts.length != uint256(0), "NO_TARGETED_ARTIFACTS"); | ||
|
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. How come the artifact handlers have
Contributor
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. afaik there's no need for that |
||
| targetedArtifacts_ = _targetedArtifacts; | ||
| } | ||
|
|
||
| function targetArtifactSelector(FuzzSelector memory newTargetedArtifactSelector_) internal { | ||
| _targetedArtifactSelectors.push(newTargetedArtifactSelector_); | ||
| } | ||
|
|
||
| function targetArtifactSelectors() public view returns (FuzzSelector[] memory targetedArtifactSelectors_) { | ||
| require(targetedArtifactSelectors_.length != uint256(0), "NO_TARGETED_ARTIFACT_SELECTORS"); | ||
| targetedArtifactSelectors_ = _targetedArtifactSelectors; | ||
| } | ||
|
Comment on lines
+59
to
+66
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. Two UX improvement suggestions, lmk what you think:
Contributor
Author
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. Agree with both of these. I remember asking about updating the naming conventions here a few months ago. I agree that its confusing that I'm good with
Contributor
Author
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. I wanted to do 1) but hesitated because I didn't know which section label convention to use 😆 I'll use whichever you guys like.
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.
Heh, what about something like this: // Functions for users: These are intended to be called in your tests
// Functions for forge: These are called by forge to run invariant tests. You
// do not need to use these or worry about them |
||
|
|
||
| function targetContract(address newTargetedContract_) internal { | ||
| _targetedContracts.push(newTargetedContract_); | ||
| } | ||
|
|
@@ -61,5 +91,4 @@ contract InvariantTest is Test { | |
| require(_targetedSenders.length != uint256(0), "NO_TARGETED_SENDERS"); | ||
| targetedSenders_ = _targetedSenders; | ||
| } | ||
|
|
||
| } | ||
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.
Some of these vars are
privateand others areinternal. Is there a reason for this difference? Wondering which we should preferThere 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.
Good call out, I don't really see any advantage to
private, what do you think? Who know someone might want access to these values in the inherited contracts.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.
Hmm, I think I lean towards keeping it
privateuntil someone has a use case for needing access to the array directly, just a bit safer / more clear API that way since you can't accidentally overwrite it / directly set it