ERC1155Supply.test.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. const { BN, constants } = require('@openzeppelin/test-helpers');
  2. const { expect } = require('chai');
  3. const { ZERO_ADDRESS } = constants;
  4. const ERC1155Supply = artifacts.require('$ERC1155Supply');
  5. contract('ERC1155Supply', function (accounts) {
  6. const [holder] = accounts;
  7. const uri = 'https://token.com';
  8. const firstTokenId = new BN('37');
  9. const firstTokenAmount = new BN('42');
  10. const secondTokenId = new BN('19842');
  11. const secondTokenAmount = new BN('23');
  12. beforeEach(async function () {
  13. this.token = await ERC1155Supply.new(uri);
  14. });
  15. context('before mint', function () {
  16. it('exist', async function () {
  17. expect(await this.token.exists(firstTokenId)).to.be.equal(false);
  18. });
  19. it('totalSupply', async function () {
  20. expect(await this.token.methods['totalSupply(uint256)'](firstTokenId)).to.be.bignumber.equal('0');
  21. expect(await this.token.methods['totalSupply()']()).to.be.bignumber.equal('0');
  22. });
  23. });
  24. context('after mint', function () {
  25. context('single', function () {
  26. beforeEach(async function () {
  27. await this.token.$_mint(holder, firstTokenId, firstTokenAmount, '0x');
  28. });
  29. it('exist', async function () {
  30. expect(await this.token.exists(firstTokenId)).to.be.equal(true);
  31. });
  32. it('totalSupply', async function () {
  33. expect(await this.token.methods['totalSupply(uint256)'](firstTokenId)).to.be.bignumber.equal(firstTokenAmount);
  34. expect(await this.token.methods['totalSupply()']()).to.be.bignumber.equal(firstTokenAmount);
  35. });
  36. });
  37. context('batch', function () {
  38. beforeEach(async function () {
  39. await this.token.$_mintBatch(
  40. holder,
  41. [firstTokenId, secondTokenId],
  42. [firstTokenAmount, secondTokenAmount],
  43. '0x',
  44. );
  45. });
  46. it('exist', async function () {
  47. expect(await this.token.exists(firstTokenId)).to.be.equal(true);
  48. expect(await this.token.exists(secondTokenId)).to.be.equal(true);
  49. });
  50. it('totalSupply', async function () {
  51. expect(await this.token.methods['totalSupply(uint256)'](firstTokenId)).to.be.bignumber.equal(firstTokenAmount);
  52. expect(await this.token.methods['totalSupply(uint256)'](secondTokenId)).to.be.bignumber.equal(
  53. secondTokenAmount,
  54. );
  55. expect(await this.token.methods['totalSupply()']()).to.be.bignumber.equal(
  56. firstTokenAmount.add(secondTokenAmount),
  57. );
  58. });
  59. });
  60. });
  61. context('after burn', function () {
  62. context('single', function () {
  63. beforeEach(async function () {
  64. await this.token.$_mint(holder, firstTokenId, firstTokenAmount, '0x');
  65. await this.token.$_burn(holder, firstTokenId, firstTokenAmount);
  66. });
  67. it('exist', async function () {
  68. expect(await this.token.exists(firstTokenId)).to.be.equal(false);
  69. });
  70. it('totalSupply', async function () {
  71. expect(await this.token.methods['totalSupply(uint256)'](firstTokenId)).to.be.bignumber.equal('0');
  72. expect(await this.token.methods['totalSupply()']()).to.be.bignumber.equal('0');
  73. });
  74. });
  75. context('batch', function () {
  76. beforeEach(async function () {
  77. await this.token.$_mintBatch(
  78. holder,
  79. [firstTokenId, secondTokenId],
  80. [firstTokenAmount, secondTokenAmount],
  81. '0x',
  82. );
  83. await this.token.$_burnBatch(holder, [firstTokenId, secondTokenId], [firstTokenAmount, secondTokenAmount]);
  84. });
  85. it('exist', async function () {
  86. expect(await this.token.exists(firstTokenId)).to.be.equal(false);
  87. expect(await this.token.exists(secondTokenId)).to.be.equal(false);
  88. });
  89. it('totalSupply', async function () {
  90. expect(await this.token.methods['totalSupply(uint256)'](firstTokenId)).to.be.bignumber.equal('0');
  91. expect(await this.token.methods['totalSupply(uint256)'](secondTokenId)).to.be.bignumber.equal('0');
  92. expect(await this.token.methods['totalSupply()']()).to.be.bignumber.equal('0');
  93. });
  94. });
  95. });
  96. context('other', function () {
  97. it('supply unaffected by no-op', async function () {
  98. this.token.safeTransferFrom(ZERO_ADDRESS, ZERO_ADDRESS, firstTokenId, firstTokenAmount, '0x', {
  99. from: ZERO_ADDRESS,
  100. });
  101. expect(await this.token.methods['totalSupply(uint256)'](firstTokenId)).to.be.bignumber.equal('0');
  102. expect(await this.token.methods['totalSupply()']()).to.be.bignumber.equal('0');
  103. });
  104. });
  105. });