Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion test/TestStableToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ contract TestStableToken is
{
mapping(address => bool) public isMinter;
uint256 public maxSupply;
uint256 public constant MIN_MINT_WEI = 1 ether;

event MinterAdded(address indexed account);
event MinterRemoved(address indexed account);
Expand Down Expand Up @@ -71,7 +72,7 @@ contract TestStableToken is
}

function mintWithETH(address to) external payable {
if (msg.value == 0) revert InsufficientETH();
if (msg.value < MIN_MINT_WEI) revert InsufficientETH();
if (totalSupply() + msg.value > maxSupply) revert ExceedsMaxSupply();

// Burn ETH by sending to zero address
Expand Down
42 changes: 32 additions & 10 deletions test/TestStableToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,30 @@ contract TestStableTokenTest is Test {
token.mintWithETH(user1);
}

function test__MintWithETH_RevertsBelowOneETH() external {
// Owner calling with less than 1 ETH should revert due to minimum requirement
uint256 sendAmount = 0.5 ether;
vm.deal(owner, sendAmount);

vm.prank(owner);
vm.expectRevert(abi.encodeWithSelector(InsufficientETH.selector));
token.mintWithETH{ value: sendAmount }(user1);
}

function test__MintWithETH_SucceedsAtOneETH() external {
// Owner calling with exactly 1 ETH should succeed and mint 1 token (1 wei == 1 token unit here)
Comment thread
stubbsta marked this conversation as resolved.
Outdated
uint256 sendAmount = 1 ether;
address recipient = vm.addr(20);

vm.deal(owner, sendAmount);
vm.prank(owner);
token.mintWithETH{ value: sendAmount }(recipient);

assertEq(token.balanceOf(recipient), sendAmount);
}

function test__ERC20BasicFunctionality() external {
uint256 ethAmount = 0.1 ether;
uint256 ethAmount = 1 ether;

vm.deal(user1, ethAmount);
vm.prank(user1);
Expand All @@ -206,14 +228,14 @@ contract TestStableTokenTest is Test {
assertEq(token.totalSupply(), ethAmount);

vm.prank(user2);
assertTrue(token.transfer(owner, 0.05 ether));
assertTrue(token.transfer(owner, 0.5 ether));

assertEq(token.balanceOf(user2), 0.05 ether);
assertEq(token.balanceOf(owner), 0.05 ether);
assertEq(token.balanceOf(user2), 0.5 ether);
assertEq(token.balanceOf(owner), 0.5 ether);
}

function test__ETHBurnedEventEmitted() external {
uint256 ethAmount = 0.1 ether;
uint256 ethAmount = 1 ether;

vm.deal(owner, ethAmount);

Expand All @@ -225,7 +247,7 @@ contract TestStableTokenTest is Test {
}

function test__ETHIsBurnedToZeroAddress() external {
uint256 ethAmount = 0.1 ether;
uint256 ethAmount = 1 ether;
address zeroAddress = address(0);

uint256 zeroBalanceBefore = zeroAddress.balance;
Expand All @@ -239,7 +261,7 @@ contract TestStableTokenTest is Test {
}

function test__ContractDoesNotHoldETHAfterMint() external {
uint256 ethAmount = 0.1 ether;
uint256 ethAmount = 1 ether;

uint256 contractBalanceBefore = address(token).balance;

Expand All @@ -253,9 +275,9 @@ contract TestStableTokenTest is Test {

function test__MintWithDifferentETHAmounts() external {
uint256[] memory ethAmounts = new uint256[](3);
ethAmounts[0] = 0.01 ether;
ethAmounts[1] = 1 ether;
ethAmounts[2] = 10 ether;
ethAmounts[0] = 1 ether;
ethAmounts[1] = 10 ether;
ethAmounts[2] = 100 ether;

for (uint256 i = 0; i < ethAmounts.length; i++) {
address user = vm.addr(i + 10);
Expand Down
Loading