BasicERC20.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { expect } from "chai"
  2. import { deployments, ethers, getNamedAccounts } from "hardhat"
  3. describe("BasicERC20", () => {
  4. const setupFixture = deployments.createFixture(async () => {
  5. await deployments.fixture()
  6. const signers = await getNamedAccounts()
  7. const name = "ProtoToken"
  8. const symbol = "PT"
  9. const owner = signers.deployer
  10. const contract = await ethers.deployContract(
  11. "BasicERC20",
  12. [name, symbol, owner],
  13. await ethers.getSigner(signers.deployer)
  14. )
  15. return {
  16. contract,
  17. contractAddress: await contract.getAddress(),
  18. deployer: signers.deployer,
  19. accounts: await ethers.getSigners(),
  20. contractConstructor: {
  21. name,
  22. symbol,
  23. owner,
  24. },
  25. }
  26. })
  27. it("Should Return Valid Contract Configurations Passed In Constructor", async () => {
  28. const { contractConstructor, contract } = await setupFixture()
  29. expect(await contract.name()).to.equal(contractConstructor.name)
  30. expect(await contract.symbol()).to.equal(contractConstructor.symbol)
  31. expect(await contract.owner()).to.equal(contractConstructor.owner)
  32. })
  33. describe("Minting Functionality", () => {
  34. it("Should Increase Total Supply and User Supply When Minting", async () => {
  35. const { contract, accounts } = await setupFixture()
  36. expect(await contract.totalSupply()).to.equal(0)
  37. await contract.mint(accounts[0].address, 1000)
  38. await contract.mint(accounts[1].address, 2000)
  39. expect(await contract.totalSupply()).to.equal(3000)
  40. expect(await contract.balanceOf(accounts[0].address)).to.equal(1000)
  41. expect(await contract.balanceOf(accounts[1].address)).to.equal(2000)
  42. })
  43. it("Should Allow Only Owner to Mint Tokens", async () => {
  44. const { contract, accounts } = await setupFixture()
  45. await expect(contract.connect(accounts[1]).mint(accounts[1].address, 1000))
  46. .to.be.revertedWithCustomError(contract, "OwnableUnauthorizedAccount")
  47. .withArgs(await accounts[1].getAddress())
  48. })
  49. })
  50. })