BasicERC20.ts 1.9 KB

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