// SPDX-License-Identifier: MIT pragma solidity ^0.8.16; import "@openzeppelin/contracts/utils/Strings.sol"; import "@openzeppelin/contracts/interfaces/IERC721.sol"; import "@openzeppelin/contracts/interfaces/IERC2981.sol"; import "./utils/BaseTest.sol"; import "#/KanjiDropERC721REnumerable.sol"; contract KanjiDropERC721REnumerableTest is BaseTest { using Strings for uint256; KanjiDropERC721REnumerable notEncrypted; KanjiDropERC721REnumerable encrypted; address public constant OWNER = address(0x5000); function setUp() public override { super.setUp(); vm.startPrank(OWNER); encrypted = new KanjiDropERC721REnumerable(NAME, SYMBOL, MAX_SUPPLY, METADATA, PRIMARY_SALE_RECIPIENTS, ROYALTY_FEE_BPS, ROYALTY_RECIPIENTS, IAccessControl(address(0))); notEncrypted = new KanjiDropERC721REnumerable(NAME, SYMBOL, MAX_SUPPLY, METADATA, PRIMARY_SALE_RECIPIENTS, ROYALTY_FEE_BPS, ROYALTY_RECIPIENTS, IAccessControl(address(0))); encrypted.lazyMint(15, ENCRYPTED_URI, FLASK_URI); notEncrypted.lazyMint(15, UNENCRYPTED_URI, ""); vm.stopPrank(); } function testTokenURI() public { vm.startPrank(OWNER); encrypted.reveal(KEY); vm.stopPrank(); for (uint256 i = 0; i < 5; i++) { assertEq(encrypted.tokenURI(i), string(abi.encodePacked(UNENCRYPTED_URI, i.toString(), ".json"))); } } function testFlaskURI() public { for (uint256 i = 0; i < 5; i++) { assertEq(encrypted.tokenURI(i), FLASK_URI); } } function testSupportsInterface() public { assertEq(true, encrypted.supportsInterface(type(IERC2981).interfaceId)); assertEq(true, encrypted.supportsInterface(type(IERC721).interfaceId)); } function testReveal() public { vm.startPrank(OWNER); encrypted.reveal(KEY); vm.stopPrank(); } function testLazyMint() public { KanjiDropERC721REnumerable temp = new KanjiDropERC721REnumerable(NAME, SYMBOL, MAX_SUPPLY, METADATA, PRIMARY_SALE_RECIPIENTS, ROYALTY_FEE_BPS, ROYALTY_RECIPIENTS, IAccessControl(address(0))); temp.lazyMint(15, ENCRYPTED_URI, FLASK_URI); } function testCannotLazyMintWithoutMainURI() public { KanjiDropERC721REnumerable temp = new KanjiDropERC721REnumerable(NAME, SYMBOL, MAX_SUPPLY, METADATA, PRIMARY_SALE_RECIPIENTS, ROYALTY_FEE_BPS, ROYALTY_RECIPIENTS, IAccessControl(address(0))); vm.expectRevert(abi.encodeWithSignature("BaseURIRequiredError()")); temp.lazyMint(15, "", FLASK_URI); } function testCannotLazyMintZeroTokens() public { KanjiDropERC721REnumerable temp = new KanjiDropERC721REnumerable(NAME, SYMBOL, MAX_SUPPLY, METADATA, PRIMARY_SALE_RECIPIENTS, ROYALTY_FEE_BPS, ROYALTY_RECIPIENTS, IAccessControl(address(0))); vm.expectRevert(abi.encodeWithSignature("AmountCantBeZeroError()")); temp.lazyMint(0, ENCRYPTED_URI, FLASK_URI); } function testCannotRevealIfNotEncrypted() public { vm.startPrank(OWNER); vm.expectRevert(abi.encodeWithSignature("NothingToReveal()")); notEncrypted.reveal(KEY); } function testMintOwner() public { vm.startPrank(OWNER, OWNER); encrypted.mintOwner(ELON, 5); vm.stopPrank(); assertEq(encrypted.balanceOf(ELON), 5); } function testCannotMintOwnerIfExceedsSupply() public { vm.startPrank(OWNER); vm.expectRevert(abi.encodeWithSignature("ExceedMaxSupplyError(uint256,uint256,uint256)", 1005, 1000, 0)); encrypted.mintOwner(ELON, 1005); vm.stopPrank(); } function testBatchMintOwner() public { vm.startPrank(OWNER, OWNER); address[] memory recipients = new address[](5); for (uint256 i = 0; i < recipients.length; i++) { recipients[i] = address(uint160(0x1000 + i)); } encrypted.batchMintOwner(recipients); for (uint256 i = 0; i < recipients.length; i++) { assertEq(encrypted.balanceOf(recipients[i]), 1); } vm.stopPrank(); } function testCannotBatchMintOwnerIfExceedssSupply() public { vm.startPrank(OWNER, OWNER); address[] memory recipients = new address[](1005); for (uint256 i = 0; i < recipients.length; i++) { recipients[i] = address(uint160(0x1000 + i)); } vm.expectRevert(abi.encodeWithSignature("ExceedMaxSupplyError(uint256,uint256,uint256)", 1005, 1000, 0)); encrypted.batchMintOwner(recipients); vm.stopPrank(); } function testTotalMinted() public { assertEq(encrypted.totalMinted(), 0); vm.startPrank(OWNER, OWNER); encrypted.mintOwner(ELON, 5); vm.stopPrank(); assertEq(encrypted.totalMinted(), 5); } function testNextTokenIdToMint() public { assertEq(encrypted.nextTokenIdToMint(), AMOUNT_TO_LAZY_MINT); } function testPause() public { vm.startPrank(OWNER, OWNER); assertEq(encrypted.paused(), false); encrypted.pause(); assertEq(encrypted.paused(), true); vm.expectRevert(abi.encodeWithSignature("PausedError()")); encrypted.mintOwner(ELON, 1); encrypted.pause(); assertEq(encrypted.paused(), false); vm.stopPrank(); } 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" }); vm.startPrank(OWNER); encrypted.setClaimConditions(conditions, false); vm.stopPrank(); } 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" }); vm.startPrank(OWNER); encrypted.setClaimConditions(conditions, false); vm.stopPrank(); vm.deal(ELON, 5 wei); vm.startPrank(ELON, ELON); encrypted.claim{value: 5 wei}(ELON, 5, new bytes32[](0)); vm.stopPrank(); assertEq(encrypted.getUsedAllowListSpot(0, 0), true); } function testCannotClaimIfNotEnoughMintedTokens() 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" }); vm.startPrank(OWNER); encrypted.setClaimConditions(conditions, false); vm.stopPrank(); vm.deal(ELON, 20 wei); vm.startPrank(ELON); vm.expectRevert(abi.encodeWithSignature("NotEnoughMintedTokensError(uint256,uint256,uint256)", 20, 0, 15)); encrypted.claim{value: 20 wei}(ELON, 20, new bytes32[](0)); vm.stopPrank(); } function testCannotClaimIfExceedsMaxSupply() public { vm.startPrank(OWNER); KanjiDropERC721REnumerable temp = new KanjiDropERC721REnumerable(NAME, SYMBOL, 10, METADATA, PRIMARY_SALE_RECIPIENTS, ROYALTY_FEE_BPS, ROYALTY_RECIPIENTS, IAccessControl(address(0))); temp.lazyMint(AMOUNT_TO_LAZY_MINT, ENCRYPTED_URI, FLASK_URI); 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" }); temp.setClaimConditions(conditions, false); vm.stopPrank(); vm.deal(ELON, 15 wei); vm.startPrank(ELON); vm.expectRevert(abi.encodeWithSignature("ExceedMaxSupplyError(uint256,uint256,uint256)", 15, 10, 0)); temp.claim{value: 15 wei}(ELON, 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" }); vm.startPrank(OWNER); encrypted.setClaimConditions(conditions, false); encrypted.setMaxWalletClaimCount(10); vm.stopPrank(); vm.deal(ELON, 15 wei); vm.startPrank(ELON); vm.expectRevert( abi.encodeWithSignature("ExceedClaimLimitForWalletError(uint256,uint256,address,uint256)", 15, 0, ELON, 10) ); encrypted.claim{value: 15 wei}(ELON, 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" }); vm.startPrank(OWNER); encrypted.setClaimConditions(conditions, false); vm.stopPrank(); vm.startPrank(ELON); vm.expectRevert(abi.encodeWithSignature("IncorrectMsgValue(uint256)", 15)); encrypted.claim(ELON, 15, new bytes32[](0)); vm.stopPrank(); } function testTotalSupply() 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" }); vm.startPrank(OWNER); encrypted.setClaimConditions(conditions, false); vm.stopPrank(); vm.deal(ELON, 5 wei); vm.startPrank(ELON, ELON); encrypted.claim{value: 5 wei}(ELON, 5, new bytes32[](0)); vm.stopPrank(); assertEq(encrypted.totalSupply(), 5); } function testTokenOfOwnerByIndex() 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" }); vm.startPrank(OWNER); encrypted.setClaimConditions(conditions, false); vm.stopPrank(); vm.deal(ELON, 1 wei); vm.recordLogs(); vm.startPrank(ELON, ELON); encrypted.claim{value: 1 wei}(ELON, 1, new bytes32[](0)); vm.stopPrank(); Vm.Log[] memory logs = vm.getRecordedLogs(); // We need to extract the tokenId from the logs. // In that case that is gonna be the first captured event log. uint256 mintedTokenId = uint256(logs[0].topics[3]); assertEq(mintedTokenId, encrypted.tokenOfOwnerByIndex(ELON, 0)); } function testTokenByIndex() 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" }); vm.startPrank(OWNER); encrypted.setClaimConditions(conditions, false); vm.stopPrank(); vm.deal(ELON, 1 wei); vm.recordLogs(); vm.startPrank(ELON, ELON); encrypted.claim{value: 1 wei}(ELON, 1, new bytes32[](0)); vm.stopPrank(); Vm.Log[] memory logs = vm.getRecordedLogs(); // We need to extract the tokenId from the logs. // In that case that is gonna be the first captured event log. uint256 mintedTokenId = uint256(logs[0].topics[3]); assertEq(mintedTokenId, encrypted.tokenByIndex(0)); } }