Skip to content

Commit

Permalink
test: add test_debit_RevertsInsufficientPayment
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlak committed Jun 21, 2024
1 parent 88478b7 commit dc7ba33
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/test/FeeOnTransferToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ contract FeeOnTransferToken {
INTERNAL MINT/BURN LOGIC
//////////////////////////////////////////////////////////////*/

function _mint(address to, uint256 amount) internal virtual {
function mint(address to, uint256 amount) public virtual {
totalSupply += amount;

// Cannot overflow because the sum of all user
Expand All @@ -178,7 +178,7 @@ contract FeeOnTransferToken {
emit Transfer(address(0), to, amount);
}

function _burn(address from, uint256 amount) internal virtual {
function burn(address from, uint256 amount) public virtual {
balanceOf[from] -= amount;

// Cannot underflow because a user's balance
Expand Down
24 changes: 20 additions & 4 deletions test/unit/Debit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ import {Test} from "forge-std/Test.sol";
import {MockERC20} from "solmate/test/utils/mocks/MockERC20.sol";
import {FeeOnTransferToken} from "../../src/test/FeeOnTransferToken.sol";
import {MockRMM} from "../MockRMM.sol";
import {InsufficientPayment} from "./../../src/lib/RmmErrors.sol";

contract DebitTest is Test {
MockRMM rmm;

function test_debit_TransfersTokens() public {
function setUp() public {
rmm = new MockRMM(address(0), "", "");
}

function test_debit_TransfersTokens() public {
MockERC20 token = new MockERC20("", "", 18);

uint256 amount = 1 ether;

token.mint(address(this), amount);

token.approve(address(rmm), amount);

uint256 preBalanceRMM = token.balanceOf(address(rmm));
Expand All @@ -29,14 +32,12 @@ contract DebitTest is Test {
}

function test_debit_DownscalesAmount() public {
rmm = new MockRMM(address(0), "", "");
MockERC20 token = new MockERC20("", "", 6);

uint256 amountWAD = 1 ether;
uint256 amountNative = 1 * 10 ** 6;

token.mint(address(this), amountNative);

token.approve(address(rmm), amountNative);

uint256 preBalanceRMM = token.balanceOf(address(rmm));
Expand All @@ -47,4 +48,19 @@ contract DebitTest is Test {
assertEq(token.balanceOf(address(rmm)), preBalanceRMM + amountNative);
assertEq(token.balanceOf(address(this)), preBalanceUser - amountNative);
}

function test_debit_RevertsInsufficientPayment() public {
FeeOnTransferToken token = new FeeOnTransferToken();

uint256 amount = 1 ether;

token.mint(address(this), amount);
token.approve(address(rmm), amount);

vm.expectRevert(
abi.encodeWithSelector(InsufficientPayment.selector, address(token), amount - token.transferFee(), amount)
);

rmm.debit(address(token), amount);
}
}

0 comments on commit dc7ba33

Please sign in to comment.