// SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.28; import {stdStorage, StdStorage, Test} from "forge-std/Test.sol"; import {NFT} from "src/NFT.sol"; contract NFTTest is Test { using stdStorage for StdStorage; NFT private nft; function setUp() public { nft = new NFT("NFT_Tutorial", "TUT", "baseUri"); } function test_RevertMintWithoutValue() public { vm.expectRevert(NFT.MintPriceNotPaid.selector); nft.mintTo(address(1)); } function test_MintPricePaid() public { nft.mintTo{value: 0.08 ether}(address(1)); } function test_RevertMintMaxSupplyReached() public { string memory signature = "currentTokenId()"; uint256 slot = stdstore.target(address(nft)).sig(signature).find(); bytes32 loc = bytes32(slot); bytes32 mockedCurrentTokenId = bytes32(abi.encode(10000)); vm.store(address(nft), loc, mockedCurrentTokenId); vm.expectRevert(NFT.MaxSupply.selector); nft.mintTo{value: 0.08 ether}(address(1)); } function test_RevertMintToZeroAddress() public { vm.expectRevert("INVALID_RECIPIENT"); nft.mintTo{value: 0.08 ether}(address(0)); } function test_NewMintOwnerRegistered() public { nft.mintTo{value: 0.08 ether}(address(1)); uint256 slotOfNewOwner = stdstore.target(address(nft)).sig(nft.ownerOf.selector).with_key(address(1)).find(); uint160 ownerOfTokenIdOne = uint160( uint256( (vm.load(address(nft), bytes32(abi.encode(slotOfNewOwner)))) ) ); assertEq(address(ownerOfTokenIdOne), address(1)); } function test_BalanceIncremented() public { nft.mintTo{value: 0.08 ether}(address(1)); uint256 slotBalance = stdstore.target(address(nft)).sig(nft.balanceOf.selector).with_key(address(1)).find(); uint256 balanceFirstMint = uint256( vm.load(address(nft), bytes32(slotBalance)) ); assertEq(balanceFirstMint, 1); nft.mintTo{value: 0.08 ether}(address(1)); uint256 balanceSecondMint = uint256( vm.load(address(nft), bytes32(slotBalance)) ); assertEq(balanceSecondMint, 2); } }