Skip to content

Commit

Permalink
I fix failing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SweetmanTech committed Aug 6, 2023
1 parent 21e137a commit 69ef746
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
20 changes: 3 additions & 17 deletions src/ERC721ACH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}

/**
Expand Down
28 changes: 21 additions & 7 deletions test/hooks/OwnerOfHook.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
2 changes: 1 addition & 1 deletion test/utils/hooks/OwnerOfHookMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 69ef746

Please sign in to comment.