Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx committed Jul 26, 2022
1 parent e5d5d0f commit 1c10cfc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
},
"homepage": "https://openzeppelin.com/contracts/",
"devDependencies": {
"@nomicfoundation/hardhat-network-helpers": "^1.0.3",
"@nomiclabs/hardhat-truffle5": "^2.0.5",
"@nomiclabs/hardhat-web3": "^2.0.0",
"@openzeppelin/docs-utils": "^0.1.0",
Expand Down
30 changes: 16 additions & 14 deletions test/finance/VestingWallet.behavior.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { time } = require('@nomicfoundation/hardhat-network-helpers');
const { expectEvent } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');

Expand All @@ -9,26 +10,32 @@ function releasedEvent (token, amount) {

function shouldBehaveLikeVesting (beneficiary) {
it('check vesting schedule', async function () {
const [ method, ...args ] = this.token
? [ 'vestedAmount(address,uint64)', this.token.address ]
: [ 'vestedAmount(uint64)' ];
const [ fnVestedAmount, fnReleasable, ...args ] = this.token
? [ 'vestedAmount(address,uint64)', 'releasable(address)', this.token.address ]
: [ 'vestedAmount(uint64)', 'releasable()' ];

for (const timestamp of this.schedule) {
expect(await this.mock.methods[method](...args, timestamp))
.to.be.bignumber.equal(this.vestingFn(timestamp));
await time.increaseTo(timestamp);
const vesting = this.vestingFn(timestamp);

expect(await this.mock.methods[fnVestedAmount](...args, timestamp))
.to.be.bignumber.equal(vesting);

expect(await this.mock.methods[fnReleasable](...args))
.to.be.bignumber.equal(vesting);
}
});

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

let released = web3.utils.toBN(0);
const before = await this.getBalance(beneficiary);

{
const receipt = await this.mock.methods[method](...args);
const receipt = await this.mock.methods[fnRelease](...args);

await expectEvent.inTransaction(
receipt.tx,
Expand All @@ -42,15 +49,10 @@ function shouldBehaveLikeVesting (beneficiary) {
}

for (const timestamp of this.schedule) {
await time.setNextBlockTimestamp(timestamp);
const vested = this.vestingFn(timestamp);

await new Promise(resolve => web3.currentProvider.send({
method: 'evm_setNextBlockTimestamp',
params: [ timestamp.toNumber() ],
}, resolve));

const receipt = await this.mock.methods[method](...args);

const receipt = await this.mock.methods[fnRelease](...args);
await expectEvent.inTransaction(
receipt.tx,
this.mock,
Expand Down

0 comments on commit 1c10cfc

Please sign in to comment.