Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
revert test changes
  • Loading branch information
frangio committed Aug 4, 2023
commit 085aaf6646c8a2fa906de2a41d202732eadf20f2
60 changes: 21 additions & 39 deletions test/finance/VestingWallet.behavior.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
const { time, setNextBlockBaseFeePerGas } = require('@nomicfoundation/hardhat-network-helpers');
const { time } = require('@nomicfoundation/hardhat-network-helpers');
const { expectEvent } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const { web3 } = require('hardhat');
const { expectRevertCustomError } = require('../helpers/customError');

function releasedEvent(token, amount) {
return token ? ['ERC20Released', { token: token.address, amount }] : ['EtherReleased', { amount }];
}

function shouldBehaveLikeVesting(beneficiary, accounts) {
function shouldBehaveLikeVesting(beneficiary) {
it('check vesting schedule', async function () {
const [vestedAmount, releasable, ...args] = this.token
? ['vestedAmount(address,uint64)', 'releasable(address)', this.token.address]
Expand All @@ -24,51 +22,35 @@ function shouldBehaveLikeVesting(beneficiary, accounts) {
}
});

describe('execute vesting schedule', async function () {
beforeEach(async function () {
[this.release, ...this.args] = this.token ? ['release(address)', this.token.address] : ['release()'];
});
it('execute vesting schedule', async function () {
const [release, ...args] = this.token ? ['release(address)', this.token.address] : ['release()'];

it('releases a linearly vested schedule', async function () {
let released = web3.utils.toBN(0);
const before = await this.getBalance(beneficiary);
const releaser = await this.mock.owner();
let released = web3.utils.toBN(0);
const before = await this.getBalance(beneficiary);

{
// Allows gas price to be 0 so no ETH is spent in the transaction.
await setNextBlockBaseFeePerGas(0);
{
const receipt = await this.mock.methods[release](...args);

const receipt = await this.mock.methods[this.release](...this.args, { from: releaser, gasPrice: 0 });
await expectEvent.inTransaction(receipt.tx, this.mock, ...releasedEvent(this.token, '0'));
await this.checkRelease(receipt, beneficiary, '0');
await expectEvent.inTransaction(receipt.tx, this.mock, ...releasedEvent(this.token, '0'));

expect(await this.getBalance(beneficiary)).to.be.bignumber.equal(before);
}
await this.checkRelease(receipt, beneficiary, '0');

for (const timestamp of this.schedule) {
await time.setNextBlockTimestamp(timestamp);
const vested = this.vestingFn(timestamp);
expect(await this.getBalance(beneficiary)).to.be.bignumber.equal(before);
}

// Allows gas price to be 0 so no ETH is spent in the transaction.
await setNextBlockBaseFeePerGas(0);
for (const timestamp of this.schedule) {
await time.setNextBlockTimestamp(timestamp);
const vested = this.vestingFn(timestamp);

const receipt = await this.mock.methods[this.release](...this.args, { from: releaser, gasPrice: 0 });
await expectEvent.inTransaction(receipt.tx, this.mock, ...releasedEvent(this.token, vested.sub(released)));
await this.checkRelease(receipt, beneficiary, vested.sub(released));
const receipt = await this.mock.methods[release](...args);
await expectEvent.inTransaction(receipt.tx, this.mock, ...releasedEvent(this.token, vested.sub(released)));

expect(await this.getBalance(beneficiary)).to.be.bignumber.equal(before.add(vested));
await this.checkRelease(receipt, beneficiary, vested.sub(released));

released = vested;
}
});
expect(await this.getBalance(beneficiary)).to.be.bignumber.equal(before.add(vested));

it('cannot be released by a non releaser', async function () {
await expectRevertCustomError(
this.mock.methods[this.release](...this.args, { from: accounts[0] }),
'OwnableUnauthorizedAccount',
[accounts[0]],
);
});
released = vested;
}
});
}

Expand Down
11 changes: 2 additions & 9 deletions test/finance/VestingWallet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ contract('VestingWallet', function (accounts) {
beforeEach(async function () {
this.start = (await time.latest()).addn(3600); // in 1 hour
this.mock = await VestingWallet.new(beneficiary, this.start, duration);
await this.mock.acceptOwnership({ from: beneficiary });
});

it('rejects zero address for beneficiary', async function () {
Expand All @@ -29,12 +28,6 @@ contract('VestingWallet', function (accounts) {
);
});

it('sets the initial owner as the sender (benefactor)', async function () {
this.mock = await VestingWallet.new(beneficiary, this.start, duration, { from: sender });
expect(await this.mock.owner()).to.be.equal(sender);
expect(await this.mock.pendingOwner()).to.be.equal(beneficiary);
});

it('check vesting contract', async function () {
expect(await this.mock.owner()).to.be.equal(beneficiary);
expect(await this.mock.start()).to.be.bignumber.equal(this.start);
Expand All @@ -57,7 +50,7 @@ contract('VestingWallet', function (accounts) {
this.checkRelease = () => {};
});

shouldBehaveLikeVesting(beneficiary, accounts);
shouldBehaveLikeVesting(beneficiary);
});

describe('ERC20 vesting', function () {
Expand All @@ -70,7 +63,7 @@ contract('VestingWallet', function (accounts) {
await this.token.$_mint(this.mock.address, amount);
});

shouldBehaveLikeVesting(beneficiary, accounts);
shouldBehaveLikeVesting(beneficiary);
});
});
});