Files
openzeppelin-contracts/test/token/ERC1155/extensions/ERC1155URIStorage.test.js
S E R A Y A 02fcc75bb7 Add ERC1155URIStorage (#3210)
* Add ERC721URIStorage-like extension for ERC1155

* Add tests for ERC1155URIStorage extension

* add changelog entry for ERC721URIStorage

* Fix linting errors

* Emit URI event in ERC1155URIStorage

* Remove exists check and ERC1155Supply dependency

* Fix lint error

* Overwrite ERC1155 uri method

* Update ERC1155URIStorage specs

* Fix ERC1155URIStorageMock

* Rename _setTokenURI => _setURI in ERC1155URIStorage

* Add baseURI to ERC1155URIStorage

* Move super.uri call in ERC1155URIStorage

* Clearify ERC1155URIStorage description in change log

* reorder changelog & add documentation

* improve documentation

* fix typo

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
2022-03-29 09:15:43 +00:00

67 lines
2.2 KiB
JavaScript

const { BN, expectEvent } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const { artifacts } = require('hardhat');
const ERC1155URIStorageMock = artifacts.require('ERC1155URIStorageMock');
contract(['ERC1155URIStorage'], function (accounts) {
const [ holder ] = accounts;
const erc1155Uri = 'https://token.com/nfts/';
const baseUri = 'https://token.com/';
const tokenId = new BN('1');
const amount = new BN('3000');
describe('with base uri set', function () {
beforeEach(async function () {
this.token = await ERC1155URIStorageMock.new(erc1155Uri);
this.token.setBaseURI(baseUri);
await this.token.mint(holder, tokenId, amount, '0x');
});
it('can request the token uri, returning the erc1155 uri if no token uri was set', async function () {
const receivedTokenUri = await this.token.uri(tokenId);
expect(receivedTokenUri).to.be.equal(erc1155Uri);
});
it('can request the token uri, returning the concatenated uri if a token uri was set', async function () {
const tokenUri = '1234/';
const receipt = await this.token.setURI(tokenId, tokenUri);
const receivedTokenUri = await this.token.uri(tokenId);
const expectedUri = `${baseUri}${tokenUri}`;
expect(receivedTokenUri).to.be.equal(expectedUri);
expectEvent(receipt, 'URI', { value: expectedUri, id: tokenId });
});
});
describe('with base uri set to the empty string', function () {
beforeEach(async function () {
this.token = await ERC1155URIStorageMock.new('');
await this.token.mint(holder, tokenId, amount, '0x');
});
it('can request the token uri, returning an empty string if no token uri was set', async function () {
const receivedTokenUri = await this.token.uri(tokenId);
expect(receivedTokenUri).to.be.equal('');
});
it('can request the token uri, returning the token uri if a token uri was set', async function () {
const tokenUri = 'ipfs://1234/';
const receipt = await this.token.setURI(tokenId, tokenUri);
const receivedTokenUri = await this.token.uri(tokenId);
expect(receivedTokenUri).to.be.equal(tokenUri);
expectEvent(receipt, 'URI', { value: tokenUri, id: tokenId });
});
});
});