Skip to content

Commit

Permalink
fix: redeem minter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kulkarohan committed Sep 26, 2023
1 parent fd46a94 commit 7769b42
Showing 1 changed file with 87 additions and 27 deletions.
114 changes: 87 additions & 27 deletions test/minters/redeem/ZoraCreatorRedeemMinterStrategy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,13 @@ contract ZoraCreatorRedeemMinterStrategyTest is Test {
uint256[][] memory amounts = new uint256[][](1);
amounts[0] = new uint256[](1);
amounts[0][0] = 500;

uint256 totalReward = target.computeTotalReward(10);
vm.deal(tokenRecipient, 1 ether + totalReward);

vm.expectEmit(true, true, false, false);
emit RedeemProcessed(address(target), keccak256(abi.encode(redeemInstructions)), tokenRecipient, tokenIds, amounts);
target.mint{value: 1 ether}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
target.mint{value: 1 ether + totalReward}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
assertEq(address(target).balance, 1 ether);
assertEq(target.balanceOf(tokenRecipient, newTokenId), 10);
assertEq(burnToken.balanceOf(tokenRecipient), 500);
Expand Down Expand Up @@ -340,7 +344,11 @@ contract ZoraCreatorRedeemMinterStrategyTest is Test {
uint256[][] memory amounts = new uint256[][](1);
amounts[0] = new uint256[](1);
amounts[0][0] = 500;
target.mint{value: 1 ether}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));

uint256 totalReward = target.computeTotalReward(10);
vm.deal(tokenRecipient, 1 ether + totalReward);
target.mint{value: 1 ether + totalReward}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));

assertEq(address(target).balance, 1 ether);
assertEq(target.balanceOf(tokenRecipient, newTokenId), 10);
assertEq(burnToken.balanceOf(tokenRecipient, 1), 500);
Expand Down Expand Up @@ -392,7 +400,11 @@ contract ZoraCreatorRedeemMinterStrategyTest is Test {
tokenIds[0][0] = 0;
tokenIds[0][1] = 1;
uint256[][] memory amounts = new uint256[][](1);
target.mint{value: 1 ether}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));

uint256 totalReward = target.computeTotalReward(10);
vm.deal(tokenRecipient, 1 ether + totalReward);

target.mint{value: 1 ether + totalReward}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
assertEq(address(target).balance, 1 ether);
assertEq(target.balanceOf(tokenRecipient, newTokenId), 10);
vm.expectRevert();
Expand Down Expand Up @@ -482,7 +494,10 @@ contract ZoraCreatorRedeemMinterStrategyTest is Test {
tokenIds[2][0] = 0;
tokenIds[2][1] = 1;

target.mint{value: 1 ether}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
uint256 totalReward = target.computeTotalReward(10);
vm.deal(tokenRecipient, 1 ether + totalReward);

target.mint{value: 1 ether + totalReward}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
assertEq(address(target).balance, 1 ether);
assertEq(target.balanceOf(tokenRecipient, newTokenId), 10);
assertEq(burnTokenERC20.balanceOf(tokenRecipient), 500);
Expand Down Expand Up @@ -572,7 +587,10 @@ contract ZoraCreatorRedeemMinterStrategyTest is Test {
tokenIds[2][0] = 0;
tokenIds[2][1] = 1;

target.mint{value: 1 ether}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
uint256 totalReward = target.computeTotalReward(10);
vm.deal(tokenRecipient, 1 ether + totalReward);

target.mint{value: 1 ether + totalReward}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
assertEq(address(target).balance, 1 ether);
assertEq(target.balanceOf(tokenRecipient, newTokenId), 10);
assertEq(burnTokenERC20.balanceOf(tokenRecipient), 500);
Expand Down Expand Up @@ -660,23 +678,26 @@ contract ZoraCreatorRedeemMinterStrategyTest is Test {
tokenIds[1][1] = 2;
tokenIds[1][2] = 3;

uint256 totalReward = target.computeTotalReward(10);
vm.deal(tokenRecipient, 5 ether + totalReward);

// detour: tokenId out of range
tokenIds[0][0] = 6;
vm.expectRevert(abi.encodeWithSignature("TokenIdOutOfRange()"));
target.mint{value: 1 ether}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
target.mint{value: 1 ether + totalReward}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
tokenIds[0][0] = 10;
vm.expectRevert(abi.encodeWithSignature("TokenIdOutOfRange()"));
target.mint{value: 1 ether}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
target.mint{value: 1 ether + totalReward}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
tokenIds[0][0] = 7;
tokenIds[1][0] = 0;
vm.expectRevert(abi.encodeWithSignature("TokenIdOutOfRange()"));
target.mint{value: 1 ether}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
target.mint{value: 1 ether + totalReward}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
tokenIds[1][0] = 4;
vm.expectRevert(abi.encodeWithSignature("TokenIdOutOfRange()"));
target.mint{value: 1 ether}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
target.mint{value: 1 ether + totalReward}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
tokenIds[1][0] = 1;

target.mint{value: 1 ether}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
target.mint{value: 1 ether + totalReward}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
assertEq(address(target).balance, 1 ether);
assertEq(target.balanceOf(tokenRecipient, newTokenId), 10);
assertEq(burnTokenERC1155.balanceOf(redeemTokenRecipient, 7), 100);
Expand Down Expand Up @@ -830,11 +851,16 @@ contract ZoraCreatorRedeemMinterStrategyTest is Test {
uint256[][] memory amounts = new uint256[][](1);
amounts[0] = new uint256[](1);
amounts[0][0] = 500;

uint256 totalReward = target.computeTotalReward(10);
vm.deal(tokenRecipient, 3 ether + totalReward);

vm.expectRevert(abi.encodeWithSignature("WrongValueSent()"));
target.mint{value: 0.9 ether}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
target.mint{value: 0.9 ether + totalReward}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
vm.expectRevert(abi.encodeWithSignature("WrongValueSent()"));
target.mint{value: 1.1 ether}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
target.mint{value: 1 ether}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
target.mint{value: 1.1 ether + totalReward}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));

target.mint{value: 1 ether + totalReward}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
vm.stopPrank();
}

Expand Down Expand Up @@ -883,12 +909,16 @@ contract ZoraCreatorRedeemMinterStrategyTest is Test {
uint256[][] memory amounts = new uint256[][](1);
amounts[0] = new uint256[](1);
amounts[0][0] = 500;
target.mint{value: 1 ether}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));

