ERC1155Supply.test.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 firstTokenValue = new BN('42');
  10. const secondTokenId = new BN('19842');
  11. const secondTokenValue = 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, firstTokenValue, '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(firstTokenValue);
  34. expect(await this.token.methods['totalSupply()']()).to.be.bignumber.equal(firstTokenValue);
  35. });
  36. });
  37. context('batch', function () {
  38. beforeEach(async function () {
  39. await this.token.$_mintBatch(holder, [firstTokenId, secondTokenId], [firstTokenValue, secondTokenValue], '0x');
  40. });
  41. it('exist', async function () {
  42. expect(await this.token.exists(firstTokenId)).to.be.equal(true);
  43. expect(await this.token.exists(secondTokenId)).to.be.equal(true);
  44. });
  45. it('totalSupply', async function () {
  46. expect(await this.token.methods['totalSupply(uint256)'](firstTokenId)).to.be.bignumber.equal(firstTokenValue);
  47. expect(await this.token.methods['totalSupply(uint256)'](secondTokenId)).to.be.bignumber.equal(secondTokenValue);
  48. expect(await this.token.methods['totalSupply()']()).to.be.bignumber.equal(
  49. firstTokenValue.add(secondTokenValue),
  50. );
  51. });
  52. });
  53. });
  54. context('after burn', function () {
  55. context('single', function () {
  56. beforeEach(async function () {
  57. await this.token.$_mint(holder, firstTokenId, firstTokenValue, '0x');
  58. await this.token.$_burn(holder, firstTokenId, firstTokenValue);
  59. });
  60. it('exist', async function () {
  61. expect(await this.token.exists(firstTokenId)).to.be.equal(false);
  62. });
  63. it('totalSupply', async function () {
  64. expect(await this.token.methods['totalSupply(uint256)'](firstTokenId)).to.be.bignumber.equal('0');
  65. expect(await this.token.methods['totalSupply()']()).to.be.bignumber.equal('0');
  66. });
  67. });
  68. context('batch', function () {
  69. beforeEach(async function () {
  70. await this.token.$_mintBatch(holder, [firstTokenId, secondTokenId], [firstTokenValue, secondTokenValue], '0x');
  71. await this.token.$_burnBatch(holder, [firstTokenId, secondTokenId], [firstTokenValue, secondTokenValue]);
  72. });
  73. it('exist', async function () {
  74. expect(await this.token.exists(firstTokenId)).to.be.equal(false);
  75. expect(await this.token.exists(secondTokenId)).to.be.equal(false);
  76. });
  77. it('totalSupply', async function () {
  78. expect(await this.token.methods['totalSupply(uint256)'](firstTokenId)).to.be.bignumber.equal('0');
  79. expect(await this.token.methods['totalSupply(uint256)'](secondTokenId)).to.be.bignumber.equal('0');
  80. expect(await this.token.methods['totalSupply()']()).to.be.bignumber.equal('0');
  81. });
  82. });
  83. });
  84. context('other', function () {
  85. it('supply unaffected by no-op', async function () {
  86. this.token.safeTransferFrom(ZERO_ADDRESS, ZERO_ADDRESS, firstTokenId, firstTokenValue, '0x', {
  87. from: ZERO_ADDRESS,
  88. });
  89. expect(await this.token.methods['totalSupply(uint256)'](firstTokenId)).to.be.bignumber.equal('0');
  90. expect(await this.token.methods['totalSupply()']()).to.be.bignumber.equal('0');
  91. });
  92. });
  93. });