feat: add baseTokenURI to ERC721Metadata (#1970)
* feat: add baseTokenURI * fix: tests * chore: dev notation * chore: changelog * chore: typo * Remove extra getters, return empty URI by default * Update docs * Rename baseTokenURI to baseURI * Roll back visibility change of tokenURI * Update changelog entry * Version setBaseURI docs * Improve internal names and comments * Fix compilation errors * Add an external getter for baseURI
This commit is contained in:
committed by
Francisco Giordano
parent
714f13df7e
commit
49042f2b1a
@ -72,8 +72,6 @@ contract('ERC721Full', function ([
|
||||
});
|
||||
|
||||
describe('metadata', function () {
|
||||
const sampleUri = 'mock://mytoken';
|
||||
|
||||
it('has a name', async function () {
|
||||
expect(await this.token.name()).to.be.equal(name);
|
||||
});
|
||||
@ -82,31 +80,68 @@ contract('ERC721Full', function ([
|
||||
expect(await this.token.symbol()).to.be.equal(symbol);
|
||||
});
|
||||
|
||||
it('sets and returns metadata for a token id', async function () {
|
||||
await this.token.setTokenURI(firstTokenId, sampleUri);
|
||||
expect(await this.token.tokenURI(firstTokenId)).to.be.equal(sampleUri);
|
||||
});
|
||||
describe('token URI', function () {
|
||||
const baseURI = 'https://api.com/v1/';
|
||||
const sampleUri = 'mock://mytoken';
|
||||
|
||||
it('reverts when setting metadata for non existent token id', async function () {
|
||||
await expectRevert(
|
||||
this.token.setTokenURI(nonExistentTokenId, sampleUri), 'ERC721Metadata: URI set of nonexistent token'
|
||||
);
|
||||
});
|
||||
it('it is empty by default', async function () {
|
||||
expect(await this.token.tokenURI(firstTokenId)).to.be.equal('');
|
||||
});
|
||||
|
||||
it('can burn token with metadata', async function () {
|
||||
await this.token.setTokenURI(firstTokenId, sampleUri);
|
||||
await this.token.burn(firstTokenId, { from: owner });
|
||||
expect(await this.token.exists(firstTokenId)).to.equal(false);
|
||||
});
|
||||
it('reverts when queried for non existent token id', async function () {
|
||||
await expectRevert(
|
||||
this.token.tokenURI(nonExistentTokenId), 'ERC721Metadata: URI query for nonexistent token'
|
||||
);
|
||||
});
|
||||
|
||||
it('returns empty metadata for token', async function () {
|
||||
expect(await this.token.tokenURI(firstTokenId)).to.be.equal('');
|
||||
});
|
||||
it('can be set for a token id', async function () {
|
||||
await this.token.setTokenURI(firstTokenId, sampleUri);
|
||||
expect(await this.token.tokenURI(firstTokenId)).to.be.equal(sampleUri);
|
||||
});
|
||||
|
||||
it('reverts when querying metadata for non existent token id', async function () {
|
||||
await expectRevert(
|
||||
this.token.tokenURI(nonExistentTokenId), 'ERC721Metadata: URI query for nonexistent token'
|
||||
);
|
||||
it('reverts when setting for non existent token id', async function () {
|
||||
await expectRevert(
|
||||
this.token.setTokenURI(nonExistentTokenId, sampleUri), 'ERC721Metadata: URI set of nonexistent token'
|
||||
);
|
||||
});
|
||||
|
||||
it('base URI can be set', async function () {
|
||||
await this.token.setBaseURI(baseURI);
|
||||
expect(await this.token.baseURI()).to.equal(baseURI);
|
||||
});
|
||||
|
||||
it('base URI is added as a prefix to the token URI', async function () {
|
||||
await this.token.setBaseURI(baseURI);
|
||||
await this.token.setTokenURI(firstTokenId, sampleUri);
|
||||
|
||||
expect(await this.token.tokenURI(firstTokenId)).to.be.equal(baseURI + sampleUri);
|
||||
});
|
||||
|
||||
it('token URI can be changed by changing the base URI', async function () {
|
||||
await this.token.setBaseURI(baseURI);
|
||||
await this.token.setTokenURI(firstTokenId, sampleUri);
|
||||
|
||||
const newBaseURI = 'https://api.com/v2/';
|
||||
await this.token.setBaseURI(newBaseURI);
|
||||
expect(await this.token.tokenURI(firstTokenId)).to.be.equal(newBaseURI + sampleUri);
|
||||
});
|
||||
|
||||
it('token URI is empty for tokens with no URI but with base URI', async function () {
|
||||
await this.token.setBaseURI(baseURI);
|
||||
|
||||
expect(await this.token.tokenURI(firstTokenId)).to.be.equal('');
|
||||
});
|
||||
|
||||
it('tokens with URI can be burnt ', async function () {
|
||||
await this.token.setTokenURI(firstTokenId, sampleUri);
|
||||
|
||||
await this.token.burn(firstTokenId, { from: owner });
|
||||
|
||||
expect(await this.token.exists(firstTokenId)).to.equal(false);
|
||||
await expectRevert(
|
||||
this.token.tokenURI(firstTokenId), 'ERC721Metadata: URI query for nonexistent token'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user