Skip to content

Commit

Permalink
update ERC-165 support for the abstract StoryContract implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
mpeyfuss committed Nov 20, 2023
1 parent 7998546 commit 5ff5466
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 39 deletions.
5 changes: 3 additions & 2 deletions src/StoryContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ abstract contract StoryContract is IStory, ERC165 {
//////////////////////////////////////////////////////////////////////////*/

/// @inheritdoc ERC165
function supportsInterface(bytes4 interfaceId) public view virtual override (ERC165) returns (bool) {
return interfaceId == type(IStory).interfaceId || ERC165.supportsInterface(interfaceId);
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165) returns (bool) {
return interfaceId == type(IStory).interfaceId || interfaceId == 0x0d23ecb9 // support interface id for previous IStory interface, since this technically implements it
|| ERC165.supportsInterface(interfaceId);
}
}
9 changes: 4 additions & 5 deletions src/upgradeable/StoryContractUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ pragma solidity ^0.8.17;

import {Initializable} from "openzeppelin-upgradeable/proxy/utils/Initializable.sol";
import {ERC165Upgradeable} from "openzeppelin-upgradeable/utils/introspection/ERC165Upgradeable.sol";
import {
IStory, StoryNotEnabled, TokenDoesNotExist, NotTokenOwner, NotCreator, NotStoryAdmin
} from "../IStory.sol";
import {IStory, StoryNotEnabled, TokenDoesNotExist, NotTokenOwner, NotCreator, NotStoryAdmin} from "../IStory.sol";

/*//////////////////////////////////////////////////////////////////////////
Story Contract
Expand Down Expand Up @@ -117,8 +115,9 @@ abstract contract StoryContractUpgradeable is Initializable, IStory, ERC165Upgra
//////////////////////////////////////////////////////////////////////////*/

/// @inheritdoc ERC165Upgradeable
function supportsInterface(bytes4 interfaceId) public view virtual override (ERC165Upgradeable) returns (bool) {
return interfaceId == type(IStory).interfaceId || ERC165Upgradeable.supportsInterface(interfaceId);
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165Upgradeable) returns (bool) {
return interfaceId == type(IStory).interfaceId || interfaceId == 0x0d23ecb9 // support interface id for previous IStory interface, since this technically implements it
|| ERC165Upgradeable.supportsInterface(interfaceId);
}

/*//////////////////////////////////////////////////////////////////////////
Expand Down
23 changes: 6 additions & 17 deletions test/mocks/Example721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,37 @@ contract Example721 is ERC721, StoryContract, Ownable {
}
}

function _isStoryAdmin(address potentialAdmin) internal view override (StoryContract) returns (bool) {
function _isStoryAdmin(address potentialAdmin) internal view override(StoryContract) returns (bool) {
return owner() == potentialAdmin;
}

function _tokenExists(uint256 tokenId) internal view override (StoryContract) returns (bool) {
function _tokenExists(uint256 tokenId) internal view override(StoryContract) returns (bool) {
return _exists(tokenId);
}

function _isTokenOwner(address potentialOwner, uint256 tokenId)
internal
view
override (StoryContract)
override(StoryContract)
returns (bool)
{
return ownerOf(tokenId) == potentialOwner;
}

function _isCreator(address potentialCreator)
internal
view
override (StoryContract)
returns (bool)
{
function _isCreator(address potentialCreator) internal view override(StoryContract) returns (bool) {
return owner() == potentialCreator;
}

function _isCreator(address potentialCreator, uint256 /* tokenId */ )
internal
view
override (StoryContract)
override(StoryContract)
returns (bool)
{
return owner() == potentialCreator;
}

function supportsInterface(bytes4 interfaceId)
public
view
virtual
override (ERC721, StoryContract)
returns (bool)
{
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, StoryContract) returns (bool) {
return ERC721.supportsInterface(interfaceId) || StoryContract.supportsInterface(interfaceId);
}
}
17 changes: 6 additions & 11 deletions test/mocks/Example721Upgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,31 @@ contract Example721Upgradeable is ERC721Upgradeable, OwnableUpgradeable, StoryCo
}
}

