Skip to content
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

[legacy gov] Preparations for epoch 5 #1973

Merged
merged 3 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading