From f3dde7bbb454036b14082e249036216967a3158f Mon Sep 17 00:00:00 2001 From: Arr00 <13561405+arr00@users.noreply.github.com> Date: Mon, 12 Aug 2024 17:37:01 -0400 Subject: [PATCH] add tests and rename files --- test/MintERC1155.t.sol | 7 +++-- test/NFTMint.t.sol | 30 ++++++++++++++++++- .../mock/EmptyContract.t.sol | 0 .../mock/MockERC1155Receiver.t.sol | 14 +++++++-- .../MockFailingRecipient.t.sol} | 19 +++++++++--- test/util/LintJSON.t.sol | 2 +- {utils => util}/lint-json.ts | 0 7 files changed, 61 insertions(+), 11 deletions(-) rename utils/EmptyContract.sol => test/mock/EmptyContract.t.sol (100%) rename utils/MockERC1155Receiver.sol => test/mock/MockERC1155Receiver.t.sol (81%) rename test/{util/MockFailingRecipient.sol => mock/MockFailingRecipient.t.sol} (65%) rename {utils => util}/lint-json.ts (100%) diff --git a/test/MintERC1155.t.sol b/test/MintERC1155.t.sol index e5584df..2ee860b 100644 --- a/test/MintERC1155.t.sol +++ b/test/MintERC1155.t.sol @@ -5,8 +5,8 @@ import { TestBase } from "./util/TestBase.t.sol"; import { MintERC1155 } from "src/MintERC1155.sol"; import { Clones } from "@openzeppelin/contracts/proxy/Clones.sol"; import { LintJSON } from "./util/LintJSON.t.sol"; -import { MockERC1155Receiver } from "utils/MockERC1155Receiver.sol"; -import { EmptyContract } from "utils/EmptyContract.sol"; +import { MockERC1155Receiver } from "./mock/MockERC1155Receiver.t.sol"; +import { EmptyContract } from "./mock/EmptyContract.t.sol"; contract MintERC1155Test is TestBase, LintJSON { MintERC1155 token; @@ -14,8 +14,9 @@ contract MintERC1155Test is TestBase, LintJSON { function setUp() external { MintERC1155 impl = new MintERC1155(address(this)); - MintERC1155.Attribute[] memory attributes = new MintERC1155.Attribute[](1); + MintERC1155.Attribute[] memory attributes = new MintERC1155.Attribute[](2); attributes[0] = MintERC1155.Attribute({ traitType: "traitType", value: "value" }); + attributes[1] = MintERC1155.Attribute({ traitType: "traitType2", value: "value2" }); MintERC1155.Edition[] memory editions = new MintERC1155.Edition[](2); editions[0] = MintERC1155.Edition({ diff --git a/test/NFTMint.t.sol b/test/NFTMint.t.sol index d2c8e54..49200b4 100644 --- a/test/NFTMint.t.sol +++ b/test/NFTMint.t.sol @@ -5,7 +5,7 @@ import { TestBase } from "./util/TestBase.t.sol"; import { NFTMint } from "src/NFTMint.sol"; import { MintERC1155 } from "src/MintERC1155.sol"; import { Vm } from "forge-std/src/Test.sol"; -import { MockFailingRecipient } from "./util/MockFailingRecipient.sol"; +import { MockFailingRecipient } from "./mock/MockFailingRecipient.t.sol"; contract NFTMintTest is TestBase { NFTMint nftMint; @@ -272,7 +272,34 @@ contract NFTMintTest is TestBase { function test_order_buyerCantReceiveERC1155() external { MintERC1155 mint = test_createMint(); + MockFailingRecipient minter = new MockFailingRecipient(); + vm.deal(address(minter), 10 ether); + minter.setReceiveERC1155(false); + + vm.expectRevert(NFTMint.NFTMint_BuyerNotAcceptingERC1155.selector); + vm.prank(address(minter)); + nftMint.order{ value: 0.011 ether }(mint, 1, "", new bytes32[](0)); + } + + function test_order_buyerCantReceiveBatchERC1155() external { + MintERC1155 mint = test_createMint(); + + MockFailingRecipient minter = new MockFailingRecipient(); + vm.deal(address(minter), 10 ether); + minter.setReceiveERC1155Batch(false); + vm.expectRevert(NFTMint.NFTMint_BuyerNotAcceptingERC1155.selector); + vm.prank(address(minter)); + nftMint.order{ value: 0.011 ether }(mint, 1, "", new bytes32[](0)); + } + + function test_order_buyerCanReceiveERC1155() external { + MintERC1155 mint = test_createMint(); + + MockFailingRecipient minter = new MockFailingRecipient(); + vm.deal(address(minter), 10 ether); + + vm.prank(address(minter)); nftMint.order{ value: 0.011 ether }(mint, 1, "", new bytes32[](0)); } @@ -382,6 +409,7 @@ contract NFTMintTest is TestBase { vm.expectRevert(NFTMint.NFTMint_FailedToTransferFunds.selector); vm.prank(minter); + // Transfer excess to trigger refund nftMint.order{ value: 0.012 ether }(mint, 1, "", new bytes32[](0)); } diff --git a/utils/EmptyContract.sol b/test/mock/EmptyContract.t.sol similarity index 100% rename from utils/EmptyContract.sol rename to test/mock/EmptyContract.t.sol diff --git a/utils/MockERC1155Receiver.sol b/test/mock/MockERC1155Receiver.t.sol similarity index 81% rename from utils/MockERC1155Receiver.sol rename to test/mock/MockERC1155Receiver.t.sol index ebc58af..ffa8981 100644 --- a/utils/MockERC1155Receiver.sol +++ b/test/mock/MockERC1155Receiver.t.sol @@ -10,7 +10,12 @@ contract MockERC1155Receiver is IERC1155Receiver { uint256, uint256, bytes calldata - ) external pure override returns (bytes4) { + ) + external + pure + override + returns (bytes4) + { return this.onERC1155Received.selector; } @@ -20,7 +25,12 @@ contract MockERC1155Receiver is IERC1155Receiver { uint256[] calldata, uint256[] calldata, bytes calldata - ) external pure override returns (bytes4) { + ) + external + pure + override + returns (bytes4) + { return this.onERC1155BatchReceived.selector; } diff --git a/test/util/MockFailingRecipient.sol b/test/mock/MockFailingRecipient.t.sol similarity index 65% rename from test/util/MockFailingRecipient.sol rename to test/mock/MockFailingRecipient.t.sol index cf8e4b9..75dbe91 100644 --- a/test/util/MockFailingRecipient.sol +++ b/test/mock/MockFailingRecipient.t.sol @@ -4,6 +4,17 @@ pragma solidity ^0.8.0; import { IERC1155Receiver } from "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol"; contract MockFailingRecipient is IERC1155Receiver { + bool public receiveERC1155 = true; + bool public receiveERC1155Batch = true; + + function setReceiveERC1155(bool value) external { + receiveERC1155 = value; + } + + function setReceiveERC1155Batch(bool value) external { + receiveERC1155Batch = value; + } + receive() external payable { revert("Failed to receive funds"); } @@ -16,11 +27,11 @@ contract MockFailingRecipient is IERC1155Receiver { bytes calldata ) external - pure + view override returns (bytes4) { - return this.onERC1155Received.selector; + return receiveERC1155 ? this.onERC1155Received.selector : bytes4(0); } function onERC1155BatchReceived( @@ -31,11 +42,11 @@ contract MockFailingRecipient is IERC1155Receiver { bytes calldata ) external - pure + view override returns (bytes4) { - return this.onERC1155BatchReceived.selector; + return receiveERC1155Batch ? this.onERC1155BatchReceived.selector : bytes4(0); } function supportsInterface(bytes4 interfaceId) public pure override returns (bool) { diff --git a/test/util/LintJSON.t.sol b/test/util/LintJSON.t.sol index 37ff022..22557db 100644 --- a/test/util/LintJSON.t.sol +++ b/test/util/LintJSON.t.sol @@ -24,7 +24,7 @@ contract LintJSON is Test { string[] memory inputs = new string[](4); inputs[0] = "npx"; inputs[1] = "ts-node"; - inputs[2] = "./utils/lint-json.ts"; + inputs[2] = "./util/lint-json.ts"; inputs[3] = filePath; bytes memory ffiResp = vm.ffi(inputs); diff --git a/utils/lint-json.ts b/util/lint-json.ts similarity index 100% rename from utils/lint-json.ts rename to util/lint-json.ts