1
0

🏗️」 wip: test not passing 😭

This commit is contained in:
2025-08-06 20:08:13 +02:00
parent f0f3458628
commit 0f77697c62
6 changed files with 181 additions and 0 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std

View File

@ -0,0 +1,3 @@
# The default one (the one you are seeing right now)
@default:
just -l

View File

@ -3,5 +3,67 @@
pragma solidity 0.8.28; pragma solidity 0.8.28;
contract Kanel42_token { contract Kanel42_token {
string public name = "Kanel42";
string public symbol = "KNL42";
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;
function transfer(address _to, uint256 _value)
public
returns (bool success)
{
balanceOf[msg.sender] -= _value;
balanceOf[_to] += _value;
emit Transfer(msg.sender, _to, _value);
success = true;
}
function transferFrom(address _from, address _to, uint256 _value)
public
returns (bool success)
{
allowance[_from][msg.sender] -= _value;
balanceOf[_from] -= _value;
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
success = true;
}
function approve(address _spender, uint256 _value)
public
returns (bool success)
{
allowance[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
success = true;
}
function mint() public payable {
uint256 minted = msg.value / mintCost * (10 ^ decimals);
balanceOf[msg.sender] += minted;
totalMinted += minted;
emit Transfer(address(0), msg.sender, minted);
}
// 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 Approval(
address indexed _owner, address indexed _spender, uint256 _value
);
} }

View File

@ -0,0 +1,86 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
import "../../lib/forge-std/src/Test.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();
}
// Test the initial supply of the token
function testInitialSupply() public {
assertEq(token.totalSupply(), 8000000000);
assertEq(token.totalMinted(), 0);
}
// Test minting tokens
function testMint() public {
uint256 initialBalance = token.balanceOf(address(this));
uint256 mintAmount = 1000000; // Mint 1 token (considering 6 decimals)
// Mint tokens by sending ether
vm.deal(address(this), 0.01 ether);
token.mint{ value: 0.01 ether }();
uint256 finalBalance = token.balanceOf(address(this));
assertEq(finalBalance - initialBalance, mintAmount);
}
// // Test transferring tokens
// function testTransfer() public {
// address sender = address(this);
// address recipient = address(1);
// uint256 transferAmount = 1000000; // Transfer 1 token (considering 6 decimals)
//
// // Mint tokens to the sender
// vm.deal(sender, 0.01 ether);
// token.mint{ value: 0.01 ether }();
//
// // Transfer tokens to the recipient
// token.transfer(recipient, transferAmount);
//
// assertEq(token.balanceOf(recipient), transferAmount);
// }
//
// // Test burning tokens
// function testBurn() public {
// uint256 initialBalance = token.balanceOf(address(this));
// uint256 burnAmount = 1000000; // 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 }();
//
// // 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 = 1000000; // Approve 1 token (considering 6 decimals)
//
// // Mint tokens to the owner
// 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);
//
// // Transfer tokens from owner to recipient using transferFrom
// vm.prank(spender);
// token.transferFrom(owner, recipient, approveAmount);
//
// assertEq(token.balanceOf(recipient), approveAmount);
// }
}

View File

@ -1,6 +1,32 @@
[profile.default] [profile.default]
src = "code" src = "code"
out = "out" out = "out"
test = "code/test"
libs = ["node_modules", "lib"] libs = ["node_modules", "lib"]
solc = '0.8.28'
# Enable or disable the optimizer
optimizer = true
# The number of optimizer runs
optimizer_runs = 200
# Fuzzing settings
[fuzz]
# The number of fuzz runs
runs = 500
# The seed for the fuzz runs
seed = '42'
# Testing settings
[fmt]
# Line length for the formatter
line_length = 80
# Number of spaces per tab
tab_width = 4
# Bracket spacing
bracket_spacing = true
# Integer type formatting
int_types = 'long'
# Multiline function signature formatting
multiline_func_header = 'attributes_first'
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options # See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

1
lib/forge-std Submodule

Submodule lib/forge-std added at 8bbcf6e3f8