|
| 1 | +// SPDX-License-Identifier: AGPL-3.0-only |
| 2 | +pragma solidity ^0.8.19; |
| 3 | + |
| 4 | +import "forge-std/Test.sol"; |
| 5 | +import {GV2ERC20} from "../script/GV2ERC20.sol"; |
| 6 | + |
| 7 | +contract GV2ERC20Test is Test { |
| 8 | + GV2ERC20 internal token; |
| 9 | + address internal alice = makeAddr("alice"); |
| 10 | + address internal bob = makeAddr("bob"); |
| 11 | + |
| 12 | + function setUp() public { |
| 13 | + token = new GV2ERC20("Mock Token", "MTK", 18); |
| 14 | + } |
| 15 | + |
| 16 | + function test_Metadata() public { |
| 17 | + assertEq(token.name(), "Mock Token"); |
| 18 | + assertEq(token.symbol(), "MTK"); |
| 19 | + assertEq(token.decimals(), 18); |
| 20 | + } |
| 21 | + |
| 22 | + function test_MintIncreasesBalanceAndSupply() public { |
| 23 | + uint256 amount = 1e18; |
| 24 | + token.mint(alice, amount); |
| 25 | + |
| 26 | + assertEq(token.totalSupply(), amount); |
| 27 | + assertEq(token.balanceOf(alice), amount); |
| 28 | + } |
| 29 | + |
| 30 | + function test_BurnDecreasesBalanceAndSupply() public { |
| 31 | + uint256 amount = 5e18; |
| 32 | + token.mint(alice, amount); |
| 33 | + |
| 34 | + vm.prank(alice); |
| 35 | + token.burn(alice, 2e18); |
| 36 | + |
| 37 | + assertEq(token.totalSupply(), 3e18); |
| 38 | + assertEq(token.balanceOf(alice), 3e18); |
| 39 | + } |
| 40 | + |
| 41 | + function test_TransferUsesBrutalizedAddress() public { |
| 42 | + token.mint(alice, 1e18); |
| 43 | + |
| 44 | + vm.prank(alice); |
| 45 | + bool ok = token.transfer(bob, 5e17); |
| 46 | + |
| 47 | + assertTrue(ok); |
| 48 | + assertEq(token.balanceOf(alice), 5e17); |
| 49 | + assertEq(token.balanceOf(bob), 5e17); |
| 50 | + } |
| 51 | + |
| 52 | + function test_TransferFromRespectsAllowance() public { |
| 53 | + token.mint(alice, 1e18); |
| 54 | + |
| 55 | + vm.prank(alice); |
| 56 | + token.approve(address(this), 4e17); |
| 57 | + |
| 58 | + bool ok = token.transferFrom(alice, bob, 4e17); |
| 59 | + |
| 60 | + assertTrue(ok); |
| 61 | + assertEq(token.allowance(alice, address(this)), 0); |
| 62 | + assertEq(token.balanceOf(alice), 6e17); |
| 63 | + assertEq(token.balanceOf(bob), 4e17); |
| 64 | + } |
| 65 | + |
| 66 | + function test_IncreaseDecreaseAllowance() public { |
| 67 | + vm.prank(alice); |
| 68 | + token.increaseAllowance(bob, 1e18); |
| 69 | + assertEq(token.allowance(alice, bob), 1e18); |
| 70 | + |
| 71 | + vm.prank(alice); |
| 72 | + token.decreaseAllowance(bob, 4e17); |
| 73 | + assertEq(token.allowance(alice, bob), 6e17); |
| 74 | + } |
| 75 | + |
| 76 | + function test_DirectTransfer() public { |
| 77 | + token.mint(alice, 1e18); |
| 78 | + token.directTransfer(alice, bob, 3e17); |
| 79 | + |
| 80 | + assertEq(token.balanceOf(alice), 7e17); |
| 81 | + assertEq(token.balanceOf(bob), 3e17); |
| 82 | + } |
| 83 | + |
| 84 | + function test_DirectSpendAllowance() public { |
| 85 | + token.mint(alice, 1e18); |
| 86 | + vm.prank(alice); |
| 87 | + token.approve(bob, 8e17); |
| 88 | + |
| 89 | + token.directSpendAllowance(alice, bob, 5e17); |
| 90 | + assertEq(token.allowance(alice, bob), 3e17); |
| 91 | + } |
| 92 | +} |
0 commit comments