-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add max fisherman rewards cut (OZ L-02)
- Loading branch information
Showing
9 changed files
with
221 additions
and
12 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
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
166 changes: 166 additions & 0 deletions
166
packages/subgraph-service/test/disputeManager/constructor/constructor.t.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,166 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.26; | ||
|
||
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, | ||
(arbitrator, disputePeriod, disputeDeposit, fishermanRewardPercentage, maxSlashingPercentage) | ||
) | ||
); | ||
} | ||
|
||
/* | ||
* TESTS | ||
*/ | ||
|
||
function test_Constructor( | ||
uint32 fishermanRewardPercentage | ||
) public useDeployer { | ||
vm.assume(fishermanRewardPercentage <= disputeManager.MAX_FISHERMAN_REWARD_CUT()); | ||
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_Constructor_RevertIf_ControllerAddressIsZero() public useDeployer { | ||
bytes memory expectedError = abi.encodeWithSelector( | ||
GraphDirectory.GraphDirectoryInvalidZeroAddress.selector, | ||
"Controller" | ||
); | ||
vm.expectRevert(expectedError); | ||
new DisputeManager(address(0)); | ||
} | ||
|
||
function test_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_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_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_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_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 | ||
); | ||
} | ||
} |
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
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
33 changes: 33 additions & 0 deletions
33
packages/subgraph-service/test/disputeManager/governance/fishermanRewardCut.t.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,33 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.26; | ||
|
||
import "forge-std/Test.sol"; | ||
|
||
import { IDisputeManager } from "../../../contracts/interfaces/IDisputeManager.sol"; | ||
import { DisputeManagerTest } from "../DisputeManager.t.sol"; | ||
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; | ||
|
||
contract DisputeManagerGovernanceFishermanRewardCutTest is DisputeManagerTest { | ||
|
||
/* | ||
* TESTS | ||
*/ | ||
|
||
function test_Governance_SetFishermanRewardCut() public useGovernor { | ||
uint32 fishermanRewardCut = 1000; | ||
disputeManager.setFishermanRewardCut(fishermanRewardCut); | ||
assertEq(disputeManager.fishermanRewardCut(), fishermanRewardCut, "Fisherman reward cut should be set."); | ||
} | ||
|
||
function test_Governance_RevertWhen_OverMaximumValue(uint32 fishermanRewardCut) public useGovernor { | ||
vm.assume(fishermanRewardCut > disputeManager.MAX_FISHERMAN_REWARD_CUT()); | ||
vm.expectRevert(abi.encodeWithSelector(IDisputeManager.DisputeManagerInvalidFishermanReward.selector, fishermanRewardCut)); | ||
disputeManager.setFishermanRewardCut(fishermanRewardCut); | ||
} | ||
|
||
function test_Governance_RevertWhen_NotGovernor() public useFisherman { | ||
uint32 fishermanRewardCut = 1000; | ||
vm.expectRevert(abi.encodeWithSelector(OwnableUpgradeable.OwnableUnauthorizedAccount.selector, users.fisherman)); | ||
disputeManager.setFishermanRewardCut(fishermanRewardCut); | ||
} | ||
} |