ERC1155URIStorage.test.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. const { ethers } = require('hardhat');
  2. const { expect } = require('chai');
  3. const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
  4. const erc1155Uri = 'https://token.com/nfts/';
  5. const baseUri = 'https://token.com/';
  6. const tokenId = 1n;
  7. const value = 3000n;
  8. describe('ERC1155URIStorage', function () {
  9. describe('with base uri set', function () {
  10. async function fixture() {
  11. const [holder] = await ethers.getSigners();
  12. const token = await ethers.deployContract('$ERC1155URIStorage', [erc1155Uri]);
  13. await token.$_setBaseURI(baseUri);
  14. await token.$_mint(holder, tokenId, value, '0x');
  15. return { token, holder };
  16. }
  17. beforeEach(async function () {
  18. Object.assign(this, await loadFixture(fixture));
  19. });
  20. it('can request the token uri, returning the erc1155 uri if no token uri was set', async function () {
  21. expect(await this.token.uri(tokenId)).to.equal(erc1155Uri);
  22. });
  23. it('can request the token uri, returning the concatenated uri if a token uri was set', async function () {
  24. const tokenUri = '1234/';
  25. const expectedUri = `${baseUri}${tokenUri}`;
  26. await expect(this.token.$_setURI(ethers.Typed.uint256(tokenId), tokenUri))
  27. .to.emit(this.token, 'URI')
  28. .withArgs(expectedUri, tokenId);
  29. expect(await this.token.uri(tokenId)).to.equal(expectedUri);
  30. });
  31. });
  32. describe('with base uri set to the empty string', function () {
  33. async function fixture() {
  34. const [holder] = await ethers.getSigners();
  35. const token = await ethers.deployContract('$ERC1155URIStorage', ['']);
  36. await token.$_mint(holder, tokenId, value, '0x');
  37. return { token, holder };
  38. }
  39. beforeEach(async function () {
  40. Object.assign(this, await loadFixture(fixture));
  41. });
  42. it('can request the token uri, returning an empty string if no token uri was set', async function () {
  43. expect(await this.token.uri(tokenId)).to.equal('');
  44. });
  45. it('can request the token uri, returning the token uri if a token uri was set', async function () {
  46. const tokenUri = 'ipfs://1234/';
  47. await expect(this.token.$_setURI(ethers.Typed.uint256(tokenId), tokenUri))
  48. .to.emit(this.token, 'URI')
  49. .withArgs(tokenUri, tokenId);
  50. expect(await this.token.uri(tokenId)).to.equal(tokenUri);
  51. });
  52. });
  53. });