Skip to content

Commit

Permalink
allow to change dates during nomination period
Browse files Browse the repository at this point in the history
  • Loading branch information
mjlescano committed Dec 18, 2023
1 parent ac12286 commit 58f24b3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
4 changes: 2 additions & 2 deletions packages/core-modules/contracts/modules/ElectionModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ contract ElectionModule is
uint64 newNominationPeriodStartDate,
uint64 newVotingPeriodStartDate,
uint64 newEpochEndDate
) external override onlyOwner onlyInPeriod(ElectionPeriod.Administration) {
) external override onlyOwner onlyInPeriods(ElectionPeriod.Administration, ElectionPeriod.Nomination) {
_adjustEpochSchedule(
_getCurrentEpoch(),
newNominationPeriodStartDate,
Expand All @@ -115,7 +115,7 @@ contract ElectionModule is
uint64 newNominationPeriodStartDate,
uint64 newVotingPeriodStartDate,
uint64 newEpochEndDate
) external override onlyOwner onlyInPeriod(ElectionPeriod.Administration) {
) external override onlyOwner onlyInPeriods(ElectionPeriod.Administration, ElectionPeriod.Nomination) {
_adjustEpochSchedule(
_getCurrentEpoch(),
newNominationPeriodStartDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ contract ElectionSchedule is ElectionBase {
bool ensureChangesAreSmall
) internal {
uint64 maxDateAdjustmentTolerance = _electionSettings().maxDateAdjustmentTolerance;
ElectionPeriod initialPeriod = _getCurrentPeriod();

if (ensureChangesAreSmall) {
if (
Expand All @@ -134,7 +135,7 @@ contract ElectionSchedule is ElectionBase {
newEpochEndDate
);

if (_getCurrentPeriod() != ElectionPeriod.Administration) {
if (_getCurrentPeriod() != initialPeriod) {
revert ChangesCurrentPeriod();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('ElectionModule (schedule)', () => {
};

// ----------------------------------
// Evaluation behaviors
// Adjustments behaviors
// ----------------------------------

const itRejectsAdjustments = () => {
Expand All @@ -155,17 +155,13 @@ describe('ElectionModule (schedule)', () => {
const itAcceptsAdjustments = () => {
describe('when trying to adjust the epoch schedule', function () {
before('fast forward', async function () {
await fastForwardTo(
(await ElectionModule.getNominationPeriodStartDate()) - daysToSeconds(1),
ethers.provider
);
});
const currentPeriod = (await ElectionModule.getCurrentPeriod()).toNumber();
const targetTimestamp =
currentPeriod === ElectionPeriod.Administration
? await ElectionModule.getNominationPeriodStartDate()
: await ElectionModule.getVotingPeriodStartDate();

before('fast forward', async function () {
await fastForwardTo(
(await ElectionModule.getNominationPeriodStartDate()) - daysToSeconds(1),
ethers.provider
);
await fastForwardTo(targetTimestamp.toNumber() - daysToSeconds(1), ethers.provider);
});

before('take snapshot', async function () {
Expand Down Expand Up @@ -230,7 +226,7 @@ describe('ElectionModule (schedule)', () => {
ElectionModule.tweakEpochSchedule(
(await ElectionModule.getNominationPeriodStartDate()).toNumber() -
daysToSeconds(2),
(await ElectionModule.getVotingPeriodStartDate()).toNumber() + daysToSeconds(0.5),
(await ElectionModule.getVotingPeriodStartDate()).toNumber() - daysToSeconds(2),
(await ElectionModule.getEpochEndDate()).toNumber() + daysToSeconds(4)
),
'ChangesCurrentPeriod'
Expand All @@ -240,13 +236,16 @@ describe('ElectionModule (schedule)', () => {

describe('which dont change the current period type', function () {
before('adjust', async function () {
newEpochEndDate =
(await ElectionModule.getEpochEndDate()).toNumber() + daysToSeconds(4);
newNominationPeriodStartDate =
(await ElectionModule.getNominationPeriodStartDate()).toNumber() -
daysToSeconds(0.5);
const currentPeriod = await ElectionModule.getCurrentPeriod();

newNominationPeriodStartDate = currentPeriod.eq(ElectionPeriod.Administration)
? (await ElectionModule.getNominationPeriodStartDate()).toNumber() +
daysToSeconds(0.5)
: (await ElectionModule.getNominationPeriodStartDate()).toNumber();
newVotingPeriodStartDate =
(await ElectionModule.getVotingPeriodStartDate()).toNumber() + daysToSeconds(0.5);
newEpochEndDate =
(await ElectionModule.getEpochEndDate()).toNumber() + daysToSeconds(4);

const tx = await ElectionModule.tweakEpochSchedule(
newNominationPeriodStartDate,
Expand Down Expand Up @@ -288,7 +287,7 @@ describe('ElectionModule (schedule)', () => {
ElectionModule.modifyEpochSchedule(
(await ElectionModule.getNominationPeriodStartDate()).toNumber() -
daysToSeconds(2),
(await ElectionModule.getVotingPeriodStartDate()).toNumber() + daysToSeconds(100),
(await ElectionModule.getVotingPeriodStartDate()).toNumber() - daysToSeconds(2),
(await ElectionModule.getEpochEndDate()).toNumber() + daysToSeconds(100)
),
'ChangesCurrentPeriod'
Expand All @@ -298,13 +297,15 @@ describe('ElectionModule (schedule)', () => {

describe('which dont change the current period type', function () {
before('adjust', async function () {
newEpochEndDate =
(await ElectionModule.getEpochEndDate()).toNumber() + daysToSeconds(100);
const currentPeriod = await ElectionModule.getCurrentPeriod();

newNominationPeriodStartDate =
(await ElectionModule.getNominationPeriodStartDate()).toNumber() +
daysToSeconds(100);
(currentPeriod.eq(ElectionPeriod.Administration) ? daysToSeconds(100) : 0);
newVotingPeriodStartDate =
(await ElectionModule.getVotingPeriodStartDate()).toNumber() + daysToSeconds(100);
newEpochEndDate =
(await ElectionModule.getEpochEndDate()).toNumber() + daysToSeconds(100);

const tx = await ElectionModule.modifyEpochSchedule(
newNominationPeriodStartDate,
Expand Down Expand Up @@ -416,7 +417,7 @@ describe('ElectionModule (schedule)', () => {
itAcceptsWithdrawals();
itRejectsVotes();
itRejectsEvaluations();
itRejectsAdjustments();
itAcceptsAdjustments();
});

// ----------------------------------
Expand Down

0 comments on commit 58f24b3

Please sign in to comment.