-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathconstructor.t.sol
169 lines (153 loc) · 6.18 KB
/
constructor.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// SPDX-License-Identifier: MIT
pragma solidity 0.8.27;
import "forge-std/Test.sol";
import { PPMMath } from "@graphprotocol/horizon/contracts/libraries/PPMMath.sol";
import { GraphDirectory } from "@graphprotocol/horizon/contracts/utilities/GraphDirectory.sol";
import { UnsafeUpgrades } from "openzeppelin-foundry-upgrades/Upgrades.sol";
import { DisputeManager } from "../../../contracts/DisputeManager.sol";
import { DisputeManagerTest } from "../DisputeManager.t.sol";
import { IDisputeManager } from "../../../contracts/interfaces/IDisputeManager.sol";
contract DisputeManagerConstructorTest is DisputeManagerTest {
using PPMMath for uint256;
/*
* MODIFIERS
*/
modifier useDeployer() {
vm.startPrank(users.deployer);
_;
vm.stopPrank();
}
/*
* HELPERS
*/
function _initializeDisputeManager(
address implementation,
address arbitrator,
uint64 disputePeriod,
uint256 disputeDeposit,
uint32 fishermanRewardPercentage,
uint32 maxSlashingPercentage
) private returns (address) {
return
UnsafeUpgrades.deployTransparentProxy(
implementation,
users.governor,
abi.encodeCall(
DisputeManager.initialize,
(users.deployer, arbitrator, disputePeriod, disputeDeposit, fishermanRewardPercentage, maxSlashingPercentage)
)
);
}
/*
* TESTS
*/
function test_DisputeManager_Constructor(
uint32 fishermanRewardPercentage,
uint32 maxSlashingPercentage
) public useDeployer {
vm.assume(fishermanRewardPercentage <= disputeManager.MAX_FISHERMAN_REWARD_CUT());
vm.assume(maxSlashingPercentage <= PPMMath.MAX_PPM);
address disputeManagerImplementation = address(new DisputeManager(address(controller)));
address proxy = _initializeDisputeManager(
disputeManagerImplementation,
users.arbitrator,
disputePeriod,
disputeDeposit,
fishermanRewardPercentage,
maxSlashingPercentage
);
DisputeManager disputeManager = DisputeManager(proxy);
assertEq(disputeManager.arbitrator(), users.arbitrator);
assertEq(disputeManager.disputePeriod(), disputePeriod);
assertEq(disputeManager.disputeDeposit(), disputeDeposit);
assertEq(disputeManager.fishermanRewardCut(), fishermanRewardPercentage);
}
function test_DisputeManager_Constructor_RevertIf_ControllerAddressIsZero() public useDeployer {
bytes memory expectedError = abi.encodeWithSelector(
GraphDirectory.GraphDirectoryInvalidZeroAddress.selector,
"Controller"
);
vm.expectRevert(expectedError);
new DisputeManager(address(0));
}
function test_DisputeManager_Constructor_RevertIf_ArbitratorAddressIsZero() public useDeployer {
address disputeManagerImplementation = address(new DisputeManager(address(controller)));
bytes memory expectedError = abi.encodeWithSelector(IDisputeManager.DisputeManagerInvalidZeroAddress.selector);
vm.expectRevert(expectedError);
_initializeDisputeManager(
disputeManagerImplementation,
address(0),
disputePeriod,
disputeDeposit,
fishermanRewardPercentage,
maxSlashingPercentage
);
}
function test_DisputeManager_Constructor_RevertIf_InvalidDisputePeriod() public useDeployer {
address disputeManagerImplementation = address(new DisputeManager(address(controller)));
bytes memory expectedError = abi.encodeWithSelector(IDisputeManager.DisputeManagerDisputePeriodZero.selector);
vm.expectRevert(expectedError);
_initializeDisputeManager(
disputeManagerImplementation,
users.arbitrator,
0,
disputeDeposit,
fishermanRewardPercentage,
maxSlashingPercentage
);
}
function test_DisputeManager_Constructor_RevertIf_InvalidDisputeDeposit() public useDeployer {
address disputeManagerImplementation = address(new DisputeManager(address(controller)));
bytes memory expectedError = abi.encodeWithSelector(
IDisputeManager.DisputeManagerInvalidDisputeDeposit.selector,
0
);
vm.expectRevert(expectedError);
_initializeDisputeManager(
disputeManagerImplementation,
users.arbitrator,
disputePeriod,
0,
fishermanRewardPercentage,
maxSlashingPercentage
);
}
function test_DisputeManager_Constructor_RevertIf_InvalidFishermanRewardPercentage(
uint32 _fishermanRewardPercentage
) public useDeployer {
vm.assume(_fishermanRewardPercentage > disputeManager.MAX_FISHERMAN_REWARD_CUT());
address disputeManagerImplementation = address(new DisputeManager(address(controller)));
bytes memory expectedError = abi.encodeWithSelector(
IDisputeManager.DisputeManagerInvalidFishermanReward.selector,
_fishermanRewardPercentage
);
vm.expectRevert(expectedError);
_initializeDisputeManager(
disputeManagerImplementation,
users.arbitrator,
disputePeriod,
disputeDeposit,
_fishermanRewardPercentage,
maxSlashingPercentage
);
}
function test_DisputeManager_Constructor_RevertIf_InvalidMaxSlashingPercentage(
uint32 _maxSlashingPercentage
) public useDeployer {
vm.assume(_maxSlashingPercentage > PPMMath.MAX_PPM);
address disputeManagerImplementation = address(new DisputeManager(address(controller)));
bytes memory expectedError = abi.encodeWithSelector(
IDisputeManager.DisputeManagerInvalidMaxSlashingCut.selector,
_maxSlashingPercentage
);
vm.expectRevert(expectedError);
_initializeDisputeManager(
disputeManagerImplementation,
users.arbitrator,
disputePeriod,
disputeDeposit,
fishermanRewardPercentage,
_maxSlashingPercentage
);
}
}