You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
2.4 KiB
55 lines
2.4 KiB
const { BN, time } = require('@openzeppelin/test-helpers');
|
|
const { expect } = require('chai');
|
|
|
|
const TimersBlockNumberImpl = artifacts.require('TimersBlockNumberImpl');
|
|
|
|
contract('TimersBlockNumber', function () {
|
|
beforeEach(async function () {
|
|
this.instance = await TimersBlockNumberImpl.new();
|
|
this.now = await web3.eth.getBlock('latest').then(({ number }) => number);
|
|
});
|
|
|
|
it('unset', async function () {
|
|
expect(await this.instance.getDeadline()).to.be.bignumber.equal('0');
|
|
expect(await this.instance.isUnset()).to.be.equal(true);
|
|
expect(await this.instance.isStarted()).to.be.equal(false);
|
|
expect(await this.instance.isPending()).to.be.equal(false);
|
|
expect(await this.instance.isExpired()).to.be.equal(false);
|
|
});
|
|
|
|
it('pending', async function () {
|
|
await this.instance.setDeadline(this.now + 3);
|
|
expect(await this.instance.getDeadline()).to.be.bignumber.equal(new BN(this.now + 3));
|
|
expect(await this.instance.isUnset()).to.be.equal(false);
|
|
expect(await this.instance.isStarted()).to.be.equal(true);
|
|
expect(await this.instance.isPending()).to.be.equal(true);
|
|
expect(await this.instance.isExpired()).to.be.equal(false);
|
|
});
|
|
|
|
it('expired', async function () {
|
|
await this.instance.setDeadline(this.now - 3);
|
|
expect(await this.instance.getDeadline()).to.be.bignumber.equal(new BN(this.now - 3));
|
|
expect(await this.instance.isUnset()).to.be.equal(false);
|
|
expect(await this.instance.isStarted()).to.be.equal(true);
|
|
expect(await this.instance.isPending()).to.be.equal(false);
|
|
expect(await this.instance.isExpired()).to.be.equal(true);
|
|
});
|
|
|
|
it('reset', async function () {
|
|
await this.instance.reset();
|
|
expect(await this.instance.getDeadline()).to.be.bignumber.equal(new BN(0));
|
|
expect(await this.instance.isUnset()).to.be.equal(true);
|
|
expect(await this.instance.isStarted()).to.be.equal(false);
|
|
expect(await this.instance.isPending()).to.be.equal(false);
|
|
expect(await this.instance.isExpired()).to.be.equal(false);
|
|
});
|
|
|
|
it('fast forward', async function () {
|
|
await this.instance.setDeadline(this.now + 3);
|
|
expect(await this.instance.isPending()).to.be.equal(true);
|
|
expect(await this.instance.isExpired()).to.be.equal(false);
|
|
await time.advanceBlockTo(this.now + 3);
|
|
expect(await this.instance.isPending()).to.be.equal(false);
|
|
expect(await this.instance.isExpired()).to.be.equal(true);
|
|
});
|
|
});
|
|
|