「🏗️」 wip(wallet): seemingly working
This commit is contained in:
57
code/test/KNL_wallet.t.sol
Normal file
57
code/test/KNL_wallet.t.sol
Normal file
@ -0,0 +1,57 @@
|
||||
// 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 "../knlWallet.sol";
|
||||
import "../Kanel42_token.sol";
|
||||
|
||||
contract KNLwalletTest is Test {
|
||||
Kanel42_token public token;
|
||||
knlWallet public wallet;
|
||||
|
||||
address owner1 = address(1);
|
||||
address owner2 = address(2);
|
||||
address owner3 = address(3);
|
||||
address owner4 = address(4);
|
||||
|
||||
address to = address(5);
|
||||
|
||||
function setUp() public {
|
||||
address[] memory owners = new address[](4);
|
||||
owners[0] = owner1;
|
||||
owners[1] = owner2;
|
||||
owners[2] = owner3;
|
||||
owners[3] = owner4;
|
||||
wallet = new knlWallet(owners, 3);
|
||||
token = new Kanel42_token();
|
||||
|
||||
console.log(wallet.owners(0));
|
||||
|
||||
token.mint(10 * (10 ** token.decimals()));
|
||||
vm.prank(owner3);
|
||||
token.mint(4 * (10 ** token.decimals()));
|
||||
token.transfer(address(wallet), 4 * (10 ** token.decimals()));
|
||||
}
|
||||
|
||||
function testAdd() public {
|
||||
vm.prank(owner1);
|
||||
wallet.addTransaction(payable(to), 1, address(token));
|
||||
}
|
||||
|
||||
function testConfirm() public {
|
||||
vm.prank(owner1);
|
||||
wallet.submitTransaction(payable(to), 1, address(token));
|
||||
|
||||
uint tr = wallet.transactionCount() - 1;
|
||||
|
||||
vm.prank(owner2);
|
||||
wallet.confirmTransaction(tr);
|
||||
|
||||
vm.prank(owner3);
|
||||
wallet.confirmTransaction(tr);
|
||||
|
||||
vm.prank(owner4);
|
||||
wallet.confirmTransaction(tr);
|
||||
}
|
||||
}
|
@ -11,7 +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);
|
||||
vm.deal(address(token), 1 ether);
|
||||
}
|
||||
|
||||
// Test the initial supply of the token
|
||||
@ -20,40 +20,25 @@ contract Kanel42TokenTest is Test {
|
||||
assertEq(token.totalMinted(), 0);
|
||||
}
|
||||
|
||||
function testMint() public {
|
||||
// Define the amount of ether to send for minting
|
||||
uint256 mintAmount = 1 * (10 ** token.decimals());
|
||||
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));
|
||||
// Get the initial balance of the sender
|
||||
uint256 initialBalance = token.balanceOf(address(this));
|
||||
|
||||
// Mint tokens by sending ether
|
||||
token.mint(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");
|
||||
}
|
||||
// Check if the balance increased as expected
|
||||
uint256 expectedMintedAmount = mintAmount;
|
||||
uint256 finalBalance = token.balanceOf(address(this));
|
||||
assertEq(
|
||||
finalBalance - initialBalance,
|
||||
expectedMintedAmount,
|
||||
"Minted amount is incorrect"
|
||||
);
|
||||
}
|
||||
|
||||
// Test transferring tokens
|
||||
function testTransfer() public {
|
||||
|
Reference in New Issue
Block a user