Simplify finance tests (#4912)

This commit is contained in:
Renan Souza
2024-02-22 12:15:26 -03:00
committed by GitHub
parent 141c947921
commit 8b4b7b8d04
3 changed files with 42 additions and 78 deletions

View File

@ -1,6 +1,41 @@
const { ethers } = require('hardhat');
const { expect } = require('chai');
const time = require('../helpers/time');
async function envSetup(mock, beneficiary, token) {
return {
eth: {
checkRelease: async (tx, amount) => {
await expect(tx).to.changeEtherBalances([mock, beneficiary], [-amount, amount]);
},
setupFailure: async () => {
const beneficiaryMock = await ethers.deployContract('EtherReceiverMock');
await beneficiaryMock.setAcceptEther(false);
await mock.connect(beneficiary).transferOwnership(beneficiaryMock);
return { args: [], error: [mock, 'FailedInnerCall'] };
},
releasedEvent: 'EtherReleased',
args: [],
},
token: {
checkRelease: async (tx, amount) => {
await expect(tx).to.emit(token, 'Transfer').withArgs(mock, beneficiary, amount);
await expect(tx).to.changeTokenBalances(token, [mock, beneficiary], [-amount, amount]);
},
setupFailure: async () => {
const pausableToken = await ethers.deployContract('$ERC20Pausable', ['Name', 'Symbol']);
await pausableToken.$_pause();
return {
args: [ethers.Typed.address(pausableToken)],
error: [pausableToken, 'EnforcedPause'],
};
},
releasedEvent: 'ERC20Released',
args: [ethers.Typed.address(token)],
},
};
}
function shouldBehaveLikeVesting() {
it('check vesting schedule', async function () {
for (const timestamp of this.schedule) {
@ -18,7 +53,7 @@ function shouldBehaveLikeVesting() {
const tx = await this.mock.release(...this.args);
await expect(tx)
.to.emit(this.mock, this.releasedEvent)
.withArgs(...this.argsVerify, 0);
.withArgs(...this.args, 0);
await this.checkRelease(tx, 0n);
}
@ -47,5 +82,6 @@ function shouldBehaveLikeVesting() {
}
module.exports = {
envSetup,
shouldBehaveLikeVesting,
};