Skip to content

Commit

Permalink
simplify getTransferValidationFunction(), add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanio committed Apr 1, 2024
1 parent 652c21d commit 9328779
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 22 deletions.
8 changes: 3 additions & 5 deletions src-upgradeable/src/ERC721ContractMetadataUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
ILegacyCreatorToken
} from "./interfaces/ICreatorToken.sol";

import { ITransferValidator } from "./interfaces/ITransferValidator.sol";
import { ITransferValidator721 } from "./interfaces/ITransferValidator.sol";

import {
ERC721AUpgradeable
Expand Down Expand Up @@ -304,9 +304,7 @@ contract ERC721ContractMetadataUpgradeable is
pure
returns (bytes4 functionSignature, bool isViewFunction)
{
functionSignature = bytes4(
keccak256("validateTransfer(address,address,address,uint256)")
);
functionSignature = ITransferValidator721.validateTransfer.selector;
isViewFunction = false;
}

Expand All @@ -331,7 +329,7 @@ contract ERC721ContractMetadataUpgradeable is
if (from != address(0) && to != address(0)) {
// Call the transfer validator if one is set.
if (_transferValidator != address(0)) {
ITransferValidator(_transferValidator).validateTransfer(
ITransferValidator721(_transferValidator).validateTransfer(
msg.sender,
from,
to,
Expand Down
4 changes: 3 additions & 1 deletion src-upgradeable/src/interfaces/ITransferValidator.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

interface ITransferValidator {
interface ITransferValidator721 {
/// @notice Ensure that a transfer has been authorized for a specific tokenId
function validateTransfer(
address caller,
address from,
address to,
uint256 tokenId
) external view;
}

interface ITransferValidator1155 {
/// @notice Ensure that a transfer has been authorized for a specific amount of a specific tokenId, and reduce the transferable amount remaining
function validateTransfer(
address caller,
Expand Down
8 changes: 3 additions & 5 deletions src/ERC721ContractMetadata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
ILegacyCreatorToken
} from "./interfaces/ICreatorToken.sol";

import { ITransferValidator } from "./interfaces/ITransferValidator.sol";
import { ITransferValidator721 } from "./interfaces/ITransferValidator.sol";

import { TwoStepOwnable } from "utility-contracts/TwoStepOwnable.sol";

Expand Down Expand Up @@ -294,9 +294,7 @@ contract ERC721ContractMetadata is
pure
returns (bytes4 functionSignature, bool isViewFunction)
{
functionSignature = bytes4(
keccak256("validateTransfer(address,address,address,uint256)")
);
functionSignature = ITransferValidator721.validateTransfer.selector;
isViewFunction = false;
}

Expand All @@ -321,7 +319,7 @@ contract ERC721ContractMetadata is
if (from != address(0) && to != address(0)) {
// Call the transfer validator if one is set.
if (_transferValidator != address(0)) {
ITransferValidator(_transferValidator).validateTransfer(
ITransferValidator721(_transferValidator).validateTransfer(
msg.sender,
from,
to,
Expand Down
8 changes: 3 additions & 5 deletions src/clones/ERC721ContractMetadataCloneable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
ILegacyCreatorToken
} from "../interfaces/ICreatorToken.sol";

import { ITransferValidator } from "../interfaces/ITransferValidator.sol";
import { ITransferValidator721 } from "../interfaces/ITransferValidator.sol";

import { TwoStepOwnable } from "utility-contracts/TwoStepOwnable.sol";

Expand Down Expand Up @@ -289,9 +289,7 @@ contract ERC721ContractMetadataCloneable is
pure
returns (bytes4 functionSignature, bool isViewFunction)
{
functionSignature = bytes4(
keccak256("validateTransfer(address,address,address,uint256)")
);
functionSignature = ITransferValidator721.validateTransfer.selector;
isViewFunction = false;
}

Expand All @@ -316,7 +314,7 @@ contract ERC721ContractMetadataCloneable is
if (from != address(0) && to != address(0)) {
// Call the transfer validator if one is set.
if (_transferValidator != address(0)) {
ITransferValidator(_transferValidator).validateTransfer(
ITransferValidator721(_transferValidator).validateTransfer(
msg.sender,
from,
to,
Expand Down
9 changes: 5 additions & 4 deletions src/interfaces/ITransferValidator.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

interface ITransferValidator {
/// @notice Ensure that a transfer has been authorized for a specific tokenId.
interface ITransferValidator721 {
/// @notice Ensure that a transfer has been authorized for a specific tokenId
function validateTransfer(
address caller,
address from,
address to,
uint256 tokenId
) external view;
}

/// @notice Ensure that a transfer has been authorized for a specific amount of
// a specific tokenId, and reduce the transferable amount remaining.
interface ITransferValidator1155 {
/// @notice Ensure that a transfer has been authorized for a specific amount of a specific tokenId, and reduce the transferable amount remaining
function validateTransfer(
address caller,
address from,
Expand Down
4 changes: 2 additions & 2 deletions src/test/MockTransferValidator.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: Unlicense
pragma solidity 0.8.17;

import { ITransferValidator } from "../interfaces/ITransferValidator.sol";
import { ITransferValidator721, ITransferValidator1155 } from "../interfaces/ITransferValidator.sol";

contract MockTransferValidator is ITransferValidator {
contract MockTransferValidator is ITransferValidator721, ITransferValidator1155 {
bool internal _revertOnValidate;

constructor(bool revertOnValidate) {
Expand Down
14 changes: 14 additions & 0 deletions test/foundry/ERC721TransferValidator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { TestHelper } from "test/foundry/utils/TestHelper.sol";

import { ERC721SeaDrop } from "seadrop/ERC721SeaDrop.sol";

import {
ITransferValidator721
} from "seadrop/interfaces/ITransferValidator.sol";

import { MockTransferValidator } from "seadrop/test/MockTransferValidator.sol";

import { TwoStepOwnable } from "utility-contracts/TwoStepOwnable.sol";
Expand Down Expand Up @@ -79,6 +83,16 @@ contract ERC721TransferValidatorTest is TestHelper {
token_.safeTransferFrom(address(this), msg.sender, 2);
}

function testGetTransferValidationFunction() public {
(bytes4 functionSignature, bool isViewFunction) = token_
.getTransferValidationFunction();
assertEq(
functionSignature,
ITransferValidator721.validateTransfer.selector
);
assertEq(isViewFunction, false);
}

function onERC721Received(
address,
address,
Expand Down

0 comments on commit 9328779

Please sign in to comment.