VestingWallet.behavior.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. const { expect } = require('chai');
  2. const { bigint: time } = require('../helpers/time');
  3. function shouldBehaveLikeVesting() {
  4. it('check vesting schedule', async function () {
  5. for (const timestamp of this.schedule) {
  6. await time.forward.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.forward.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. }
  31. module.exports = {
  32. shouldBehaveLikeVesting,
  33. };