This repository has been archived by the owner on Jul 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEpoch.test.ts
106 lines (89 loc) · 3.36 KB
/
Epoch.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import chai, { expect } from 'chai';
import { ethers } from 'hardhat';
import { solidity } from 'ethereum-waffle';
import { Contract, ContractFactory, BigNumber, utils } from 'ethers';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/dist/src/signer-with-address';
import { advanceTimeAndBlock, latestBlocktime } from './shared/utilities';
chai.use(solidity);
describe('Epoch', () => {
const DAY = 86400;
const ETH = utils.parseEther('1');
const ZERO = BigNumber.from(0);
const { provider } = ethers;
let operator: SignerWithAddress;
before('provider & accounts setting', async () => {
[operator] = await ethers.getSigners();
});
let Epoch: ContractFactory;
before('fetch contract factories', async () => {
Epoch = await ethers.getContractFactory('EpochTester');
});
let epoch: Contract;
beforeEach('deploy contracts', async () => {
epoch = await Epoch.connect(operator).deploy(
DAY,
(await latestBlocktime(provider)) + DAY,
0
);
});
it('#getLastEpoch', async () => {
expect(await epoch.getLastEpoch()).to.eq(0);
await advanceTimeAndBlock(provider, DAY);
await epoch.testCheckEpoch();
expect(await epoch.getLastEpoch()).to.eq(0);
await advanceTimeAndBlock(provider, DAY);
await epoch.testCheckEpoch();
expect(await epoch.getLastEpoch()).to.eq(1);
await advanceTimeAndBlock(provider, DAY);
await epoch.testCheckEpoch();
expect(await epoch.getLastEpoch()).to.eq(2);
await advanceTimeAndBlock(provider, DAY);
await advanceTimeAndBlock(provider, DAY);
await epoch.testCheckEpoch();
expect(await epoch.getLastEpoch()).to.eq(4);
});
it('#getCurrentEpoch', async () => {
expect(await epoch.getCurrentEpoch()).to.eq(0);
await advanceTimeAndBlock(provider, DAY);
expect(await epoch.getCurrentEpoch()).to.eq(0);
await advanceTimeAndBlock(provider, DAY);
expect(await epoch.getCurrentEpoch()).to.eq(1);
await advanceTimeAndBlock(provider, DAY);
expect(await epoch.getCurrentEpoch()).to.eq(2);
await advanceTimeAndBlock(provider, DAY);
await advanceTimeAndBlock(provider, DAY);
expect(await epoch.getCurrentEpoch()).to.eq(4);
});
it('#getNextEpoch', async () => {
expect(await epoch.getNextEpoch()).to.eq(0);
await advanceTimeAndBlock(provider, DAY);
await epoch.testCheckEpoch();
expect(await epoch.getNextEpoch()).to.eq(1);
await advanceTimeAndBlock(provider, DAY);
await epoch.testCheckEpoch();
expect(await epoch.getNextEpoch()).to.eq(2);
await advanceTimeAndBlock(provider, DAY);
await epoch.testCheckEpoch();
expect(await epoch.getNextEpoch()).to.eq(3);
await advanceTimeAndBlock(provider, DAY);
await advanceTimeAndBlock(provider, DAY);
await epoch.testCheckEpoch();
expect(await epoch.getNextEpoch()).to.eq(5);
});
describe('before startTime', () => {
it('check status', async () => {
expect(await epoch.getLastEpoch()).to.eq(0);
expect(await epoch.getCurrentEpoch()).to.eq(0);
expect(await epoch.getNextEpoch()).to.eq(0);
expect(await epoch.nextEpochPoint()).to.eq(await epoch.getStartTime());
});
it('should fail', async () => {
await expect(epoch.testCheckStartTime()).to.revertedWith(
'Epoch: not started yet'
);
await expect(epoch.testCheckEpoch()).to.revertedWith(
'Epoch: not started yet'
);
});
});
});