Skip to content

Commit

Permalink
test: test for CODE mint role
Browse files Browse the repository at this point in the history
  • Loading branch information
swr1bm86 committed May 2, 2022
1 parent 627b69a commit 7cecb4b
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions packages/hardhat/test/CODE.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { expect } from './chai-setup';
import { ethers, deployments, getNamedAccounts } from 'hardhat';
import { CODE } from '../../next-app/src/typechain';

const TOKEN_DECIMALS = 18;

const setup = deployments.createFixture(async () => {
await deployments.fixture(['CODE']);

const CODE = <CODE>await ethers.getContract('CODE');

return {
CODE,
};
});

describe('CODE', function () {
it('Only mint role can mint new token', async function () {
const { CODE } = await setup();
const { treasury } = await getNamedAccounts();

const tc = await CODE.connect(await ethers.getSigner(treasury));
const mintRole = await CODE.MINTER_ROLE();
await expect(tc.mint(treasury, ethers.utils.parseUnits((100_000).toString(), TOKEN_DECIMALS))).to.be.revertedWith(
`AccessControl: account ${treasury.toLowerCase()} is missing role ${mintRole}`
);

const treasuryBalance = await CODE.balanceOf(treasury);
expect(treasuryBalance).to.equal(ethers.utils.parseUnits((6_500_000).toString(), TOKEN_DECIMALS));

await CODE.grantRole(mintRole, treasury);

await tc.mint(treasury, ethers.utils.parseUnits((100_000).toString(), TOKEN_DECIMALS));

const treasuryBalanceAfter = await CODE.balanceOf(treasury);
expect(treasuryBalanceAfter).to.equal(ethers.utils.parseUnits((6_600_000).toString(), TOKEN_DECIMALS));

await CODE.revokeRole(mintRole, treasury);

await expect(tc.mint(treasury, ethers.utils.parseUnits((100_000).toString(), TOKEN_DECIMALS))).to.be.revertedWith(
`AccessControl: account ${treasury.toLowerCase()} is missing role ${mintRole}`
);
});
});

0 comments on commit 7cecb4b

Please sign in to comment.