-
-
Notifications
You must be signed in to change notification settings - Fork 126
/
Copy pathBase.t.sol
72 lines (56 loc) · 3.05 KB
/
Base.t.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
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.13 <0.9.0;
import { PRBTest } from "@prb/test/PRBTest.sol";
import { StdCheats } from "forge-std/StdCheats.sol";
import { SD59x18 } from "src/sd59x18/ValueType.sol";
import { PRBMathAssertions } from "src/test/Assertions.sol";
import { PRBMathUtils } from "src/test/Utils.sol";
import { UD60x18 } from "src/ud60x18/ValueType.sol";
/// @title Base_Test
/// @author Paul Razvan Berg
/// @notice Common contract members needed across tests.
abstract contract Base_Test is PRBTest, StdCheats, PRBMathAssertions, PRBMathUtils {
/*//////////////////////////////////////////////////////////////////////////
STRUCTS
//////////////////////////////////////////////////////////////////////////*/
struct Users {
address payable alice;
address payable bob;
address payable eve;
}
/*//////////////////////////////////////////////////////////////////////////
CONSTANTS
//////////////////////////////////////////////////////////////////////////*/
/// @dev The maximum value an uint128 number can have.
uint128 internal constant MAX_UINT128 = type(uint128).max;
/// @dev The maximum value an uint40 number can have.
uint128 internal constant MAX_UINT40 = type(uint40).max;
/*//////////////////////////////////////////////////////////////////////////
TESTING VARIABLES
//////////////////////////////////////////////////////////////////////////*/
Users internal users;
/*//////////////////////////////////////////////////////////////////////////
SET-UP FUNCTION
//////////////////////////////////////////////////////////////////////////*/
function setUp() public virtual {
// Create users for testing.
users = Users({ alice: mkaddr("Alice"), bob: mkaddr("Bob"), eve: mkaddr("Eve") });
// Make Alice the `msg.sender` and `tx.origin` for all subsequent calls.
vm.startPrank({ msgSender: users.alice, txOrigin: users.alice });
}
/*//////////////////////////////////////////////////////////////////////////
INTERNAL CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @dev Bounds a `uint128` number.
function boundUint128(uint128 x, uint128 min, uint128 max) internal view returns (uint128 result) {
result = uint128(bound(uint256(x), uint256(min), uint256(max)));
}
/*//////////////////////////////////////////////////////////////////////////
INTERNAL NON-CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @dev Generates an address by hashing the name and labels the address.
function mkaddr(string memory name) internal returns (address payable addr) {
addr = payable(address(uint160(uint256(keccak256(abi.encodePacked(name))))));
vm.label({ account: addr, newLabel: name });
}
}