Migrate utils to ethersjs v6 (#4736)

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Co-authored-by: ernestognw <ernestognw@gmail.com>
This commit is contained in:
Renan Souza
2023-11-24 01:32:30 +00:00
committed by GitHub
parent 330c39b662
commit 78d5708340
13 changed files with 497 additions and 602 deletions

View File

@ -1,83 +1,87 @@
const { expectEvent } = require('@openzeppelin/test-helpers');
const { ethers } = require('hardhat');
const { expect } = require('chai');
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
const { expectRevertCustomError } = require('../helpers/customError');
async function fixture() {
const [pauser] = await ethers.getSigners();
const PausableMock = artifacts.require('PausableMock');
const mock = await ethers.deployContract('PausableMock');
contract('Pausable', function (accounts) {
const [pauser] = accounts;
return { pauser, mock };
}
describe('Pausable', function () {
beforeEach(async function () {
this.pausable = await PausableMock.new();
Object.assign(this, await loadFixture(fixture));
});
context('when unpaused', function () {
describe('when unpaused', function () {
beforeEach(async function () {
expect(await this.pausable.paused()).to.equal(false);
expect(await this.mock.paused()).to.be.false;
});
it('can perform normal process in non-pause', async function () {
expect(await this.pausable.count()).to.be.bignumber.equal('0');
expect(await this.mock.count()).to.equal(0n);
await this.pausable.normalProcess();
expect(await this.pausable.count()).to.be.bignumber.equal('1');
await this.mock.normalProcess();
expect(await this.mock.count()).to.equal(1n);
});
it('cannot take drastic measure in non-pause', async function () {
await expectRevertCustomError(this.pausable.drasticMeasure(), 'ExpectedPause', []);
expect(await this.pausable.drasticMeasureTaken()).to.equal(false);
await expect(this.mock.drasticMeasure()).to.be.revertedWithCustomError(this.mock, 'ExpectedPause');
expect(await this.mock.drasticMeasureTaken()).to.be.false;
});
context('when paused', function () {
describe('when paused', function () {
beforeEach(async function () {
this.receipt = await this.pausable.pause({ from: pauser });
this.tx = await this.mock.pause();
});
it('emits a Paused event', function () {
expectEvent(this.receipt, 'Paused', { account: pauser });
it('emits a Paused event', async function () {
await expect(this.tx).to.emit(this.mock, 'Paused').withArgs(this.pauser.address);
});
it('cannot perform normal process in pause', async function () {
await expectRevertCustomError(this.pausable.normalProcess(), 'EnforcedPause', []);
await expect(this.mock.normalProcess()).to.be.revertedWithCustomError(this.mock, 'EnforcedPause');
});
it('can take a drastic measure in a pause', async function () {
await this.pausable.drasticMeasure();
expect(await this.pausable.drasticMeasureTaken()).to.equal(true);
await this.mock.drasticMeasure();
expect(await this.mock.drasticMeasureTaken()).to.be.true;
});
it('reverts when re-pausing', async function () {
await expectRevertCustomError(this.pausable.pause(), 'EnforcedPause', []);
await expect(this.mock.pause()).to.be.revertedWithCustomError(this.mock, 'EnforcedPause');
});
describe('unpausing', function () {
it('is unpausable by the pauser', async function () {
await this.pausable.unpause();
expect(await this.pausable.paused()).to.equal(false);
await this.mock.unpause();
expect(await this.mock.paused()).to.be.false;
});
context('when unpaused', function () {
describe('when unpaused', function () {
beforeEach(async function () {
this.receipt = await this.pausable.unpause({ from: pauser });
this.tx = await this.mock.unpause();
});
it('emits an Unpaused event', function () {
expectEvent(this.receipt, 'Unpaused', { account: pauser });
it('emits an Unpaused event', async function () {
await expect(this.tx).to.emit(this.mock, 'Unpaused').withArgs(this.pauser.address);
});
it('should resume allowing normal process', async function () {
expect(await this.pausable.count()).to.be.bignumber.equal('0');
await this.pausable.normalProcess();
expect(await this.pausable.count()).to.be.bignumber.equal('1');
expect(await this.mock.count()).to.equal(0n);
await this.mock.normalProcess();
expect(await this.mock.count()).to.equal(1n);
});
it('should prevent drastic measure', async function () {
await expectRevertCustomError(this.pausable.drasticMeasure(), 'ExpectedPause', []);
await expect(this.mock.drasticMeasure()).to.be.revertedWithCustomError(this.mock, 'ExpectedPause');
});
it('reverts when re-unpausing', async function () {
await expectRevertCustomError(this.pausable.unpause(), 'ExpectedPause', []);
await expect(this.mock.unpause()).to.be.revertedWithCustomError(this.mock, 'ExpectedPause');
});
});
});