forked from OpenZeppelin/openzeppelin-contracts
/
ERC1155URIStorage.js
64 lines (45 loc) · 2.15 KB
/
ERC1155URIStorage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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 uri = '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(uri);
await this.token.mint(holder, tokenId, amount, '0x');
});
it('can request the token uri, returning the base uri if no token uri was set', async function () {
const receivedTokenUri = await this.token.tokenURI(tokenId);
expect(receivedTokenUri).to.be.equal(uri);
});
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.setTokenURI(tokenId, tokenUri);
const receivedTokenUri = await this.token.tokenURI(tokenId);
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 () {
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.tokenURI(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.setTokenURI(tokenId, tokenUri);
const receivedTokenUri = await this.token.tokenURI(tokenId);
expect(receivedTokenUri).to.be.equal(tokenUri);
expectEvent(receipt, 'URI', { value: tokenUri, id: tokenId });
});
});
});