「🏗️」 wip: test passing lol xor diff
This commit is contained in:
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
pragma solidity 0.8.28;
|
pragma solidity 0.8.28;
|
||||||
|
|
||||||
|
import "../../lib/forge-std/src/Test.sol";
|
||||||
|
import { console } from "../lib/forge-std/src/console.sol";
|
||||||
|
|
||||||
contract Kanel42_token {
|
contract Kanel42_token {
|
||||||
string public name = "Kanel42";
|
string public name = "Kanel42";
|
||||||
string public symbol = "KNL42";
|
string public symbol = "KNL42";
|
||||||
@ -43,7 +46,7 @@ contract Kanel42_token {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function mint() public payable {
|
function mint() public payable {
|
||||||
uint256 minted = msg.value / mintCost * (10 ^ decimals);
|
uint256 minted = msg.value / mintCost * (10 ** decimals);
|
||||||
|
|
||||||
balanceOf[msg.sender] += minted;
|
balanceOf[msg.sender] += minted;
|
||||||
totalMinted += minted;
|
totalMinted += minted;
|
||||||
@ -51,16 +54,16 @@ contract Kanel42_token {
|
|||||||
emit Transfer(address(0), msg.sender, minted);
|
emit Transfer(address(0), msg.sender, minted);
|
||||||
}
|
}
|
||||||
|
|
||||||
// function burn(uint256 _value) public {
|
function burn(uint256 _value) public {
|
||||||
// uint256 sendBack = _value / (10 ^ decimals) * mintCost * 1 ether;
|
uint256 sendBack = _value / (10 ** decimals) * mintCost * 1 ether;
|
||||||
//
|
|
||||||
// balanceOf[msg.sender] -= _value;
|
balanceOf[msg.sender] -= _value;
|
||||||
// totalMinted -= _value;
|
totalMinted -= _value;
|
||||||
//
|
|
||||||
// msg.sender.call{ value: sendBack };
|
msg.sender.call{ value: sendBack };
|
||||||
//
|
|
||||||
// emit Transfer(msg.sender, address(0), _value);
|
emit Transfer(msg.sender, address(0), _value);
|
||||||
// }
|
}
|
||||||
|
|
||||||
event Transfer(address indexed _from, address indexed _to, uint256 _value);
|
event Transfer(address indexed _from, address indexed _to, uint256 _value);
|
||||||
event Approval(
|
event Approval(
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
pragma solidity 0.8.28;
|
pragma solidity 0.8.28;
|
||||||
|
|
||||||
import "../../lib/forge-std/src/Test.sol";
|
import "../../lib/forge-std/src/Test.sol";
|
||||||
|
import { console } from "../../lib/forge-std/src/console.sol";
|
||||||
import "../Kanel42_token.sol";
|
import "../Kanel42_token.sol";
|
||||||
|
|
||||||
contract Kanel42TokenTest is Test {
|
contract Kanel42TokenTest is Test {
|
||||||
@ -21,7 +22,7 @@ contract Kanel42TokenTest is Test {
|
|||||||
// Test minting tokens
|
// Test minting tokens
|
||||||
function testMint() public {
|
function testMint() public {
|
||||||
uint256 initialBalance = token.balanceOf(address(this));
|
uint256 initialBalance = token.balanceOf(address(this));
|
||||||
uint256 mintAmount = 1000000; // Mint 1 token (considering 6 decimals)
|
uint256 mintAmount = 1 * (10 ** 6); // Mint 1 token (considering 6 decimals)
|
||||||
|
|
||||||
// Mint tokens by sending ether
|
// Mint tokens by sending ether
|
||||||
vm.deal(address(this), 0.01 ether);
|
vm.deal(address(this), 0.01 ether);
|
||||||
@ -31,56 +32,57 @@ contract Kanel42TokenTest is Test {
|
|||||||
assertEq(finalBalance - initialBalance, mintAmount);
|
assertEq(finalBalance - initialBalance, mintAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
// // Test transferring tokens
|
// Test transferring tokens
|
||||||
// function testTransfer() public {
|
function testTransfer() public {
|
||||||
// address sender = address(this);
|
address sender = address(this);
|
||||||
// address recipient = address(1);
|
address recipient = address(1);
|
||||||
// uint256 transferAmount = 1000000; // Transfer 1 token (considering 6 decimals)
|
uint256 transferAmount = 1 * (10 ** 6); // Transfer 1 token (considering 6 decimals)
|
||||||
//
|
|
||||||
// // Mint tokens to the sender
|
// Mint tokens to the sender
|
||||||
// vm.deal(sender, 0.01 ether);
|
vm.deal(sender, 0.01 ether);
|
||||||
// token.mint{ value: 0.01 ether }();
|
token.mint{ value: 0.01 ether }();
|
||||||
//
|
|
||||||
// // Transfer tokens to the recipient
|
// Transfer tokens to the recipient
|
||||||
// token.transfer(recipient, transferAmount);
|
token.transfer(recipient, transferAmount);
|
||||||
//
|
|
||||||
// assertEq(token.balanceOf(recipient), transferAmount);
|
assertEq(token.balanceOf(recipient), transferAmount);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// // Test burning tokens
|
// Test burning tokens
|
||||||
// function testBurn() public {
|
function testBurn() public {
|
||||||
// uint256 initialBalance = token.balanceOf(address(this));
|
uint256 burnAmount = 1 * (10 ** 6); // Burn 1 token (considering 6 decimals)
|
||||||
// uint256 burnAmount = 1000000; // Burn 1 token (considering 6 decimals)
|
|
||||||
//
|
// Mint tokens to have something to burn
|
||||||
// // Mint tokens to have something to burn
|
vm.deal(address(this), 0.01 ether);
|
||||||
// vm.deal(address(this), 0.01 ether);
|
token.mint{ value: 0.01 ether }();
|
||||||
// token.mint{ value: 0.01 ether }();
|
|
||||||
//
|
uint256 initialBalance = token.balanceOf(address(this));
|
||||||
// // Burn tokens
|
|
||||||
// token.burn(burnAmount);
|
// Burn tokens
|
||||||
//
|
token.burn(burnAmount);
|
||||||
// uint256 finalBalance = token.balanceOf(address(this));
|
|
||||||
// assertEq(initialBalance, finalBalance + burnAmount);
|
uint256 finalBalance = token.balanceOf(address(this));
|
||||||
// }
|
assertEq(initialBalance, finalBalance + burnAmount);
|
||||||
//
|
}
|
||||||
// // Test approval and transferFrom
|
|
||||||
// function testApproveAndTransferFrom() public {
|
// Test approval and transferFrom
|
||||||
// address owner = address(this);
|
function testApproveAndTransferFrom() public {
|
||||||
// address spender = address(1);
|
address owner = address(this);
|
||||||
// address recipient = address(2);
|
address spender = address(1);
|
||||||
// uint256 approveAmount = 1000000; // Approve 1 token (considering 6 decimals)
|
address recipient = address(2);
|
||||||
//
|
uint256 approveAmount = 1 * (10 ** 6); // Approve 1 token (considering 6 decimals)
|
||||||
// // Mint tokens to the owner
|
|
||||||
// vm.deal(owner, 0.01 ether);
|
// Mint tokens to the owner
|
||||||
// token.mint{ value: 0.01 ether }();
|
vm.deal(owner, 0.01 ether);
|
||||||
//
|
token.mint{ value: 0.01 ether }();
|
||||||
// // Approve spender to spend tokens on behalf of owner
|
|
||||||
// token.approve(spender, approveAmount);
|
// Approve spender to spend tokens on behalf of owner
|
||||||
//
|
token.approve(spender, approveAmount);
|
||||||
// // Transfer tokens from owner to recipient using transferFrom
|
|
||||||
// vm.prank(spender);
|
// Transfer tokens from owner to recipient using transferFrom
|
||||||
// token.transferFrom(owner, recipient, approveAmount);
|
vm.prank(spender);
|
||||||
//
|
token.transferFrom(owner, recipient, approveAmount);
|
||||||
// assertEq(token.balanceOf(recipient), approveAmount);
|
|
||||||
// }
|
assertEq(token.balanceOf(recipient), approveAmount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user