93 lines
2.9 KiB
Solidity
93 lines
2.9 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
pragma solidity 0.8.28;
|
|
|
|
import "../lib/forge-std/src/Test.sol";
|
|
import { console } from "../lib/forge-std/src/console.sol";
|
|
import "../Kanel42_token.sol";
|
|
|
|
contract Kanel42TokenTest is Test {
|
|
Kanel42_token public token;
|
|
|
|
// This function runs before each test
|
|
function setUp() public {
|
|
token = new Kanel42_token();
|
|
vm.deal(address(token), 1 ether);
|
|
}
|
|
|
|
// Test the initial supply of the token
|
|
function testInitialSupply() public view {
|
|
assertEq(token.totalSupply(), 8000000000);
|
|
assertEq(token.totalMinted(), 0);
|
|
}
|
|
|
|
function testMint() public {
|
|
// Define the amount of ether to send for minting
|
|
uint256 mintAmount = 1 * (10 ** token.decimals());
|
|
|
|
// Get the initial balance of the sender
|
|
uint256 initialBalance = token.balanceOf(address(this));
|
|
|
|
// Mint tokens by sending ether
|
|
token.mint(mintAmount);
|
|
|
|
// Check if the balance increased as expected
|
|
uint256 expectedMintedAmount = mintAmount;
|
|
uint256 finalBalance = token.balanceOf(address(this));
|
|
assertEq(finalBalance - initialBalance, expectedMintedAmount, "Minted amount is incorrect");
|
|
}
|
|
|
|
function testBurn() public {
|
|
// First, mint some tokens to burn
|
|
uint256 mintAmount = 1 * (10 ** token.decimals());
|
|
token.mint(mintAmount);
|
|
|
|
// Get the initial balance of the sender
|
|
uint256 initialBalance = token.balanceOf(address(this));
|
|
|
|
// Define the amount of tokens to burn
|
|
uint256 burnAmount = mintAmount;
|
|
|
|
// Burn tokens
|
|
token.burn(burnAmount);
|
|
|
|
// Check if the balance decreased as expected
|
|
uint256 finalBalance = token.balanceOf(address(this));
|
|
assertEq(initialBalance - finalBalance, burnAmount, "Burned amount is incorrect");
|
|
}
|
|
|
|
// Test transferring tokens
|
|
function testTransfer() public {
|
|
// address sender = address(this);
|
|
address recipient = address(1);
|
|
uint256 transferAmount = 1 * (10 ** token.decimals()); // Transfer 1 token (considering 6 decimals)
|
|
|
|
// Mint tokens to the sender
|
|
token.mint(10 * (10 ** token.decimals()));
|
|
|
|
// Transfer tokens to the recipient
|
|
token.transfer(recipient, transferAmount);
|
|
|
|
assertEq(token.balanceOf(recipient), transferAmount);
|
|
}
|
|
|
|
// Test approval and transferFrom
|
|
function testApproveAndTransferFrom() public {
|
|
address owner = address(this);
|
|
address spender = address(1);
|
|
address recipient = address(2);
|
|
uint256 approveAmount = 1 * (10 ** token.decimals()); // Approve 1 token (considering 6 decimals)
|
|
|
|
// Mint tokens to the owner
|
|
token.mint(10 * (10 ** token.decimals()));
|
|
|
|
// Approve spender to spend tokens on behalf of owner
|
|
token.approve(spender, approveAmount);
|
|
|
|
// Transfer tokens from owner to recipient using transferFrom
|
|
vm.prank(spender);
|
|
token.transferFrom(owner, recipient, approveAmount);
|
|
|
|
assertEq(token.balanceOf(recipient), approveAmount);
|
|
}
|
|
}
|