44 lines
1.4 KiB
Solidity
44 lines
1.4 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
|
|
pragma solidity ^0.8.19;
|
|
|
|
import {Test} from "forge-std/Test.sol";
|
|
import {BasicNft} from "src/BasicNft.sol";
|
|
import {DeployBasicNft} from "script/DeployBasicNft.s.sol";
|
|
|
|
contract BasicNftTest is Test {
|
|
DeployBasicNft public deployer;
|
|
BasicNft public basicNft;
|
|
address public USER = makeAddr("USER");
|
|
string public constant ipfsHoeleeImage =
|
|
"ipfs://QmW1aRxvAngY22wrxyrUYSriekkHQMcXA3D1mjHgBc5ge6?filename=MrHoelee.png";
|
|
|
|
function setUp() public {
|
|
deployer = new DeployBasicNft();
|
|
basicNft = deployer.run();
|
|
}
|
|
|
|
function testNameIsCorrect() public view {
|
|
string memory expectedName = "Hoelee";
|
|
string memory actualName = basicNft.name();
|
|
// string is array of bytes can't directly compare
|
|
// we can compare: bool, uint256, address, bytes32
|
|
|
|
// Solution: compare the hash of array of bytes
|
|
assert(
|
|
keccak256(abi.encodePacked(expectedName)) ==
|
|
keccak256(abi.encodePacked(actualName))
|
|
);
|
|
}
|
|
|
|
function testCanMintAndHaveABalance() public {
|
|
vm.prank(USER);
|
|
basicNft.mintNft(ipfsHoeleeImage);
|
|
assert(basicNft.balanceOf(USER) == 1);
|
|
assert(
|
|
keccak256(abi.encodePacked(basicNft.tokenURI(0))) ==
|
|
keccak256(abi.encodePacked(ipfsHoeleeImage))
|
|
);
|
|
}
|
|
}
|