-
Notifications
You must be signed in to change notification settings - Fork 48
/
BaseHandler.sol
79 lines (62 loc) · 3.01 KB
/
BaseHandler.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.22 <0.9.0;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { StdCheats } from "forge-std/src/StdCheats.sol";
import { Constants } from "../../utils/Constants.sol";
import { Fuzzers } from "../../utils/Fuzzers.sol";
/// @notice Base contract with common logic needed by all handler contracts.
abstract contract BaseHandler is Constants, Fuzzers, StdCheats {
/*//////////////////////////////////////////////////////////////////////////
STATE-VARIABLES
//////////////////////////////////////////////////////////////////////////*/
/// @dev Maximum number of streams that can be created during an invariant campaign.
uint256 internal constant MAX_STREAM_COUNT = 100;
/// @dev Maps function names to the number of times they have been called.
mapping(string func => uint256 calls) public calls;
/// @dev The total number of calls made to this contract.
uint256 public totalCalls;
/*//////////////////////////////////////////////////////////////////////////
TEST CONTRACTS
//////////////////////////////////////////////////////////////////////////*/
/// @dev Default ERC-20 asset used for testing.
IERC20 public asset;
/*//////////////////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////////////////*/
constructor(IERC20 asset_) {
asset = asset_;
}
/*//////////////////////////////////////////////////////////////////////////
MODIFIERS
//////////////////////////////////////////////////////////////////////////*/
/// @dev Simulates the passage of time. The time jump is upper bounded so that streams don't settle too quickly.
/// @param timeJumpSeed A fuzzed value needed for generating random time warps.
modifier adjustTimestamp(uint256 timeJumpSeed) {
uint256 timeJump = _bound(timeJumpSeed, 2 minutes, 40 days);
vm.warp(block.timestamp + timeJump);
_;
}
/// @dev Checks user assumptions.
modifier checkUsers(address sender, address recipient, address broker) {
// The protocol doesn't allow the sender, recipient or broker to be the zero address.
if (sender == address(0) || recipient == address(0) || broker == address(0)) {
return;
}
// Prevent the contract itself from playing the role of any user.
if (sender == address(this) || recipient == address(this) || broker == address(this)) {
return;
}
_;
}
/// @dev Records a function call for instrumentation purposes.
modifier instrument(string memory functionName) {
calls[functionName]++;
totalCalls++;
_;
}
/// @dev Makes the provided sender the caller.
modifier useNewSender(address sender) {
resetPrank(sender);
_;
}
}