Skip to content

Commit

Permalink
Emit URI event in ERC1155URIStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
takahser committed Feb 21, 2022
1 parent 7f6b569 commit 5fb51ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions contracts/token/ERC1155/extensions/ERC1155URIStorage.sol
Expand Up @@ -49,5 +49,6 @@ abstract contract ERC1155URIStorage is ERC1155Supply {
function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual {
require(exists(tokenId), "ERC1155URIStorage: URI set of nonexistent token");
_tokenURIs[tokenId] = _tokenURI;
emit URI(tokenURI(tokenId), tokenId);
}
}
15 changes: 9 additions & 6 deletions test/token/ERC1155/extensions/ERC1155URIStorage.js
@@ -1,4 +1,4 @@
const { BN } = require('@openzeppelin/test-helpers');
const { BN, expectEvent } = require('@openzeppelin/test-helpers');

const { expect } = require('chai');
const { artifacts } = require('hardhat');
Expand All @@ -13,7 +13,7 @@ contract(['ERC1155URIStorage'], function (accounts) {
const tokenId = new BN('1');
const amount = new BN('3000');

describe('with base uri set', function () {
describe.only('with base uri set', function () {
beforeEach(async function () {
this.token = await ERC1155URIStorageMock.new(uri);

Expand All @@ -28,15 +28,17 @@ contract(['ERC1155URIStorage'], function (accounts) {

it('can request the token uri, returning the concatenated uri if a token uri was set', async function () {
const tokenUri = '1234/';
await this.token.setTokenURI(tokenId, tokenUri);
const receipt = await this.token.setTokenURI(tokenId, tokenUri);

const receivedTokenUri = await this.token.tokenURI(tokenId);

expect(receivedTokenUri).to.be.equal(`${uri}${tokenUri}`);
const expectedUri = `${uri}${tokenUri}`;
expect(receivedTokenUri).to.be.equal(expectedUri);
expectEvent(receipt, 'URI', { value: expectedUri, id: tokenId });
});
});

describe('with base uri set to the empty string', function () {
describe.only('with base uri set to the empty string', function () {
beforeEach(async function () {
this.token = await ERC1155URIStorageMock.new('');

Expand All @@ -51,11 +53,12 @@ contract(['ERC1155URIStorage'], function (accounts) {

it('can request the token uri, returning the token uri if a token uri was set', async function () {
const tokenUri = 'ipfs://1234/';
await this.token.setTokenURI(tokenId, tokenUri);
const receipt = await this.token.setTokenURI(tokenId, tokenUri);

const receivedTokenUri = await this.token.tokenURI(tokenId);

expect(receivedTokenUri).to.be.equal(tokenUri);
expectEvent(receipt, 'URI', { value: tokenUri, id: tokenId });
});
});
});

0 comments on commit 5fb51ac

Please sign in to comment.