VestingWalletCliff.test.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. const { ethers } = require('hardhat');
  2. const { expect } = require('chai');
  3. const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
  4. const { min } = require('../helpers/math');
  5. const time = require('../helpers/time');
  6. const { envSetup, shouldBehaveLikeVesting } = require('./VestingWallet.behavior');
  7. async function fixture() {
  8. const amount = ethers.parseEther('100');
  9. const duration = time.duration.years(4);
  10. const start = (await time.clock.timestamp()) + time.duration.hours(1);
  11. const cliffDuration = time.duration.years(1);
  12. const cliff = start + cliffDuration;
  13. const [sender, beneficiary] = await ethers.getSigners();
  14. const mock = await ethers.deployContract('$VestingWalletCliff', [beneficiary, start, duration, cliffDuration]);
  15. const token = await ethers.deployContract('$ERC20', ['Name', 'Symbol']);
  16. await token.$_mint(mock, amount);
  17. await sender.sendTransaction({ to: mock, value: amount });
  18. const env = await envSetup(mock, beneficiary, token);
  19. const schedule = Array.from({ length: 64 }, (_, i) => (BigInt(i) * duration) / 60n + start);
  20. const vestingFn = timestamp => min(amount, timestamp < cliff ? 0n : (amount * (timestamp - start)) / duration);
  21. return { mock, duration, start, beneficiary, cliff, schedule, vestingFn, env };
  22. }
  23. describe('VestingWalletCliff', function () {
  24. beforeEach(async function () {
  25. Object.assign(this, await loadFixture(fixture));
  26. });
  27. it('rejects a larger cliff than vesting duration', async function () {
  28. await expect(
  29. ethers.deployContract('$VestingWalletCliff', [this.beneficiary, this.start, this.duration, this.duration + 1n]),
  30. )
  31. .revertedWithCustomError(this.mock, 'InvalidCliffDuration')
  32. .withArgs(this.duration + 1n, this.duration);
  33. });
  34. it('check vesting contract', async function () {
  35. expect(await this.mock.owner()).to.equal(this.beneficiary);
  36. expect(await this.mock.start()).to.equal(this.start);
  37. expect(await this.mock.duration()).to.equal(this.duration);
  38. expect(await this.mock.end()).to.equal(this.start + this.duration);
  39. expect(await this.mock.cliff()).to.equal(this.cliff);
  40. });
  41. describe('vesting schedule', function () {
  42. describe('Eth vesting', function () {
  43. beforeEach(async function () {
  44. Object.assign(this, this.env.eth);
  45. });
  46. shouldBehaveLikeVesting();
  47. });
  48. describe('ERC20 vesting', function () {
  49. beforeEach(async function () {
  50. Object.assign(this, this.env.token);
  51. });
  52. shouldBehaveLikeVesting();
  53. });
  54. });
  55. });