Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Unit tests for MixinScheduler #2314

Merged
merged 2 commits into from
Nov 5, 2019
Merged

Conversation

hysz
Copy link
Contributor

@hysz hysz commented Nov 4, 2019

Description

This PR includes unit tests for MixinScheduler in the Staking Contracts.

Testing instructions

Types of changes

Checklist:

  • Prefix PR title with [WIP] if necessary.
  • Add tests to cover changes as needed.
  • Update documentation as needed.
  • Add new entries to the relevant CHANGELOG.jsons.

@coveralls
Copy link

coveralls commented Nov 5, 2019

Coverage Status

Coverage remained the same at 75.286% when pulling 9b2231e on tests/3.0/MixinSchedulerUnitTests into 3c6c412 on development.

Copy link
Contributor

@moodlezoup moodlezoup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me, just a minor nit and q

// (i) Set `epochDurationInSeconds` to a constant value of 1, and
// (ii) Rearrange the eqn above to get:
// `currentEpochStartTimeInSeconds = epochEndTimeDelta + block.timestamp - epochDurationInSeconds`
epochDurationInSeconds = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we set this to 1? can we use a more realistic value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value just needs to be non-zero. Allows us to verify that the endTime is accounting for both currentEpochStartTimeInSeconds and epochDurationInSeconds.

Comment on lines +109 to +117
// Mine the block that this tx would've been in.
await env.web3Wrapper.mineBlockAsync();
const blockNumber = await env.web3Wrapper.getBlockNumberAsync();
const blockTimestampAsNumber = await env.web3Wrapper.getBlockTimestampAsync(blockNumber);
const blockTimestamp = new BigNumber(blockTimestampAsNumber);
const epochEndTime = blockTimestamp.plus(epochEndTimeDelta);
return expect(tx).to.revertWith(
new StakingRevertErrors.BlockTimestampTooLowError(epochEndTime, blockTimestamp),
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

Comment on lines 84 to 85
expect(currentEpoch).to.bignumber.equal(testLog.oldEpoch.plus(1));
expect(currentEpochStartTimeInSeconds).to.bignumber.equal(testLog.blockTimestamp);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional nit: use verifyEventsFromLogs for these events

Copy link
Contributor

@jalextowle jalextowle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice coverage! Just a few cleanup related nits, and then this looks g2g.

} catch (e) {}

// Mine the block that this tx would've been in.
await env.web3Wrapper.mineBlockAsync();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pretty cool pattern. Might make sense to make a function and put in test-utils, but optional for this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏 - although it's such an edge case idk if it would be worth abstracting as-is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough lol

contracts/staking/test/unit_tests/mixin_scheduler_test.ts Outdated Show resolved Hide resolved
contracts/staking/test/unit_tests/mixin_scheduler_test.ts Outdated Show resolved Hide resolved
contracts/staking/test/unit_tests/mixin_scheduler_test.ts Outdated Show resolved Hide resolved
expect(currentEpochStartTimeInSeconds).to.bignumber.equal(testLog.blockTimestamp);
});

it('Should succeed if epoch end time is equal to block timestamp', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rigor lvl 💯

Copy link
Contributor

@jalextowle jalextowle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved (modulo "static-tests")

@hysz hysz force-pushed the tests/3.0/MixinSchedulerUnitTests branch from 87b8cc8 to 9b2231e Compare November 5, 2019 23:00
@hysz hysz merged commit a902235 into development Nov 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants