Skip to content

Commit

Permalink
feat: add tokenId to redeemInstructionsHashIsAllowed and update unit …
Browse files Browse the repository at this point in the history
…tests
  • Loading branch information
IsabellaSmallcombe committed Sep 20, 2023
1 parent 4cb56d4 commit 87c8d3f
Show file tree
Hide file tree
Showing 3 changed files with 1,551 additions and 1,540 deletions.
26 changes: 18 additions & 8 deletions src/minters/redeem/ZoraCreatorRedeemMinterStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ contract ZoraCreatorRedeemMinterStrategy is Enjoy, SaleStrategy, Initializable {
error MintTokenContractMustBeCreatorContract();
error SenderIsNotTokenOwner();

/// @notice keccak256(abi.encode(RedeemInstructions)) => redeem instructions are allowed
mapping(bytes32 => bool) public redeemInstructionsHashIsAllowed;
/// @notice tokenId, keccak256(abi.encode(RedeemInstructions)) => redeem instructions are allowed
mapping(uint256 => mapping(bytes32 => bool)) public redeemInstructionsHashIsAllowed;

/// @notice Zora creator contract
address public creatorContract;
Expand Down Expand Up @@ -210,27 +210,33 @@ contract ZoraCreatorRedeemMinterStrategy is Enjoy, SaleStrategy, Initializable {
}

/// @notice Set redeem instructions
/// @param tokenId The token id to set redeem instructions for
/// @param _redeemInstructions The redeem instructions object
function setRedeem(RedeemInstructions calldata _redeemInstructions) external onlyCreatorContract {
function setRedeem(uint256 tokenId, RedeemInstructions calldata _redeemInstructions) external onlyCreatorContract {
if (_redeemInstructions.mintToken.tokenId != tokenId) {
revert InvalidTokenIdsForTokenType();
}

validateRedeemInstructions(_redeemInstructions);

bytes32 hash = redeemInstructionsHash(_redeemInstructions);
if (redeemInstructionsHashIsAllowed[hash]) {
if (redeemInstructionsHashIsAllowed[tokenId][hash]) {
revert RedeemInstructionAlreadySet();
}
redeemInstructionsHashIsAllowed[hash] = true;
redeemInstructionsHashIsAllowed[tokenId][hash] = true;

emit RedeemSet(creatorContract, hash, _redeemInstructions);
}

/// @notice Clear redeem instructions
/// @param tokenId The token id to clear redeem instructions for
/// @param hashes Array of redeem instructions hashes to clear
function clearRedeem(bytes32[] calldata hashes) external onlyCreatorContract {
function clearRedeem(uint256 tokenId, bytes32[] calldata hashes) external onlyCreatorContract {
uint256 numHashes = hashes.length;

unchecked {
for (uint256 i; i < numHashes; ++i) {
redeemInstructionsHashIsAllowed[hashes[i]] = false;
redeemInstructionsHashIsAllowed[tokenId][hashes[i]] = false;
}
}

Expand All @@ -254,7 +260,11 @@ contract ZoraCreatorRedeemMinterStrategy is Enjoy, SaleStrategy, Initializable {
(RedeemInstructions, uint256[][], uint256[][])
);
bytes32 hash = redeemInstructionsHash(redeemInstructions);
if (!redeemInstructionsHashIsAllowed[hash]) {

if (tokenId != redeemInstructions.mintToken.tokenId) {
revert InvalidTokenIdsForTokenType();
}
if (!redeemInstructionsHashIsAllowed[tokenId][hash]) {
revert RedeemInstructionNotAllowed();
}
if (redeemInstructions.saleStart > block.timestamp) {
Expand Down
100 changes: 50 additions & 50 deletions test/minters/redeem/ZoraCreatorRedeemMinterFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,64 +17,64 @@ import {ZoraCreatorRedeemMinterStrategy} from "../../../src/minters/redeem/ZoraC
import {ZoraCreatorRedeemMinterFactory} from "../../../src/minters/redeem/ZoraCreatorRedeemMinterFactory.sol";

/// @notice Contract versions after v1.4.0 will not support burn to redeem
// contract ZoraCreatorRedeemMinterFactoryTest is Test {
// ProtocolRewards internal protocolRewards;
// ZoraCreator1155Impl internal target;
// ZoraCreatorRedeemMinterFactory internal minterFactory;
// address payable internal tokenAdmin = payable(address(0x999));
// address payable internal factoryAdmin = payable(address(0x888));
// address internal zora;
contract ZoraCreatorRedeemMinterFactoryTest is Test {
ProtocolRewards internal protocolRewards;
ZoraCreator1155Impl internal target;
ZoraCreatorRedeemMinterFactory internal minterFactory;
address payable internal tokenAdmin = payable(address(0x999));
address payable internal factoryAdmin = payable(address(0x888));
address internal zora;

// event RedeemMinterDeployed(address indexed creatorContract, address indexed minterContract);
event RedeemMinterDeployed(address indexed creatorContract, address indexed minterContract);

// function setUp() public {
// zora = makeAddr("zora");
// bytes[] memory emptyData = new bytes[](0);
// protocolRewards = new ProtocolRewards();
// ZoraCreator1155Impl targetImpl = new ZoraCreator1155Impl(0, zora, address(0), address(protocolRewards));
// Zora1155 proxy = new Zora1155(address(targetImpl));
// target = ZoraCreator1155Impl(address(proxy));
// target.initialize("test", "test", ICreatorRoyaltiesControl.RoyaltyConfiguration(0, 0, address(0)), tokenAdmin, emptyData);
function setUp() public {
zora = makeAddr("zora");
bytes[] memory emptyData = new bytes[](0);
protocolRewards = new ProtocolRewards();
ZoraCreator1155Impl targetImpl = new ZoraCreator1155Impl(0, zora, address(0), address(protocolRewards));
Zora1155 proxy = new Zora1155(address(targetImpl));
target = ZoraCreator1155Impl(address(proxy));
target.initialize("test", "test", ICreatorRoyaltiesControl.RoyaltyConfiguration(0, 0, address(0)), tokenAdmin, emptyData);

// minterFactory = new ZoraCreatorRedeemMinterFactory();
// }
minterFactory = new ZoraCreatorRedeemMinterFactory();
}

// function test_contractVersion() public {
// assertEq(minterFactory.contractVersion(), "1.0.1");
// }
function test_contractVersion() public {
assertEq(minterFactory.contractVersion(), "1.0.1");
}

// function test_createMinterIfNoneExists() public {
// vm.startPrank(tokenAdmin);
// target.addPermission(0, address(minterFactory), target.PERMISSION_BIT_MINTER());
// address predictedAddress = minterFactory.predictMinterAddress(address(target));
// vm.expectEmit(false, false, false, false);
// emit RedeemMinterDeployed(address(target), predictedAddress);
// target.callSale(0, minterFactory, abi.encodeWithSelector(ZoraCreatorRedeemMinterFactory.createMinterIfNoneExists.selector));
// vm.stopPrank();
function test_createMinterIfNoneExists() public {
vm.startPrank(tokenAdmin);
target.addPermission(0, address(minterFactory), target.PERMISSION_BIT_MINTER());
address predictedAddress = minterFactory.predictMinterAddress(address(target));
vm.expectEmit(false, false, false, false);
emit RedeemMinterDeployed(address(target), predictedAddress);
target.callSale(0, minterFactory, abi.encodeWithSelector(ZoraCreatorRedeemMinterFactory.createMinterIfNoneExists.selector, 0));
vm.stopPrank();

// ZoraCreatorRedeemMinterStrategy minter = ZoraCreatorRedeemMinterStrategy(predictedAddress);
// assertTrue(address(minter).code.length > 0);
// }
ZoraCreatorRedeemMinterStrategy minter = ZoraCreatorRedeemMinterStrategy(predictedAddress);
assertTrue(address(minter).code.length > 0);
}

// function test_createMinterRequiresIZoraCreator1155Caller() public {
// ERC1155PresetMinterPauser randomToken = new ERC1155PresetMinterPauser("https://uri.com");
function test_createMinterRequiresIZoraCreator1155Caller() public {
ERC1155PresetMinterPauser randomToken = new ERC1155PresetMinterPauser("https://uri.com");

// vm.expectRevert(abi.encodeWithSignature("CallerNotZoraCreator1155()"));
// vm.prank(address(randomToken));
// minterFactory.createMinterIfNoneExists();
// }
vm.expectRevert(abi.encodeWithSignature("CallerNotZoraCreator1155()"));
vm.prank(address(randomToken));
minterFactory.createMinterIfNoneExists();
}

// function test_getDeployedMinterForCreatorContract() public {
// vm.prank(address(target));
// minterFactory.createMinterIfNoneExists();
// address minterAddress = minterFactory.predictMinterAddress(address(target));
function test_getDeployedMinterForCreatorContract() public {
vm.prank(address(target));
minterFactory.createMinterIfNoneExists();
address minterAddress = minterFactory.predictMinterAddress(address(target));

// assertEq(minterAddress, minterFactory.getDeployedRedeemMinterForCreatorContract(address(target)));
// }
assertEq(minterAddress, minterFactory.getDeployedRedeemMinterForCreatorContract(address(target)));
}

// function test_supportsInterface() public {
// assertTrue(minterFactory.supportsInterface(0x01ffc9a7)); // ERC165
// assertTrue(minterFactory.supportsInterface(type(IMinter1155).interfaceId));
// assertTrue(!minterFactory.supportsInterface(0x6467a6fc)); // old IMinter1155
// }
// }
function test_supportsInterface() public {
assertTrue(minterFactory.supportsInterface(0x01ffc9a7)); // ERC165
assertTrue(minterFactory.supportsInterface(type(IMinter1155).interfaceId));
assertTrue(!minterFactory.supportsInterface(0x6467a6fc)); // old IMinter1155
}
}
Loading

0 comments on commit 87c8d3f

Please sign in to comment.