* 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 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 Co-authored-by: Alan Lu <alanlu1023@gmail.com> Co-authored-by: Nicolás Venturo <nicolas.venturo@gmail.com> Co-authored-by: Robert Kaiser <kairo@kairo.at>
85 lines
2.5 KiB
JavaScript
85 lines
2.5 KiB
JavaScript
const { makeInterfaceId } = require('@openzeppelin/test-helpers');
|
|
|
|
const { expect } = require('chai');
|
|
|
|
const INTERFACES = {
|
|
ERC165: [
|
|
'supportsInterface(bytes4)',
|
|
],
|
|
ERC721: [
|
|
'balanceOf(address)',
|
|
'ownerOf(uint256)',
|
|
'approve(address,uint256)',
|
|
'getApproved(uint256)',
|
|
'setApprovalForAll(address,bool)',
|
|
'isApprovedForAll(address,address)',
|
|
'transferFrom(address,address,uint256)',
|
|
'safeTransferFrom(address,address,uint256)',
|
|
'safeTransferFrom(address,address,uint256,bytes)',
|
|
],
|
|
ERC721Enumerable: [
|
|
'totalSupply()',
|
|
'tokenOfOwnerByIndex(address,uint256)',
|
|
'tokenByIndex(uint256)',
|
|
],
|
|
ERC721Metadata: [
|
|
'name()',
|
|
'symbol()',
|
|
'tokenURI(uint256)',
|
|
],
|
|
ERC1155: [
|
|
'balanceOf(address,uint256)',
|
|
'balanceOfBatch(address[],uint256[])',
|
|
'setApprovalForAll(address,bool)',
|
|
'isApprovedForAll(address,address)',
|
|
'safeTransferFrom(address,address,uint256,uint256,bytes)',
|
|
'safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)',
|
|
],
|
|
};
|
|
|
|
const INTERFACE_IDS = {};
|
|
const FN_SIGNATURES = {};
|
|
for (const k of Object.getOwnPropertyNames(INTERFACES)) {
|
|
INTERFACE_IDS[k] = makeInterfaceId.ERC165(INTERFACES[k]);
|
|
for (const fnName of INTERFACES[k]) {
|
|
// the interface id of a single function is equivalent to its function signature
|
|
FN_SIGNATURES[fnName] = makeInterfaceId.ERC165([fnName]);
|
|
}
|
|
}
|
|
|
|
function shouldSupportInterfaces (interfaces = []) {
|
|
describe('Contract interface', function () {
|
|
beforeEach(function () {
|
|
this.contractUnderTest = this.mock || this.token;
|
|
});
|
|
|
|
for (const k of interfaces) {
|
|
const interfaceId = INTERFACE_IDS[k];
|
|
describe(k, function () {
|
|
describe('ERC165\'s supportsInterface(bytes4)', function () {
|
|
it('should use less than 30k gas', async function () {
|
|
expect(await this.contractUnderTest.supportsInterface.estimateGas(interfaceId)).to.be.lte(30000);
|
|
});
|
|
|
|
it('should claim support', async function () {
|
|
expect(await this.contractUnderTest.supportsInterface(interfaceId)).to.equal(true);
|
|
});
|
|
});
|
|
|
|
for (const fnName of INTERFACES[k]) {
|
|
const fnSig = FN_SIGNATURES[fnName];
|
|
describe(fnName, function () {
|
|
it('should be implemented', function () {
|
|
expect(this.contractUnderTest.abi.filter(fn => fn.signature === fnSig).length).to.equal(1);
|
|
});
|
|
});
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
shouldSupportInterfaces,
|
|
};
|