| 1 | // SPDX-License-Identifier: MIT |
| 2 | pragma solidity >=0.6.2 <0.9.0; |
| 3 | |
| 4 | pragma experimental ABIEncoderV2; |
| 5 | |
| 6 | abstract contract StdInvariant { |
| 7 | struct FuzzSelector { |
| 8 | address addr; |
| 9 | bytes4[] selectors; |
| 10 | } |
| 11 | |
| 12 | struct FuzzArtifactSelector { |
| 13 | string artifact; |
| 14 | bytes4[] selectors; |
| 15 | } |
| 16 | |
| 17 | struct FuzzInterface { |
| 18 | address addr; |
| 19 | string[] artifacts; |
| 20 | } |
| 21 | |
| 22 | address[] private _excludedContracts; |
| 23 | address[] private _excludedSenders; |
| 24 | address[] private _targetedContracts; |
| 25 | address[] private _targetedSenders; |
| 26 | |
| 27 | string[] private _excludedArtifacts; |
| 28 | string[] private _targetedArtifacts; |
| 29 | |
| 30 | FuzzArtifactSelector[] private _targetedArtifactSelectors; |
| 31 | |
| 32 | FuzzSelector[] private _excludedSelectors; |
| 33 | FuzzSelector[] private _targetedSelectors; |
| 34 | |
| 35 | FuzzInterface[] private _targetedInterfaces; |
| 36 | |
| 37 | // Functions for users: |
| 38 | // These are intended to be called in tests. |
| 39 | |
| 40 | function excludeContract(address newExcludedContract_) internal { |
| 41 | _excludedContracts.push(newExcludedContract_); |
| 42 | } |
| 43 | |
| 44 | function excludeSelector(FuzzSelector memory newExcludedSelector_) internal { |
| 45 | _excludedSelectors.push(newExcludedSelector_); |
| 46 | } |
| 47 | |
| 48 | function excludeSender(address newExcludedSender_) internal { |
| 49 | _excludedSenders.push(newExcludedSender_); |
| 50 | } |
| 51 | |
| 52 | function excludeArtifact(string memory newExcludedArtifact_) internal { |
| 53 | _excludedArtifacts.push(newExcludedArtifact_); |
| 54 | } |
| 55 | |
| 56 | function targetArtifact(string memory newTargetedArtifact_) internal { |
| 57 | _targetedArtifacts.push(newTargetedArtifact_); |
| 58 | } |
| 59 | |
| 60 | function targetArtifactSelector(FuzzArtifactSelector memory newTargetedArtifactSelector_) internal { |
| 61 | _targetedArtifactSelectors.push(newTargetedArtifactSelector_); |
| 62 | } |
| 63 | |
| 64 | function targetContract(address newTargetedContract_) internal { |
| 65 | _targetedContracts.push(newTargetedContract_); |
| 66 | } |
| 67 | |
| 68 | function targetSelector(FuzzSelector memory newTargetedSelector_) internal { |
| 69 | _targetedSelectors.push(newTargetedSelector_); |
| 70 | } |
| 71 | |
| 72 | function targetSender(address newTargetedSender_) internal { |
| 73 | _targetedSenders.push(newTargetedSender_); |
| 74 | } |
| 75 | |
| 76 | function targetInterface(FuzzInterface memory newTargetedInterface_) internal { |
| 77 | _targetedInterfaces.push(newTargetedInterface_); |
| 78 | } |
| 79 | |
| 80 | // Functions for forge: |
| 81 | // These are called by forge to run invariant tests and don't need to be called in tests. |
| 82 | |
| 83 | function excludeArtifacts() public view returns (string[] memory excludedArtifacts_) { |
| 84 | excludedArtifacts_ = _excludedArtifacts; |
| 85 | } |
| 86 | |
| 87 | function excludeContracts() public view returns (address[] memory excludedContracts_) { |
| 88 | excludedContracts_ = _excludedContracts; |
| 89 | } |
| 90 | |
| 91 | function excludeSelectors() public view returns (FuzzSelector[] memory excludedSelectors_) { |
| 92 | excludedSelectors_ = _excludedSelectors; |
| 93 | } |
| 94 | |
| 95 | function excludeSenders() public view returns (address[] memory excludedSenders_) { |
| 96 | excludedSenders_ = _excludedSenders; |
| 97 | } |
| 98 | |
| 99 | function targetArtifacts() public view returns (string[] memory targetedArtifacts_) { |
| 100 | targetedArtifacts_ = _targetedArtifacts; |
| 101 | } |
| 102 | |
| 103 | function targetArtifactSelectors() public view returns (FuzzArtifactSelector[] memory targetedArtifactSelectors_) { |
| 104 | targetedArtifactSelectors_ = _targetedArtifactSelectors; |
| 105 | } |
| 106 | |
| 107 | function targetContracts() public view returns (address[] memory targetedContracts_) { |
| 108 | targetedContracts_ = _targetedContracts; |
| 109 | } |
| 110 | |
| 111 | function targetSelectors() public view returns (FuzzSelector[] memory targetedSelectors_) { |
| 112 | targetedSelectors_ = _targetedSelectors; |
| 113 | } |
| 114 | |
| 115 | function targetSenders() public view returns (address[] memory targetedSenders_) { |
| 116 | targetedSenders_ = _targetedSenders; |
| 117 | } |
| 118 | |
| 119 | function targetInterfaces() public view returns (FuzzInterface[] memory targetedInterfaces_) { |
| 120 | targetedInterfaces_ = _targetedInterfaces; |
| 121 | } |
| 122 | } |