Skip to content

Commit

Permalink
Create TokenVesting.test.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Dec 2, 2024
1 parent b945cb2 commit 86314df
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("Token Vesting Contract", function () {
let TokenVesting, vesting, token, owner, beneficiary;

beforeEach(async function () {
[owner, beneficiary] = await ethers.getSigners();
const Token = await ethers.getContractFactory("ERC20Mock");
token = await Token.deploy("Vesting Token", "VTK", ethers.utils.parseEther("1000"));
TokenVesting = await ethers.getContractFactory("TokenVesting");
vesting = await TokenVesting.deploy(token.address, beneficiary.address, Math.floor(Date.now() / 1000) + 60);
await vesting.deployed();
});

it("should allow the owner to start vesting", async function () {
await token.connect(owner).transfer(vesting.address, ethers.utils.parseEther("100"));
await vesting.startVesting();
expect(await vesting.vestingStarted()).to.be.true;
});

it("should allow the beneficiary to claim tokens after the vesting period", async function () {
await token.connect(owner).transfer(vesting.address, ethers.utils.parseEther("100"));
await vesting.startVesting();
await ethers.provider.send("evm_increaseTime", [61]); // Increase time by 61 seconds
await ethers.provider.send("evm_mine"); // Mine a new block
await vesting.connect(beneficiary).claimTokens();
expect(await token.balanceOf(beneficiary.address)).to.equal(ethers.utils.parseEther("100"));
});
});

0 comments on commit 86314df

Please sign in to comment.