function mintSnowman(address receiver, uint256 amount) external {
@>
for (uint256 i = 0; i < amount; i++) {
_safeMint(receiver, s_TokenCounter);
emit SnowmanMinted(receiver, s_TokenCounter);
s_TokenCounter++;
}
}
pragma solidity ^0.8.24;
import {Test, console2} from "forge-std/Test.sol";
import {Snowman} from "../src/Snowman.sol";
import {DeploySnowman} from "../script/DeploySnowman.s.sol";
contract TestSnowman is Test {
Snowman nft;
DeploySnowman deployer;
address alice = makeAddr("alice");
address bob = makeAddr("bob");
address attacker = makeAddr("attacker");
string constant NAME = "Snowman Airdrop";
string constant SYMBOL = "SNOWMAN";
function setUp() public {
deployer = new DeploySnowman();
nft = deployer.run();
}
function testMintSnowman() public {
nft.mintSnowman(alice, 1);
nft.mintSnowman(bob, 2);
vm.prank(attacker);
nft.mintSnowman(attacker, 5);
for (uint256 i = 3; i < 8; i++) {
assertEq(nft.ownerOf(i), attacker, "Attacker should own the minted snowmen");
}
assert(nft.ownerOf(0) == alice);
assert(nft.ownerOf(1) == bob);
assert(nft.ownerOf(2) == bob);
assert(nft.ownerOf(3) == attacker);
assert(nft.balanceOf(alice) == 1);
assert(nft.balanceOf(bob) == 2);
assert(nft.balanceOf(attacker) == 5);
assert(nft.getTokenCounter() == 8);
}
}