Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ cast send $TOKEN_PROXY_ADDRESS "mint(address,uint256)" <TO_ADDRESS> <AMOUNT> --r

#### Option 2: Public minting by burning ETH (no privileges required)

The total tokens minted is determined by the amount of ETH sent with the transaction.
The total tokens minted is determined by the amount of ETH sent with the transaction. There is a lower limit to the
amount that can be minted in a single transaction to prevent spam.

```bash
cast send $TOKEN_PROXY_ADDRESS "mintWithETH(address)" <TO_ACCOUNT> --value <ETH_AMOUNT> --rpc-url $RPC_URL --private-key $MINTING_ACCOUNT_PRIVATE_KEY --from $MINTING_ACCOUNT_ADDRESS
Expand Down
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
43 changes: 33 additions & 10 deletions test/TestStableToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,31 @@ 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 (with 18 decimal places, i.e., 10^18 token
// units)
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 +229,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 +248,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 +262,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 +276,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