Add a simple catch-all implementation of the metadata URI interface (#2029)

* Initial ERC1155 implementation with some tests (#1803)

* Initial ERC1155 implementation with some tests

* Remove mocked isERC1155TokenReceiver

* Revert reason edit nit

* Remove parameters associated with isERC1155TokenReceiver call

* Add tests for approvals and single transfers

* Add tests for transferring to contracts

* Add tests for batch transfers

* Make expectEvent.inTransaction tests async

* Renamed "owner" to "account" and "holder"

* Document unspecified balanceOfBatch reversion on zero behavior

* Ensure accounts can't set their own operator status

* Specify descriptive messages for underflow errors

* Bring SafeMath.add calls in line with OZ style

* Explicitly prevent _burn on the zero account

* Implement batch minting/burning

* Refactored operator approval check into isApprovedForAll calls

* Renamed ERC1155TokenReceiver to ERC1155Receiver

* Added ERC1155Holder

* Fix lint issues

* Migrate tests to @openzeppelin/test-environment

* port ERC1155 to Solidity 0.6

* make ERC1155 constructor more similar to ERC721 one

* also migrate mock contracts to Solidity 0.6

* mark all non-view functions as virtual

* add simple catch-all implementation for the metadata URI interface

* include an internal function to set the URI so users can implement functionality to switch URIs

* add tests for ERC1155 metadata URI

* fix nits, mostly pointed out by linter

* convert ERC1155 metadata URI work to Solidity 0.6

* mark all non-view functions as virtual

* Port ERC 1155 branch to Solidity 0.6 (and current master) (#2130)

* port ERC1155 to Solidity 0.6

* make ERC1155 constructor more similar to ERC721 one

* also migrate mock contracts to Solidity 0.6

* mark all non-view functions as virtual

* Update contracts/token/ERC1155/IERC1155MetadataURI.sol

Starting on Solidity v0.6.2, interfaces can now inherit. \o/

Co-authored-by: Nicolás Venturo <nicolas.venturo@gmail.com>

* Fix compile errors

* Remove URI event

* Merge MetadataCatchAll into ERC1155

* Improve documentation.

* Simplify tests

* Move tests into ERC1155 tests

* Update documentation

* Bump minimum compiler version for inteface inheritance

* Fix holder tests

* Improve setUri docs

* Fix docs generation

Co-authored-by: Alan Lu <alanlu1023@gmail.com>
Co-authored-by: Nicolás Venturo <nicolas.venturo@gmail.com>
Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
This commit is contained in:
Robert Kaiser
2020-06-03 16:56:58 +02:00
committed by GitHub
parent ccfd370b89
commit a81e948fc9
8 changed files with 143 additions and 25 deletions

View File

@ -11,8 +11,10 @@ const ERC1155Mock = contract.fromArtifact('ERC1155Mock');
describe('ERC1155', function () {
const [creator, tokenHolder, tokenBatchHolder, ...otherAccounts] = accounts;
const initialURI = 'https://token-cdn-domain/{id}.json';
beforeEach(async function () {
this.token = await ERC1155Mock.new({ from: creator });
this.token = await ERC1155Mock.new(initialURI, { from: creator });
});
shouldBehaveLikeERC1155(otherAccounts);
@ -216,4 +218,35 @@ describe('ERC1155', function () {
});
});
});
describe('ERC1155MetadataURI', function () {
const firstTokenID = new BN('42');
const secondTokenID = new BN('1337');
it('emits no URI event in constructor', async function () {
await expectEvent.notEmitted.inConstruction(this.token, 'URI');
});
it('sets the initial URI for all token types', async function () {
expect(await this.token.uri(firstTokenID)).to.be.equal(initialURI);
expect(await this.token.uri(secondTokenID)).to.be.equal(initialURI);
});
describe('_setURI', function () {
const newURI = 'https://token-cdn-domain/{locale}/{id}.json';
it('emits no URI event', async function () {
const receipt = await this.token.setURI(newURI);
expectEvent.notEmitted(receipt, 'URI');
});
it('sets the new URI for all token types', async function () {
await this.token.setURI(newURI);
expect(await this.token.uri(firstTokenID)).to.be.equal(newURI);
expect(await this.token.uri(secondTokenID)).to.be.equal(newURI);
});
});
});
});

View File

@ -10,7 +10,9 @@ describe('ERC1155Holder', function () {
const [creator] = accounts;
it('receives ERC1155 tokens', async function () {
const multiToken = await ERC1155Mock.new({ from: creator });
const uri = 'https://token-cdn-domain/{id}.json';
const multiToken = await ERC1155Mock.new(uri, { from: creator });
const multiTokenIds = [new BN(1), new BN(2), new BN(3)];
const multiTokenAmounts = [new BN(1000), new BN(2000), new BN(3000)];
await multiToken.mintBatch(creator, multiTokenIds, multiTokenAmounts, '0x', { from: creator });