// 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 "#/KanjiDropERC721AEnumerable.sol"; contract KanjiDropERC721AEnumerableTest is BaseTest { using Strings for uint256; KanjiDropERC721AEnumerable notEncrypted; KanjiDropERC721AEnumerable encrypted; function setUp() public override { super.setUp(); encrypted = new KanjiDropERC721AEnumerable(NAME, SYMBOL, MAX_SUPPLY, METADATA, PRIMARY_SALE_RECIPIENTS, ROYALTY_FEE_BPS, ROYALTY_RECIPIENTS, IAccessControl(address(0))); notEncrypted = new KanjiDropERC721AEnumerable(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, ""); } function testTokenURI() public { encrypted.reveal(KEY); 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 { encrypted.reveal(KEY); assertEq("ipfs://encrytped-uri/0.json", encrypted.tokenURI(0)); } function testLazyMint() public { KanjiDropERC721AEnumerable temp = new KanjiDropERC721AEnumerable(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 { KanjiDropERC721AEnumerable temp = new KanjiDropERC721AEnumerable(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 { KanjiDropERC721AEnumerable temp = new KanjiDropERC721AEnumerable(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.expectRevert(abi.encodeWithSignature("NothingToReveal()")); notEncrypted.reveal(KEY); } function testMintOwner() public { encrypted.mintOwner(ELON, 1); assertEq(encrypted.balanceOf(ELON), 1); } function testCannotMintOwnerIfExceedsSupply() public { vm.expectRevert(abi.encodeWithSignature("ExceedMaxSupplyError(uint256,uint256,uint256)", 1005, 1000, 0)); encrypted.mintOwner(ELON, 1005); } function testBatchMintOwner() public { 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); } } function testCannotBatchMintOwnerIfExceedssSupply() public { 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); } function testTotalMinted() public { assertEq(encrypted.totalMinted(), 0); encrypted.mintOwner(ELON, 1); assertEq(encrypted.totalMinted(), 1); } function testNextTokenIdToMint() public { assertEq(encrypted.nextTokenIdToMint(), AMOUNT_TO_LAZY_MINT); } function testNextTokenIdToClaim() public { assertEq(encrypted.nextTokenIdToClaim(), 0); encrypted.mintOwner(ELON, 1); assertEq(encrypted.nextTokenIdToClaim(), 1); } function testPause() public { 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); } 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" }); encrypted.setClaimConditions(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" }); encrypted.setClaimConditions(conditions, false); vm.deal(ELON, 1 wei); vm.startPrank(ELON); encrypted.claim{value: 1 wei}(ELON, 1, 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" }); encrypted.setClaimConditions(conditions, false); 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 { KanjiDropERC721AEnumerable temp = new KanjiDropERC721AEnumerable(NAME, SYMBOL, 10, METADATA, PRIMARY_SALE_RECIPIENTS, ROYALTY_FEE_BPS, ROYALTY_RECIPIENTS, IAccessControl(address(0))); 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); temp.lazyMint(15, ENCRYPTED_URI, FLASK_URI); 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" }); encrypted.setClaimConditions(conditions, false); encrypted.setMaxWalletClaimCount(10); 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" }); encrypted.setClaimConditions(conditions, false); 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" }); 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" }); encrypted.setClaimConditions(conditions, false); vm.deal(ELON, 5 wei); vm.startPrank(ELON, ELON); encrypted.claim{value: 5 wei}(ELON, 5, new bytes32[](0)); vm.stopPrank(); for (uint256 i = 0; i < 5; i++) { assertEq(encrypted.tokenOfOwnerByIndex(ELON, i), i); } } 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" }); encrypted.setClaimConditions(conditions, false); vm.deal(ELON, 5 wei); vm.startPrank(ELON, ELON); encrypted.claim{value: 5 wei}(ELON, 5, new bytes32[](0)); vm.stopPrank(); for (uint256 i = 0; i < 5; i++) { assertEq(encrypted.tokenByIndex(i), i); } } }