-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: disallow registration before epoch #3 #95
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.24; | ||
|
||
import {IGovernance} from "../src/interfaces/IGovernance.sol"; | ||
import {Governance} from "../src/Governance.sol"; | ||
import {MockERC20Tester} from "./mocks/MockERC20Tester.sol"; | ||
import {MockStakingV1} from "./mocks/MockStakingV1.sol"; | ||
import {MockStakingV1Deployer} from "./mocks/MockStakingV1Deployer.sol"; | ||
|
||
// These tests demonstrate that by deploying `Governance` with `epochStart` set one `EPOCH_DURATION` in the past: | ||
// - initial initiatives can immediately be voted on, | ||
// - registration of new initiatives is disabled for one epoch. | ||
// | ||
// The reason we want to initially disable registration is that there's not vote snapshot to base the registration | ||
// threshold upon, thus registration would otherwise be possible without having any LQTY staked. | ||
contract DeploymentTest is MockStakingV1Deployer { | ||
uint32 constant START_TIME = 1732873631; | ||
uint32 constant EPOCH_DURATION = 7 days; | ||
uint128 constant REGISTRATION_FEE = 1 ether; | ||
|
||
address constant deployer = address(uint160(uint256(keccak256("deployer")))); | ||
address constant voter = address(uint160(uint256(keccak256("voter")))); | ||
address constant registrant = address(uint160(uint256(keccak256("registrant")))); | ||
address constant initialInitiative = address(uint160(uint256(keccak256("initialInitiative")))); | ||
address constant newInitiative = address(uint160(uint256(keccak256("newInitiative")))); | ||
|
||
IGovernance.Configuration config = IGovernance.Configuration({ | ||
registrationFee: REGISTRATION_FEE, | ||
registrationThresholdFactor: 0.01 ether, | ||
unregistrationThresholdFactor: 4 ether, | ||
unregistrationAfterEpochs: 4, | ||
votingThresholdFactor: 0.04 ether, | ||
minClaim: 0, | ||
minAccrual: 0, | ||
epochStart: START_TIME - EPOCH_DURATION, | ||
epochDuration: EPOCH_DURATION, | ||
epochVotingCutoff: EPOCH_DURATION - 1 days | ||
}); | ||
|
||
MockStakingV1 stakingV1; | ||
MockERC20Tester lqty; | ||
MockERC20Tester lusd; | ||
MockERC20Tester bold; | ||
Governance governance; | ||
|
||
address[] initiativesToReset; | ||
address[] initiatives; | ||
int88[] votes; | ||
int88[] vetos; | ||
|
||
function setUp() external { | ||
vm.warp(START_TIME); | ||
|
||
vm.label(deployer, "deployer"); | ||
vm.label(voter, "voter"); | ||
vm.label(registrant, "registrant"); | ||
vm.label(initialInitiative, "initialInitiative"); | ||
vm.label(newInitiative, "newInitiative"); | ||
|
||
(stakingV1, lqty, lusd) = deployMockStakingV1(); | ||
bold = new MockERC20Tester("BOLD Stablecoin", "BOLD"); | ||
|
||
initiatives.push(initialInitiative); | ||
|
||
vm.prank(deployer); | ||
governance = new Governance({ | ||
_lqty: address(lqty), | ||
_lusd: address(lusd), | ||
_stakingV1: address(stakingV1), | ||
_bold: address(bold), | ||
_config: config, | ||
_owner: deployer, | ||
_initiatives: initiatives | ||
}); | ||
|
||
vm.label(governance.deriveUserProxyAddress(voter), "voterProxy"); | ||
} | ||
|
||
function test_AtStart_WeAreInEpoch2() external view { | ||
assertEq(governance.epoch(), 2, "We should start in epoch #2"); | ||
} | ||
|
||
function test_OneEpochLater_WeAreInEpoch3() external { | ||
vm.warp(block.timestamp + EPOCH_DURATION); | ||
assertEq(governance.epoch(), 3, "We should be in epoch #3"); | ||
} | ||
|
||
function test_AtStart_CanVoteOnInitialInitiative() external { | ||
_voteOnInitiative(); | ||
|
||
uint256 boldAccrued = 1 ether; | ||
bold.mint(address(governance), boldAccrued); | ||
vm.warp(block.timestamp + EPOCH_DURATION); | ||
|
||
governance.claimForInitiative(initialInitiative); | ||
assertEqDecimal(bold.balanceOf(initialInitiative), boldAccrued, 18, "Initiative should have received BOLD"); | ||
} | ||
|
||
function test_AtStart_CannotRegisterNewInitiative() external { | ||
_registerNewInitiative({expectRevertReason: "Governance: registration-not-yet-enabled"}); | ||
} | ||
|
||
function test_OneEpochLater_WhenNoOneVotedDuringEpoch2_CanRegisterNewInitiativeWithNoLQTY() external { | ||
vm.warp(block.timestamp + EPOCH_DURATION); | ||
_registerNewInitiative(); | ||
} | ||
|
||
function test_OneEpochLater_WhenSomeoneVotedDuringEpoch2_CannotRegisterNewInitiativeWithNoLQTY() external { | ||
_voteOnInitiative(); | ||
vm.warp(block.timestamp + EPOCH_DURATION); | ||
_registerNewInitiative({expectRevertReason: "Governance: insufficient-lqty"}); | ||
_depositLQTY(); // Only LQTY deposited during previous epoch counts | ||
_registerNewInitiative({expectRevertReason: "Governance: insufficient-lqty"}); | ||
} | ||
|
||
function test_OneEpochLater_WhenSomeoneVotedDuringEpoch2_CanRegisterNewInitiativeWithSufficientLQTY() external { | ||
_voteOnInitiative(); | ||
_depositLQTY(); | ||
vm.warp(block.timestamp + EPOCH_DURATION); | ||
_registerNewInitiative(); | ||
} | ||
|
||
///////////// | ||
// Helpers // | ||
///////////// | ||
|
||
function _voteOnInitiative() internal { | ||
uint88 lqtyAmount = 1 ether; | ||
lqty.mint(voter, lqtyAmount); | ||
|
||
votes.push(int88(lqtyAmount)); | ||
vetos.push(0); | ||
|
||
vm.startPrank(voter); | ||
lqty.approve(governance.deriveUserProxyAddress(voter), lqtyAmount); | ||
governance.depositLQTY(lqtyAmount); | ||
governance.allocateLQTY(initiativesToReset, initiatives, votes, vetos); | ||
vm.stopPrank(); | ||
|
||
delete votes; | ||
delete vetos; | ||
} | ||
|
||
function _registerNewInitiative() internal { | ||
_registerNewInitiative(""); | ||
} | ||
|
||
function _registerNewInitiative(bytes memory expectRevertReason) internal { | ||
bold.mint(registrant, REGISTRATION_FEE); | ||
vm.startPrank(registrant); | ||
bold.approve(address(governance), REGISTRATION_FEE); | ||
if (expectRevertReason.length > 0) vm.expectRevert(expectRevertReason); | ||
governance.registerInitiative(newInitiative); | ||
vm.stopPrank(); | ||
} | ||
|
||
function _depositLQTY() internal { | ||
uint88 lqtyAmount = 1 ether; | ||
lqty.mint(registrant, lqtyAmount); | ||
vm.startPrank(registrant); | ||
lqty.approve(governance.deriveUserProxyAddress(registrant), lqtyAmount); | ||
governance.depositLQTY(lqtyAmount); | ||
vm.stopPrank(); | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice tests here!