Skip to content

Commit

Permalink
add tests and rename files
Browse files Browse the repository at this point in the history
  • Loading branch information
arr00 committed Aug 13, 2024
1 parent d2cda20 commit f3dde7b
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 11 deletions.
7 changes: 4 additions & 3 deletions test/MintERC1155.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ 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;

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({
Expand Down
30 changes: 29 additions & 1 deletion test/NFTMint.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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));
}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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(
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/util/LintJSON.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
File renamed without changes.

0 comments on commit f3dde7b

Please sign in to comment.