-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
492 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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
92 changes: 92 additions & 0 deletions
92
packages/contracts/evm-contracts/test-lib/StdInvariant.sol
This file contains 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,92 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.6.2 <0.9.0; | ||
|
||
pragma experimental ABIEncoderV2; | ||
|
||
abstract contract StdInvariant { | ||
struct FuzzSelector { | ||
address addr; | ||
bytes4[] selectors; | ||
} | ||
|
||
address[] private _excludedContracts; | ||
address[] private _excludedSenders; | ||
address[] private _targetedContracts; | ||
address[] private _targetedSenders; | ||
|
||
string[] private _excludedArtifacts; | ||
string[] private _targetedArtifacts; | ||
|
||
FuzzSelector[] private _targetedArtifactSelectors; | ||
FuzzSelector[] private _targetedSelectors; | ||
|
||
// Functions for users: | ||
// These are intended to be called in tests. | ||
|
||
function excludeContract(address newExcludedContract_) internal { | ||
_excludedContracts.push(newExcludedContract_); | ||
} | ||
|
||
function excludeSender(address newExcludedSender_) internal { | ||
_excludedSenders.push(newExcludedSender_); | ||
} | ||
|
||
function excludeArtifact(string memory newExcludedArtifact_) internal { | ||
_excludedArtifacts.push(newExcludedArtifact_); | ||
} | ||
|
||
function targetArtifact(string memory newTargetedArtifact_) internal { | ||
_targetedArtifacts.push(newTargetedArtifact_); | ||
} | ||
|
||
function targetArtifactSelector(FuzzSelector memory newTargetedArtifactSelector_) internal { | ||
_targetedArtifactSelectors.push(newTargetedArtifactSelector_); | ||
} | ||
|
||
function targetContract(address newTargetedContract_) internal { | ||
_targetedContracts.push(newTargetedContract_); | ||
} | ||
|
||
function targetSelector(FuzzSelector memory newTargetedSelector_) internal { | ||
_targetedSelectors.push(newTargetedSelector_); | ||
} | ||
|
||
function targetSender(address newTargetedSender_) internal { | ||
_targetedSenders.push(newTargetedSender_); | ||
} | ||
|
||
// Functions for forge: | ||
// These are called by forge to run invariant tests and don't need to be called in tests. | ||
|
||
function excludeArtifacts() public view returns (string[] memory excludedArtifacts_) { | ||
excludedArtifacts_ = _excludedArtifacts; | ||
} | ||
|
||
function excludeContracts() public view returns (address[] memory excludedContracts_) { | ||
excludedContracts_ = _excludedContracts; | ||
} | ||
|
||
function excludeSenders() public view returns (address[] memory excludedSenders_) { | ||
excludedSenders_ = _excludedSenders; | ||
} | ||
|
||
function targetArtifacts() public view returns (string[] memory targetedArtifacts_) { | ||
targetedArtifacts_ = _targetedArtifacts; | ||
} | ||
|
||
function targetArtifactSelectors() public view returns (FuzzSelector[] memory targetedArtifactSelectors_) { | ||
targetedArtifactSelectors_ = _targetedArtifactSelectors; | ||
} | ||
|
||
function targetContracts() public view returns (address[] memory targetedContracts_) { | ||
targetedContracts_ = _targetedContracts; | ||
} | ||
|
||
function targetSelectors() public view returns (FuzzSelector[] memory targetedSelectors_) { | ||
targetedSelectors_ = _targetedSelectors; | ||
} | ||
|
||
function targetSenders() public view returns (address[] memory targetedSenders_) { | ||
targetedSenders_ = _targetedSenders; | ||
} | ||
} |
This file contains 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 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.