VestingWallet.behavior.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. const { expect } = require('chai');
  2. const time = require('../helpers/time');
  3. function shouldBehaveLikeVesting() {
  4. it('check vesting schedule', async function () {
  5. for (const timestamp of this.schedule) {
  6. await time.increaseTo.timestamp(timestamp);
  7. const vesting = this.vestingFn(timestamp);
  8. expect(await this.mock.vestedAmount(...this.args, timestamp)).to.be.equal(vesting);
  9. expect(await this.mock.releasable(...this.args)).to.be.equal(vesting);
  10. }
  11. });
  12. it('execute vesting schedule', async function () {
  13. let released = 0n;
  14. {
  15. const tx = await this.mock.release(...this.args);
  16. await expect(tx)
  17. .to.emit(this.mock, this.releasedEvent)
  18. .withArgs(...this.argsVerify, 0);
  19. await this.checkRelease(tx, 0n);
  20. }
  21. for (const timestamp of this.schedule) {
  22. await time.increaseTo.timestamp(timestamp, false);
  23. const vested = this.vestingFn(timestamp);
  24. const tx = await this.mock.release(...this.args);
  25. await expect(tx).to.emit(this.mock, this.releasedEvent);
  26. await this.checkRelease(tx, vested - released);
  27. released = vested;
  28. }
  29. });
  30. it('should revert on transaction failure', async function () {
  31. const { args, error } = await this.setupFailure();
  32. for (const timestamp of this.schedule) {
  33. await time.increaseTo.timestamp(timestamp);
  34. await expect(this.mock.release(...args)).to.be.revertedWithCustomError(...error);
  35. }
  36. });
  37. }
  38. module.exports = {
  39. shouldBehaveLikeVesting,
  40. };