diff --git a/src/ERC721ACH.sol b/src/ERC721ACH.sol index acb5e17..2dd899b 100644 --- a/src/ERC721ACH.sol +++ b/src/ERC721ACH.sol @@ -91,7 +91,6 @@ contract ERC721ACH is IERC721ACH, ERC721AC { } } -<<<<<<< HEAD /** * @notice Returns the owner of the `tokenId` token. * @dev The owner of a token is also its approver by default. @@ -101,35 +100,22 @@ contract ERC721ACH is IERC721ACH, ERC721AC { function ownerOf( uint256 tokenId ) public view virtual override returns (address) { - IOwnerOfHook hook = IOwnerOfHook(hooks[HookType.OwnerOf]); - - if (address(hook) != address(0) && hook.useOwnerOfHook(tokenId)) { - return hook.ownerOfHook(tokenId); - } - - return super.ownerOf(tokenId); -======= - function ownerOf(uint256 tokenId) public view virtual override returns (address) { address owner; bool runSuper; IOwnerOfHook ownerOfHook = IOwnerOfHook(hooks[HookType.OwnerOf]); - if ( - address(ownerOfHook) != address(0) && - ownerOfHook.useOwnerOfHook(tokenId) - ) { - (owner, runSuper) = ownerOfHook.ownerOfOverrideHook(tokenId); + if (address(ownerOfHook) != address(0)) { + (owner, runSuper) = ownerOfHook.ownerOfHook(tokenId); } else { runSuper = true; } - + if (runSuper) { owner = super.ownerOf(tokenId); } return owner; ->>>>>>> fba41f638a62e122470d308bdb8723c7d1a31574 } /** diff --git a/test/hooks/OwnerOfHook.t.sol b/test/hooks/OwnerOfHook.t.sol index 7dc3c04..d9bab0d 100644 --- a/test/hooks/OwnerOfHook.t.sol +++ b/test/hooks/OwnerOfHook.t.sol @@ -39,25 +39,39 @@ contract OwnerOfHookTest is DSTest, HookUtils { vm.assume(tokenId < 10); _assumeNotNull(_buyer); - test_setOwnerOfHook(); erc721Mock.mint(_buyer, tokenId); _assertOwner(address(erc721Mock), _buyer, tokenId); // override - hookMock.setHooksEnabled(true); + test_setOwnerOfHook(); _assertOwner(address(erc721Mock), address(0), tokenId); } + function test_ownerOfHook_revert(address _buyer, uint256 tokenId) public { + test_ownerOfHook(_buyer, tokenId); + // revert + hookMock.setRevertOwnerOfOverrideHook(true); + vm.expectRevert(OwnerOfHookMock.OwnerOfHook_Executed.selector); + erc721Mock.ownerOf(tokenId); + } + function test_turn_off_hook(address _buyer, uint256 tokenId) public { + // test normal override test_ownerOfHook(_buyer, tokenId); // turn off hook - hookMock.setHooksEnabled(false); + _turnOffOwnerOfHook(); _assertOwner(address(erc721Mock), _buyer, tokenId); - // TODO: put this into it's own test - hookMock.setRevertOwnerOfOverrideHook(true); - vm.expectRevert(OwnerOfHookMock.OwnerOfHook_Executed.selector); - erc721Mock.ownerOf(tokenId); + // test revert override + test_ownerOfHook_revert(_buyer, tokenId); + + // turn off hook + _turnOffOwnerOfHook(); + _assertOwner(address(erc721Mock), _buyer, tokenId); + } + + function _turnOffOwnerOfHook() internal { + _setHook(address(erc721Mock), OwnerOf, address(0)); } } diff --git a/test/utils/hooks/OwnerOfHookMock.sol b/test/utils/hooks/OwnerOfHookMock.sol index 08645d3..f25f758 100644 --- a/test/utils/hooks/OwnerOfHookMock.sol +++ b/test/utils/hooks/OwnerOfHookMock.sol @@ -36,6 +36,6 @@ contract OwnerOfHookMock is IOwnerOfHook { uint256 ) external view override returns (address, bool) { if (revertOwnerOfOverrideHook) revert OwnerOfHook_Executed(); - return (fixedOwner, true); // run super + return (fixedOwner, false); // run super } }