@@ -0,0 +1,43 @@
|
||||
// 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))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.13;
|
||||
|
||||
import {Test, console} from "forge-std/Test.sol";
|
||||
import {Counter} from "../src/Counter.sol";
|
||||
|
||||
contract CounterTest is Test {
|
||||
Counter public counter;
|
||||
|
||||
function setUp() public {
|
||||
counter = new Counter();
|
||||
counter.setNumber(0);
|
||||
}
|
||||
|
||||
function test_Increment() public {
|
||||
counter.increment();
|
||||
assertEq(counter.number(), 1);
|
||||
}
|
||||
|
||||
function testFuzz_SetNumber(uint256 x) public {
|
||||
counter.setNumber(x);
|
||||
assertEq(counter.number(), x);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user