uint256 totalReward = target.computeTotalReward(10);
vm.deal(tokenRecipient, 1 ether + totalReward);

target.mint{value: 1 ether + totalReward}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
assertEq(fundsRecipient.balance, 1 ether);
vm.stopPrank();
}

function test_MintFlowAmount() external {
function testRevert_IncorrectMintTokenAmount() external {
vm.startPrank(admin);

address tokenRecipient = address(322);
Expand Down Expand Up @@ -932,8 +962,13 @@ contract ZoraCreatorRedeemMinterStrategyTest is Test {
uint256[][] memory amounts = new uint256[][](1);
amounts[0] = new uint256[](1);
amounts[0][0] = 500;

uint256 incorrectNumTokens = 11;
uint256 totalReward = target.computeTotalReward(incorrectNumTokens);
vm.deal(tokenRecipient, 1 ether + totalReward);

vm.expectRevert(abi.encodeWithSignature("IncorrectMintAmount()"));
target.mint{value: 1 ether}(redeemMinter, newTokenId, 11, abi.encode(redeemInstructions, tokenIds, amounts));
target.mint{value: 1 ether + totalReward}(redeemMinter, newTokenId, incorrectNumTokens, abi.encode(redeemInstructions, tokenIds, amounts));
vm.stopPrank();
}

Expand Down Expand Up @@ -989,8 +1024,12 @@ contract ZoraCreatorRedeemMinterStrategyTest is Test {

// ERC1155: amounts length != tokenIds length
amounts = new uint256[][](2);

uint256 totalReward = target.computeTotalReward(10);
vm.deal(tokenRecipient, 1 ether + totalReward);

vm.expectRevert(abi.encodeWithSignature("IncorrectNumberOfTokenIds()"));
target.mint{value: 1 ether}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
target.mint{value: 1 ether + totalReward}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
}

function test_MintFlowIncorrectBurnOrTransferAmount() external {
Expand Down Expand Up @@ -1059,24 +1098,27 @@ contract ZoraCreatorRedeemMinterStrategyTest is Test {
tokenIds[1][0] = 0;
tokenIds[1][1] = 1;

uint256 totalReward = target.computeTotalReward(10);
vm.deal(tokenRecipient, 4 ether + totalReward);

// ERC721: tokenids length != instruction amount
tokenIds[1] = new uint256[](1);
vm.expectRevert(abi.encodeWithSignature("IncorrectBurnOrTransferAmount()"));
target.mint{value: 1 ether}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
target.mint{value: 1 ether + totalReward}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
tokenIds[1] = new uint256[](3);
vm.expectRevert(abi.encodeWithSignature("IncorrectBurnOrTransferAmount()"));
target.mint{value: 1 ether}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
target.mint{value: 1 ether + totalReward}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
tokenIds[1] = new uint256[](2);
tokenIds[1][0] = 0;
tokenIds[1][1] = 1;

// ERC1155: sum of amounts != instruction amount
amounts[0][0] = 499;
vm.expectRevert(abi.encodeWithSignature("IncorrectBurnOrTransferAmount()"));
target.mint{value: 1 ether}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
target.mint{value: 1 ether + totalReward}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
amounts[0][0] = 501;
vm.expectRevert(abi.encodeWithSignature("IncorrectBurnOrTransferAmount()"));
target.mint{value: 1 ether}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
target.mint{value: 1 ether + totalReward}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));

vm.stopPrank();
}
Expand Down Expand Up @@ -1133,8 +1175,11 @@ contract ZoraCreatorRedeemMinterStrategyTest is Test {
amounts[0] = new uint256[](1);
amounts[0][0] = 500;

uint256 totalReward = target.computeTotalReward(10);
vm.deal(tokenRecipient, 1 ether + totalReward);

vm.expectRevert(abi.encodeWithSignature("BurnFailed()"));
target.mint{value: 1 ether}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
target.mint{value: 1 ether + totalReward}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
vm.stopPrank();
}

Expand Down Expand Up @@ -1193,8 +1238,11 @@ contract ZoraCreatorRedeemMinterStrategyTest is Test {
amounts[0] = new uint256[](1);
amounts[0][0] = 500;

uint256 totalReward = target.computeTotalReward(10);
vm.deal(tokenRecipient, 1 ether + totalReward);

vm.expectRevert(abi.encodeWithSignature("BurnFailed()"));
target.mint{value: 1 ether}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
target.mint{value: 1 ether + totalReward}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
vm.stopPrank();
}

Expand Down Expand Up @@ -1254,8 +1302,11 @@ contract ZoraCreatorRedeemMinterStrategyTest is Test {
tokenIds[0][1] = 1;
uint256[][] memory amounts;

uint256 totalReward = target.computeTotalReward(10);
vm.deal(tokenRecipient, 1 ether + totalReward);

vm.expectRevert(abi.encodeWithSignature("SenderIsNotTokenOwner()"));
target.mint{value: 1 ether}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
target.mint{value: 1 ether + totalReward}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
vm.stopPrank();
}

Expand Down Expand Up @@ -1312,8 +1363,11 @@ contract ZoraCreatorRedeemMinterStrategyTest is Test {
amounts[0] = new uint256[](1);
amounts[0][0] = 500;

uint256 totalReward = target.computeTotalReward(10);
vm.deal(tokenRecipient, 1 ether + totalReward);

vm.expectRevert("ERC20: transfer amount exceeds balance");
target.mint{value: 1 ether}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
target.mint{value: 1 ether + totalReward}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
vm.stopPrank();
}

Expand Down Expand Up @@ -1372,8 +1426,11 @@ contract ZoraCreatorRedeemMinterStrategyTest is Test {
amounts[0] = new uint256[](1);
amounts[0][0] = 500;

uint256 totalReward = target.computeTotalReward(10);
vm.deal(tokenRecipient, 1 ether + totalReward);

vm.expectRevert("ERC1155: insufficient balance for transfer");
target.mint{value: 1 ether}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
target.mint{value: 1 ether + totalReward}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
vm.stopPrank();
}

Expand Down Expand Up @@ -1431,8 +1488,11 @@ contract ZoraCreatorRedeemMinterStrategyTest is Test {
tokenIds[0][1] = 1;
uint256[][] memory amounts;

uint256 totalReward = target.computeTotalReward(10);
vm.deal(tokenRecipient, 1 ether + totalReward);

vm.expectRevert("ERC721: caller is not token owner or approved");
target.mint{value: 1 ether}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
target.mint{value: 1 ether + totalReward}(redeemMinter, newTokenId, 10, abi.encode(redeemInstructions, tokenIds, amounts));
vm.stopPrank();
}

Expand Down

0 comments on commit 7769b42

Please sign in to comment.