BasicERC1155.ts 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { expect } from "chai"
  2. import { deployments, ethers, getNamedAccounts } from "hardhat"
  3. describe("BasicERC1155", () => {
  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 baseURI = "ipfs://base-uri/"
  10. const contractURI = "ipfs://contract-uri"
  11. const owner = signers.deployer
  12. const contract = await ethers.deployContract(
  13. "BasicERC1155",
  14. [name, symbol, baseURI, contractURI, owner],
  15. await ethers.getSigner(signers.deployer)
  16. )
  17. return {
  18. contract,
  19. contractAddress: await contract.getAddress(),
  20. deployer: signers.deployer,
  21. accounts: await ethers.getSigners(),
  22. contractConstructor: {
  23. name,
  24. symbol,
  25. baseURI,
  26. contractURI,
  27. owner,
  28. },
  29. }
  30. })
  31. it("Should Return Valid Contract Configurations Passed In Constructor", async () => {
  32. const { contractConstructor, contract } = await setupFixture()
  33. expect(await contract.name()).to.equal(contractConstructor.name)
  34. expect(await contract.symbol()).to.equal(contractConstructor.symbol)
  35. expect(await contract.contractURI()).to.equal(contractConstructor.contractURI)
  36. expect(await contract.owner()).to.equal(contractConstructor.owner)
  37. })
  38. describe("Minting Functionality", () => {
  39. it("Should Increase Supply When Minting", async () => {
  40. const { contract, deployer } = await setupFixture()
  41. expect(await contract["totalSupply(uint256)"](1)).to.equal(0)
  42. expect(await contract["totalSupply(uint256)"](2)).to.equal(0)
  43. await contract.mintBatch(deployer, [1, 2], [2000, 4000])
  44. expect(await contract["totalSupply(uint256)"](1)).to.equal(2000)
  45. expect(await contract["totalSupply(uint256)"](2)).to.equal(4000)
  46. expect(await contract.balanceOf(deployer, 1)).to.equal(2000)
  47. expect(await contract.balanceOf(deployer, 2)).to.equal(4000)
  48. })
  49. it("Should Allow Minting Only to Contract Owner - mint", async () => {
  50. const { contract, accounts } = await setupFixture()
  51. await expect(contract.connect(accounts[1]).mint(accounts[1].address, 1, 1000))
  52. .to.be.revertedWithCustomError(contract, "OwnableUnauthorizedAccount")
  53. .withArgs(await accounts[1].getAddress())
  54. })
  55. it("Should Allow Minting Only to Contract Owner - mintBatch", async () => {
  56. const { contract, accounts } = await setupFixture()
  57. await expect(contract.connect(accounts[1]).mintBatch(accounts[1].address, [1], [1000]))
  58. .to.be.revertedWithCustomError(contract, "OwnableUnauthorizedAccount")
  59. .withArgs(await accounts[1].getAddress())
  60. })
  61. })
  62. describe("Contract And Token Metadata", () => {
  63. it("Should Return Correct Token URI", async () => {
  64. const { contract, contractConstructor } = await setupFixture()
  65. expect(await contract.uri(1)).to.equal(`${contractConstructor.baseURI}1.json`)
  66. })
  67. it("Should Return Correct Contract URI", async () => {
  68. const { contract, contractConstructor } = await setupFixture()
  69. expect(await contract.contractURI()).to.equal(contractConstructor.contractURI)
  70. })
  71. })
  72. })