1
0

🏗️」 wip: work in progress, not done yet.

This commit is contained in:
2025-08-10 14:58:24 +02:00
parent da391a72de
commit b2cceef044
8 changed files with 103 additions and 52 deletions

View File

@ -11,6 +11,7 @@ contract Kanel42TokenTest is Test {
// 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
@ -19,28 +20,49 @@ contract Kanel42TokenTest is Test {
assertEq(token.totalMinted(), 0);
}
// Test minting tokens
function testMint() public {
uint256 initialBalance = token.balanceOf(address(this));
uint256 mintAmount = 1 * (10 ** 6); // Mint 1 token (considering 6 decimals)
function testMint() public {
// Define the amount of ether to send for minting
uint256 mintAmount = 1 * (10 ** token.decimals());
// Mint tokens by sending ether
vm.deal(address(this), 0.01 ether);
token.mint{ value: 0.01 ether }();
// Get the initial balance of the sender
uint256 initialBalance = token.balanceOf(address(this));
uint256 finalBalance = token.balanceOf(address(this));
assertEq(finalBalance - initialBalance, mintAmount);
}
// 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 sender = address(this);
address recipient = address(1);
uint256 transferAmount = 1 * (10 ** 6); // Transfer 1 token (considering 6 decimals)
uint256 transferAmount = 1 * (10 ** token.decimals()); // Transfer 1 token (considering 6 decimals)
// Mint tokens to the sender
vm.deal(sender, 0.01 ether);
token.mint{ value: 0.01 ether }();
token.mint(10 * (10 ** token.decimals()));
// Transfer tokens to the recipient
token.transfer(recipient, transferAmount);
@ -48,33 +70,15 @@ contract Kanel42TokenTest is Test {
assertEq(token.balanceOf(recipient), transferAmount);
}
// Test burning tokens
function testBurn() public {
uint256 burnAmount = 1 * (10 ** 6); // Burn 1 token (considering 6 decimals)
// Mint tokens to have something to burn
vm.deal(address(this), 0.01 ether);
token.mint{ value: 0.01 ether }();
uint256 initialBalance = token.balanceOf(address(this));
// Burn tokens
token.burn(burnAmount);
uint256 finalBalance = token.balanceOf(address(this));
assertEq(initialBalance, finalBalance + burnAmount);
}
// Test approval and transferFrom
function testApproveAndTransferFrom() public {
address owner = address(this);
address spender = address(1);
address recipient = address(2);
uint256 approveAmount = 1 * (10 ** 6); // Approve 1 token (considering 6 decimals)
uint256 approveAmount = 1 * (10 ** token.decimals()); // Approve 1 token (considering 6 decimals)
// Mint tokens to the owner
vm.deal(owner, 0.01 ether);
token.mint{ value: 0.01 ether }();
token.mint(10 * (10 ** token.decimals()));
// Approve spender to spend tokens on behalf of owner
token.approve(spender, approveAmount);