Skip to content

Commit

Permalink
Finished testing mentor token (#9)
Browse files Browse the repository at this point in the history
* Finished Testing Mentor Token

* Added Deployment expect
  • Loading branch information
Jovells authored Nov 1, 2023
1 parent 499d5a5 commit 1c6aed4
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions blockchain/test/MentorToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,50 @@ describe("MentorToken", function () {
// and reset Hardhat Network to that snapshot in every test.
async function deployMentorTokenFixture() {
// Contracts are deployed using the first signer/account by default
const [owner, minter] = await ethers.getSigners();
const [owner, minter, user] = await ethers.getSigners();

const MentorToken = await ethers.getContractFactory("MentorToken");
const mentorToken = await MentorToken.deploy(owner.address, minter.address);

return { mentorToken, owner, minter };
return { mentorToken, owner, minter, user };
}

// Test Goes Below
describe("Deployment", function () {
it("deploys mentor token with all expected defaults", async function () {
const { mentorToken } = await loadFixture(deployMentorTokenFixture);

console.log("Total Supply: ", await mentorToken.totalSupply());
console.log("Name: ", await mentorToken.name());
console.log("Symbol: ", await mentorToken.symbol());
console.log("Decimals: ", await mentorToken.decimals());
const TotalSupply = await mentorToken.totalSupply();
const Name = await mentorToken.name();
const Symbol = await mentorToken.symbol();
const Decimals = await mentorToken.decimals();
expect([TotalSupply, Name, Symbol, Decimals]).to.deep.equal([0n, "Mentor Token", "MENT", 0n]);
})
});
describe("Minting", function () {
it("Should mint correctly", async function () {
const { mentorToken, minter, user } = await loadFixture(deployMentorTokenFixture);

const amountToMint = 1n;
const initialBalance = await mentorToken.balanceOf(user.address);
const initialTotalSupply = await mentorToken.totalSupply();

await mentorToken.connect(minter).mint(user.address, amountToMint);

const finalBalance = await mentorToken.balanceOf(user.address);
const finalTotalSupply = await mentorToken.totalSupply();

expect(finalBalance).to.equal(initialBalance + amountToMint);
expect(finalTotalSupply).to.equal(initialTotalSupply + amountToMint);
})

it("Should not mint if not minter", async function () {
const { mentorToken, user } = await loadFixture(deployMentorTokenFixture);
const amountToMint = 1n;
const initialBalance = await mentorToken.balanceOf(user.address);
const initialTotalSupply = await mentorToken.totalSupply();

await expect(mentorToken.connect(user).mint(user.address, 1)).to.be.revertedWithCustomError(mentorToken, 'AccessControlUnauthorizedAccount')
})
});
});

0 comments on commit 1c6aed4

Please sign in to comment.