Skip to content

Commit

Permalink
test: fix E2E tests when epoch #2 is in the future
Browse files Browse the repository at this point in the history
  • Loading branch information
danielattilasimon committed Jan 17, 2025
1 parent db8c49b commit cd56861
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions contracts/test/E2E.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ contract E2ETest is Test {

uint256 ETH_GAS_COMPENSATION;
uint256 MIN_DEBT;
uint256 EPOCH_START;
uint256 EPOCH_DURATION;
uint256 REGISTRATION_FEE;

Expand Down Expand Up @@ -205,6 +206,7 @@ contract E2ETest is Test {

ETH_GAS_COMPENSATION = json.readUint(".constants.ETH_GAS_COMPENSATION");
MIN_DEBT = json.readUint(".constants.MIN_DEBT");
EPOCH_START = json.readUint(".governance.constants.EPOCH_START");
EPOCH_DURATION = json.readUint(".governance.constants.EPOCH_DURATION");
REGISTRATION_FEE = json.readUint(".governance.constants.REGISTRATION_FEE");
LQTY = json.readAddress(".governance.LQTYToken");
Expand Down Expand Up @@ -627,14 +629,21 @@ contract E2ETest is Test {
}
}

function _epoch(uint256 n) internal view returns (uint256) {
return EPOCH_START + (n - 1) * EPOCH_DURATION;
}

function test_Initially_NewInitiativeCannotBeRegistered() external {
vm.skip(governance.epoch() != 2);
vm.skip(governance.epoch() > 2);

address registrant = makeAddr("registrant");
address newInitiative = makeAddr("newInitiative");

_openTrove(0, registrant, 0, Math.max(REGISTRATION_FEE, MIN_DEBT));

uint256 epoch2 = _epoch(2);
if (block.timestamp < epoch2) vm.warp(epoch2);

vm.startPrank(registrant);
{
boldToken.approve(address(governance), REGISTRATION_FEE);
Expand All @@ -645,14 +654,15 @@ contract E2ETest is Test {
}

function test_AfterOneEpoch_NewInitiativeCanBeRegistered() external {
vm.skip(governance.epoch() != 2);
vm.skip(governance.epoch() > 2);

address registrant = makeAddr("registrant");
address newInitiative = makeAddr("newInitiative");

_openTrove(0, registrant, 0, Math.max(REGISTRATION_FEE, MIN_DEBT));

skip(EPOCH_DURATION);
uint256 epoch3 = _epoch(3);
if (block.timestamp < epoch3) vm.warp(epoch3);

vm.startPrank(registrant);
{
Expand Down Expand Up @@ -790,8 +800,13 @@ contract E2ETest is Test {
);
assertApproxEqAbsDecimal(staker.balance, ethAmount * lqtyStake / totalLQTYStaked, 1e5, 18, "ETH reward");

skip(5 minutes);

if (numInitiatives > 0) {
skip(5 minutes);
// Voting on initial initiatives opens in epoch #2
uint256 votingStart = _epoch(2);
if (block.timestamp < votingStart) vm.warp(votingStart);

_allocateLQTY_begin(staker);

for (uint256 i = 0; i < initiatives.length; ++i) {
Expand Down

0 comments on commit cd56861

Please sign in to comment.