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

0
code/KNL_wallet.sol Normal file
View File

View File

@ -8,7 +8,6 @@ contract Kanel42_token {
uint8 public decimals = 6;
uint256 public totalSupply = 8000000000; // 8000
uint256 public totalMinted;
uint256 public mintCost = 0.01 ether;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
@ -42,27 +41,18 @@ contract Kanel42_token {
success = true;
}
function mint() public payable {
uint256 minted = msg.value / mintCost * (10 ** decimals);
function mint(uint256 _value) public {
if ((totalSupply / 16) <= _value) {
revert("can't mint more than 1/16 of the supply at a time");
}
balanceOf[msg.sender] += minted;
totalMinted += minted;
balanceOf[msg.sender] += _value;
totalMinted += _value;
emit Transfer(address(0), msg.sender, minted);
emit Transfer(address(0), msg.sender, _value);
}
function burn(uint256 _value) public {
uint256 sendBack = _value / (10 ** decimals) * mintCost * 1 ether;
balanceOf[msg.sender] -= _value;
totalMinted -= _value;
msg.sender.call{ value: sendBack };
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(
address indexed _owner, address indexed _spender, uint256 _value
);

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);