ERC1155Supply.test.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. const { ethers } = require('hardhat');
  2. const { expect } = require('chai');
  3. const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
  4. async function fixture() {
  5. const [holder] = await ethers.getSigners();
  6. const token = await ethers.deployContract('$ERC1155Supply', ['https://token-cdn-domain/{id}.json']);
  7. return { token, holder };
  8. }
  9. describe('ERC1155Supply', function () {
  10. const firstTokenId = 37n;
  11. const firstTokenValue = 42n;
  12. const secondTokenId = 19842n;
  13. const secondTokenValue = 23n;
  14. beforeEach(async function () {
  15. Object.assign(this, await loadFixture(fixture));
  16. });
  17. describe('before mint', function () {
  18. it('exist', async function () {
  19. expect(await this.token.exists(firstTokenId)).to.be.false;
  20. });
  21. it('totalSupply', async function () {
  22. expect(await this.token.totalSupply(ethers.Typed.uint256(firstTokenId))).to.equal(0n);
  23. expect(await this.token.totalSupply()).to.equal(0n);
  24. });
  25. });
  26. describe('after mint', function () {
  27. describe('single', function () {
  28. beforeEach(async function () {
  29. await this.token.$_mint(this.holder, firstTokenId, firstTokenValue, '0x');
  30. });
  31. it('exist', async function () {
  32. expect(await this.token.exists(firstTokenId)).to.be.true;
  33. });
  34. it('totalSupply', async function () {
  35. expect(await this.token.totalSupply(ethers.Typed.uint256(firstTokenId))).to.equal(firstTokenValue);
  36. expect(await this.token.totalSupply()).to.equal(firstTokenValue);
  37. });
  38. });
  39. describe('batch', function () {
  40. beforeEach(async function () {
  41. await this.token.$_mintBatch(
  42. this.holder,
  43. [firstTokenId, secondTokenId],
  44. [firstTokenValue, secondTokenValue],
  45. '0x',
  46. );
  47. });
  48. it('exist', async function () {
  49. expect(await this.token.exists(firstTokenId)).to.be.true;
  50. expect(await this.token.exists(secondTokenId)).to.be.true;
  51. });
  52. it('totalSupply', async function () {
  53. expect(await this.token.totalSupply(ethers.Typed.uint256(firstTokenId))).to.equal(firstTokenValue);
  54. expect(await this.token.totalSupply(ethers.Typed.uint256(secondTokenId))).to.equal(secondTokenValue);
  55. expect(await this.token.totalSupply()).to.equal(firstTokenValue + secondTokenValue);
  56. });
  57. });
  58. });
  59. describe('after burn', function () {
  60. describe('single', function () {
  61. beforeEach(async function () {
  62. await this.token.$_mint(this.holder, firstTokenId, firstTokenValue, '0x');
  63. await this.token.$_burn(this.holder, firstTokenId, firstTokenValue);
  64. });
  65. it('exist', async function () {
  66. expect(await this.token.exists(firstTokenId)).to.be.false;
  67. });
  68. it('totalSupply', async function () {
  69. expect(await this.token.totalSupply(ethers.Typed.uint256(firstTokenId))).to.equal(0n);
  70. expect(await this.token.totalSupply()).to.equal(0n);
  71. });
  72. });
  73. describe('batch', function () {
  74. beforeEach(async function () {
  75. await this.token.$_mintBatch(
  76. this.holder,
  77. [firstTokenId, secondTokenId],
  78. [firstTokenValue, secondTokenValue],
  79. '0x',
  80. );
  81. await this.token.$_burnBatch(this.holder, [firstTokenId, secondTokenId], [firstTokenValue, secondTokenValue]);
  82. });
  83. it('exist', async function () {
  84. expect(await this.token.exists(firstTokenId)).to.be.false;
  85. expect(await this.token.exists(secondTokenId)).to.be.false;
  86. });
  87. it('totalSupply', async function () {
  88. expect(await this.token.totalSupply(ethers.Typed.uint256(firstTokenId))).to.equal(0n);
  89. expect(await this.token.totalSupply(ethers.Typed.uint256(secondTokenId))).to.equal(0n);
  90. expect(await this.token.totalSupply()).to.equal(0n);
  91. });
  92. });
  93. });
  94. describe('other', function () {
  95. it('supply unaffected by no-op', async function () {
  96. await this.token.$_update(ethers.ZeroAddress, ethers.ZeroAddress, [firstTokenId], [firstTokenValue]);
  97. expect(await this.token.totalSupply(ethers.Typed.uint256(firstTokenId))).to.equal(0n);
  98. expect(await this.token.totalSupply()).to.equal(0n);
  99. });
  100. });
  101. });