Skip to content

Commit

Permalink
feat: e2e test for unregistering
Browse files Browse the repository at this point in the history
  • Loading branch information
GalloDaSballo committed Oct 16, 2024
1 parent e4ef357 commit 62ed071
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/Governance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,7 @@ contract Governance is Multicall, UserProxyFactory, ReentrancyGuard, IGovernance


// == Unregister Condition == //
/// @audit epoch() - 1 because we can have Now - 1 and that's not a removal case | TODO: Double check | Worst case QA, off by one epoch
/// This shifts the logic by 1 epoch
// e.g. if `UNREGISTRATION_AFTER_EPOCHS` is 4, the 4th epoch flip that would result in SKIP, will result in the initiative being `UNREGISTERABLE`
if((initiativeState.lastEpochClaim + UNREGISTRATION_AFTER_EPOCHS < epoch() - 1)
|| votesForInitiativeSnapshot_.vetos > votesForInitiativeSnapshot_.votes
&& votesForInitiativeSnapshot_.vetos > votingTheshold * UNREGISTRATION_THRESHOLD_FACTOR / WAD
Expand Down
54 changes: 54 additions & 0 deletions test/E2E.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,55 @@ contract E2ETests is Test {
_allocate(address(0x123123), 1e18, 0);
}


// forge test --match-test test_deregisterIsSound -vv
function test_deregisterIsSound() public {

// Deregistration works as follows:
// We stop voting
// We wait for `UNREGISTRATION_AFTER_EPOCHS`
// The initiative is removed
vm.startPrank(user);
// Check that we can vote on the first epoch, right after deployment
_deposit(1000e18);

console.log("epoch", governance.epoch());
_allocate(baseInitiative1, 1e18, 0); // Doesn't work due to cool down I think


// And for sanity, you cannot vote on new ones, they need to be added first
deal(address(lusd), address(user), REGISTRATION_FEE);
lusd.approve(address(governance), REGISTRATION_FEE);

address newInitiative = address(0x123123);
governance.registerInitiative(newInitiative);
assertEq(uint256(Governance.InitiativeStatus.COOLDOWN) , _getInitiativeStatus(newInitiative), "Cooldown");

uint256 skipCount;

// Whereas in next week it will work
vm.warp(block.timestamp + EPOCH_DURATION); // 1
_allocate(newInitiative, 100, 0); // Will not meet the treshold
++skipCount;
assertEq(uint256(Governance.InitiativeStatus.SKIP) ,_getInitiativeStatus(newInitiative), "SKIP");

// Cooldown on epoch Staert

vm.warp(block.timestamp + EPOCH_DURATION); // 2
++skipCount;
assertEq(uint256(Governance.InitiativeStatus.SKIP) ,_getInitiativeStatus(newInitiative), "SKIP");

vm.warp(block.timestamp + EPOCH_DURATION); // 3
++skipCount;
assertEq(uint256(Governance.InitiativeStatus.SKIP) ,_getInitiativeStatus(newInitiative), "SKIP");

vm.warp(block.timestamp + EPOCH_DURATION); // 4
++skipCount;
assertEq(uint256(Governance.InitiativeStatus.UNREGISTERABLE) ,_getInitiativeStatus(newInitiative), "UNREGISTERABLE");

assertEq(skipCount, UNREGISTRATION_AFTER_EPOCHS, "Skipped exactly UNREGISTRATION_AFTER_EPOCHS");
}

function _deposit(uint88 amt) internal {
address userProxy = governance.deployUserProxy();

Expand All @@ -138,4 +187,9 @@ contract E2ETests is Test {
governance.allocateLQTY(initiatives, deltaLQTYVotes, deltaLQTYVetos);
}

function _getInitiativeStatus(address _initiative) internal returns (uint256) {
(Governance.InitiativeStatus status, , ) = governance.getInitiativeState(_initiative);
return uint256(status);
}

}
5 changes: 5 additions & 0 deletions test/recon/Setup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,10 @@ abstract contract Setup is BaseSetup {
function _getRandomUser(uint8 index) internal returns (address randomUser) {
return users[index % users.length];
}

function _getInitiativeStatus(address _initiative) internal returns (uint256) {
(Governance.InitiativeStatus status, , ) = governance.getInitiativeState(_getDeployedInitiative(0));
return uint256(status);
}

}
6 changes: 0 additions & 6 deletions test/recon/trophies/TrophiesToFoundry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,5 @@ function test_property_sum_of_lqty_global_user_matches_0() public {
property_sum_of_lqty_global_user_matches();
}

function _getInitiativeStatus(address _initiative) internal returns (uint256) {
(Governance.InitiativeStatus status, , ) = governance.getInitiativeState(_getDeployedInitiative(0));
return uint256(status);
}



}

0 comments on commit 62ed071

Please sign in to comment.