// SPDX-License-Identifier: MIT pragma solidity ^0.8.16; import "@openzeppelin/contracts/utils/Strings.sol"; import "@openzeppelin/contracts/interfaces/IERC1155.sol"; import "@openzeppelin/contracts/interfaces/IERC2981.sol"; import "./utils/BaseTest.sol"; import "#/KanjiDropERC1155.sol"; import "#/KanjiThirdParty.sol"; contract KanjiDropERC1155Test is BaseTest { using Strings for uint256; KanjiDropERC1155 collection; function setUp() public override { super.setUp(); collection = new KanjiDropERC1155(NAME, SYMBOL, METADATA, PRIMARY_SALE_RECIPIENTS, ROYALTY_FEE_BPS, ROYALTY_RECIPIENTS, IAccessControl(address(0))); } function testURI() public { collection.setBaseURI(1, string(UNENCRYPTED_URI), 1); assertEq(collection.uri(1), string(abi.encodePacked(UNENCRYPTED_URI, "1.json"))); } function testSupportsInterface() public { assertEq(true, collection.supportsInterface(type(IERC2981).interfaceId)); assertEq(true, collection.supportsInterface(type(IERC1155).interfaceId)); } function testMintOwner() public { collection.mintOwner(ELON, 1, 1); assertEq(collection.balanceOf(ELON, 1), 1); } function testBatchMintOwner() public { KanjiDropERC1155.BatchMintData[] memory data = new KanjiDropERC1155.BatchMintData[](1); for (uint256 i = 0; i < data.length; i++) { data[i] = KanjiDropERC1155.BatchMintData({amount: 1, editionId: 1}); } address[] memory recipients = new address[](5); for (uint256 i = 0; i < recipients.length; i++) { recipients[i] = address(uint160(0x1000 + i)); } collection.batchMintOwner(recipients, data); for (uint256 i = 0; i < recipients.length; i++) { assertEq(collection.balanceOf(recipients[i], 1), 1); } } function testPause() public { assertEq(collection.paused(), false); collection.pause(); assertEq(collection.paused(), true); vm.expectRevert(abi.encodeWithSignature("PausedError()")); collection.mintOwner(ELON, 1, 1); collection.pause(); assertEq(collection.paused(), false); } function testSetClaimConditions() public { IClaimCondition.ClaimCondition[] memory conditions = new IClaimCondition.ClaimCondition[](2); conditions[0] = IClaimCondition.ClaimCondition({ startsAt: block.timestamp, endsAt: block.timestamp + 1000, supplyClaimed: 0, maxClaimableSupply: 1000, quantityLimitPerTransaction: 5, waitTimeInSecondsBetweenClaims: 60, merkleRoot: 0x0000000000000000000000000000000000000000000000000000000000000000, pricePerToken: 1, metadata: "Test" }); conditions[1] = IClaimCondition.ClaimCondition({ startsAt: block.timestamp + 1001, endsAt: block.timestamp + 2001, supplyClaimed: 0, maxClaimableSupply: 1000, quantityLimitPerTransaction: 5, waitTimeInSecondsBetweenClaims: 60, merkleRoot: 0x0000000000000000000000000000000000000000000000000000000000000000, pricePerToken: 1, metadata: "Test" }); collection.setClaimConditions(1, conditions, false); } function testClaim() public { IClaimCondition.ClaimCondition[] memory conditions = new IClaimCondition.ClaimCondition[](1); conditions[0] = IClaimCondition.ClaimCondition({ startsAt: block.timestamp, endsAt: block.timestamp + 1000, maxClaimableSupply: 10, supplyClaimed: 0, quantityLimitPerTransaction: 10, waitTimeInSecondsBetweenClaims: 5000, merkleRoot: keccak256(abi.encodePacked(ELON)), pricePerToken: 1, metadata: "Test" }); collection.setClaimConditions(1, conditions, false); vm.deal(ELON, 5 wei); vm.startPrank(ELON); collection.claim{value: 5 wei}(ELON, 1, 5, new bytes32[](0)); vm.stopPrank(); assertEq(collection.getUsedAllowListSpot(1, 0, 0), true); } function testCannotClaimIfExceedsMaxSupply() public { IClaimCondition.ClaimCondition[] memory conditions = new IClaimCondition.ClaimCondition[](1); conditions[0] = IClaimCondition.ClaimCondition({ startsAt: block.timestamp, endsAt: block.timestamp + 1000, maxClaimableSupply: 20, supplyClaimed: 0, quantityLimitPerTransaction: 20, waitTimeInSecondsBetweenClaims: 5000, merkleRoot: keccak256(abi.encodePacked(ELON)), pricePerToken: 1, metadata: "Test" }); collection.setClaimConditions(1, conditions, false); collection.setMaxTotalSupply(1, 10); vm.deal(ELON, 15 wei); vm.startPrank(ELON); vm.expectRevert(abi.encodeWithSignature("ExceedMaxTotalSupplyError()")); collection.claim{value: 15 wei}(ELON, 1, 15, new bytes32[](0)); vm.stopPrank(); } function testCannotClaimIfExceedsClaimLimitForWallet() public { IClaimCondition.ClaimCondition[] memory conditions = new IClaimCondition.ClaimCondition[](1); conditions[0] = IClaimCondition.ClaimCondition({ startsAt: block.timestamp, endsAt: block.timestamp + 1000, maxClaimableSupply: 20, supplyClaimed: 0, quantityLimitPerTransaction: 20, waitTimeInSecondsBetweenClaims: 5000, merkleRoot: keccak256(abi.encodePacked(ELON)), pricePerToken: 1, metadata: "Test" }); collection.setClaimConditions(1, conditions, false); collection.setMaxWalletClaimCount(1, 10); vm.deal(ELON, 15 wei); vm.startPrank(ELON); vm.expectRevert( abi.encodeWithSignature("ExceedClaimLimitForWalletError(uint256,uint256,address,uint256)", 15, 0, ELON, 10) ); collection.claim{value: 15 wei}(ELON, 1, 15, new bytes32[](0)); vm.stopPrank(); } function testCannotClaimIfDidNotTransferETH() public { IClaimCondition.ClaimCondition[] memory conditions = new IClaimCondition.ClaimCondition[](1); conditions[0] = IClaimCondition.ClaimCondition({ startsAt: block.timestamp, endsAt: block.timestamp + 1000, maxClaimableSupply: 20, supplyClaimed: 0, quantityLimitPerTransaction: 20, waitTimeInSecondsBetweenClaims: 5000, merkleRoot: keccak256(abi.encodePacked(ELON)), pricePerToken: 1, metadata: "Test" }); collection.setClaimConditions(1, conditions, false); vm.startPrank(ELON); vm.expectRevert(abi.encodeWithSignature("IncorrectMsgValue(uint256)", 15)); collection.claim(ELON, 1, 15, new bytes32[](0)); vm.stopPrank(); } function testAfterMintFromThirdParty() public { KanjiThirdParty party = new KanjiThirdParty(BOB); KanjiDropERC1155 temp = new KanjiDropERC1155(NAME, SYMBOL, METADATA, PRIMARY_SALE_RECIPIENTS, ROYALTY_FEE_BPS, ROYALTY_RECIPIENTS, IAccessControl(party)); vm.prank(BOB); temp.mintFromThirdParty(BOB, 1, 5); assertEq(temp.balanceOf(BOB, 1), 5); } function testCannotMintOwnerIfExceedsSupply() public { collection.setMaxTotalSupply(1, 1000); vm.expectRevert(abi.encodeWithSignature("ExceedMaxTotalSupplyError()")); collection.mintOwner(ELON, 1, 1005); vm.stopPrank(); } // As the burn was disabled in the contract, this test is not needed // function testTransferToZeroAddress() public { // collection.mintOwner(BOB, 1, 1); // uint256 supplyBefore = collection.totalSupply(1); // vm.prank(BOB); // collection.safeTransferFrom(BOB, address(0), 1, 1, ""); // uint256 supplyAfter = collection.totalSupply(1); // assertEq(supplyBefore - 1, supplyAfter); // } }