-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}` | ||
); | ||
}); | ||
}); |