function _isStoryAdmin(address potentialAdmin) internal view override (StoryContractUpgradeable) returns (bool) {
function _isStoryAdmin(address potentialAdmin) internal view override(StoryContractUpgradeable) returns (bool) {
return owner() == potentialAdmin;
}

function _tokenExists(uint256 tokenId) internal view override (StoryContractUpgradeable) returns (bool) {
function _tokenExists(uint256 tokenId) internal view override(StoryContractUpgradeable) returns (bool) {
return _exists(tokenId);
}

function _isTokenOwner(address potentialOwner, uint256 tokenId)
internal
view
override (StoryContractUpgradeable)
override(StoryContractUpgradeable)
returns (bool)
{
return ownerOf(tokenId) == potentialOwner;
}

function _isCreator(address potentialCreator)
internal
view
override (StoryContractUpgradeable)
returns (bool)
{
function _isCreator(address potentialCreator) internal view override(StoryContractUpgradeable) returns (bool) {
return owner() == potentialCreator;
}

function _isCreator(address potentialCreator, uint256 /* tokenId */ )
internal
view
override (StoryContractUpgradeable)
override(StoryContractUpgradeable)
returns (bool)
{
return owner() == potentialCreator;
Expand All @@ -60,7 +55,7 @@ contract Example721Upgradeable is ERC721Upgradeable, OwnableUpgradeable, StoryCo
public
view
virtual
override (ERC721Upgradeable, StoryContractUpgradeable)
override(ERC721Upgradeable, StoryContractUpgradeable)
returns (bool)
{
return
Expand Down
6 changes: 4 additions & 2 deletions test/testStoryContract.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,17 @@ contract StoryContractTest is Test {

function testERC165() public {
assertTrue(contractWithStory.supportsInterface(type(IStory).interfaceId));
assertTrue(contractWithStory.supportsInterface(0x0d23ecb9)); // previous IStory interfaceId
assertTrue(contractNoStory.supportsInterface(type(IStory).interfaceId));
assertTrue(contractNoStory.supportsInterface(0x0d23ecb9)); // previous IStory interfaceId
}

///////////////////// STORY ENABLED TESTS /////////////////////

function testAddCollectionStory() public {
vm.expectEmit(true, false, false, true, address(contractWithStory));
emit CollectionStory(address(this), "XCOPY", "I AM XCOPY");
contractWithStory.addCollectionStory("XCOPY", "I AM XCOPY");
emit CollectionStory(address(this), "XCOPY", "I AM XCOPY");
contractWithStory.addCollectionStory("XCOPY", "I AM XCOPY");
}

function testExpectRevertAddCollectionStory() public {
Expand Down
6 changes: 4 additions & 2 deletions test/testStoryContractUpgradeable.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,17 @@ contract StoryContractUpgradeableTest is Test {

function testERC165() public {
assertTrue(contractWithStory.supportsInterface(type(IStory).interfaceId));
assertTrue(contractWithStory.supportsInterface(0x0d23ecb9)); // previous IStory interfaceId
assertTrue(contractNoStory.supportsInterface(type(IStory).interfaceId));
assertTrue(contractNoStory.supportsInterface(0x0d23ecb9)); // previous IStory interfaceId
}

///////////////////// STORY ENABLED TESTS /////////////////////

function testAddCollectionStory() public {
vm.expectEmit(true, false, false, true, address(contractWithStory));
emit CollectionStory(address(this), "XCOPY", "I AM XCOPY");
contractWithStory.addCollectionStory("XCOPY", "I AM XCOPY");
emit CollectionStory(address(this), "XCOPY", "I AM XCOPY");
contractWithStory.addCollectionStory("XCOPY", "I AM XCOPY");
}

function testExpectRevertAddCollectionStory() public {
Expand Down

0 comments on commit 5ff5466

Please sign in to comment.