ERC1155URIStorage.test.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. const { BN, expectEvent } = require('@openzeppelin/test-helpers');
  2. const { expect } = require('chai');
  3. const { artifacts } = require('hardhat');
  4. const ERC1155URIStorage = artifacts.require('$ERC1155URIStorage');
  5. contract(['ERC1155URIStorage'], function (accounts) {
  6. const [holder] = accounts;
  7. const erc1155Uri = 'https://token.com/nfts/';
  8. const baseUri = 'https://token.com/';
  9. const tokenId = new BN('1');
  10. const amount = new BN('3000');
  11. describe('with base uri set', function () {
  12. beforeEach(async function () {
  13. this.token = await ERC1155URIStorage.new(erc1155Uri);
  14. await this.token.$_setBaseURI(baseUri);
  15. await this.token.$_mint(holder, tokenId, amount, '0x');
  16. });
  17. it('can request the token uri, returning the erc1155 uri if no token uri was set', async function () {
  18. const receivedTokenUri = await this.token.uri(tokenId);
  19. expect(receivedTokenUri).to.be.equal(erc1155Uri);
  20. });
  21. it('can request the token uri, returning the concatenated uri if a token uri was set', async function () {
  22. const tokenUri = '1234/';
  23. const receipt = await this.token.$_setURI(tokenId, tokenUri);
  24. const receivedTokenUri = await this.token.uri(tokenId);
  25. const expectedUri = `${baseUri}${tokenUri}`;
  26. expect(receivedTokenUri).to.be.equal(expectedUri);
  27. expectEvent(receipt, 'URI', { value: expectedUri, id: tokenId });
  28. });
  29. });
  30. describe('with base uri set to the empty string', function () {
  31. beforeEach(async function () {
  32. this.token = await ERC1155URIStorage.new('');
  33. await this.token.$_mint(holder, tokenId, amount, '0x');
  34. });
  35. it('can request the token uri, returning an empty string if no token uri was set', async function () {
  36. const receivedTokenUri = await this.token.uri(tokenId);
  37. expect(receivedTokenUri).to.be.equal('');
  38. });
  39. it('can request the token uri, returning the token uri if a token uri was set', async function () {
  40. const tokenUri = 'ipfs://1234/';
  41. const receipt = await this.token.$_setURI(tokenId, tokenUri);
  42. const receivedTokenUri = await this.token.uri(tokenId);
  43. expect(receivedTokenUri).to.be.equal(tokenUri);
  44. expectEvent(receipt, 'URI', { value: tokenUri, id: tokenId });
  45. });
  46. });
  47. });