ERC6909TokenSupply.test.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. const { ethers } = require('hardhat');
  2. const { expect } = require('chai');
  3. const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
  4. const { shouldBehaveLikeERC6909 } = require('../ERC6909.behavior');
  5. async function fixture() {
  6. const [holder, operator, recipient, other] = await ethers.getSigners();
  7. const token = await ethers.deployContract('$ERC6909TokenSupply');
  8. return { token, holder, operator, recipient, other };
  9. }
  10. describe('ERC6909TokenSupply', function () {
  11. beforeEach(async function () {
  12. Object.assign(this, await loadFixture(fixture));
  13. });
  14. shouldBehaveLikeERC6909();
  15. describe('totalSupply', function () {
  16. it('is zero before any mint', async function () {
  17. await expect(this.token.totalSupply(1n)).to.eventually.be.equal(0n);
  18. });
  19. it('minting tokens increases the total supply', async function () {
  20. await this.token.$_mint(this.holder, 1n, 17n);
  21. await expect(this.token.totalSupply(1n)).to.eventually.be.equal(17n);
  22. });
  23. describe('with tokens minted', function () {
  24. const supply = 1000n;
  25. beforeEach(async function () {
  26. await this.token.$_mint(this.holder, 1n, supply);
  27. });
  28. it('burning tokens decreases the total supply', async function () {
  29. await this.token.$_burn(this.holder, 1n, 17n);
  30. await expect(this.token.totalSupply(1n)).to.eventually.be.equal(supply - 17n);
  31. });
  32. it('supply unaffected by transfers', async function () {
  33. await this.token.$_transfer(this.holder, this.recipient, 1n, 42n);
  34. await expect(this.token.totalSupply(1n)).to.eventually.be.equal(supply);
  35. });
  36. it('supply unaffected by no-op', async function () {
  37. await this.token.$_update(ethers.ZeroAddress, ethers.ZeroAddress, 1n, 42n);
  38. await expect(this.token.totalSupply(1n)).to.eventually.be.equal(supply);
  39. });
  40. });
  41. });
  42. });