diff --git a/src/test/FeeOnTransferToken.sol b/src/test/FeeOnTransferToken.sol index 90aba50..dfdccd1 100644 --- a/src/test/FeeOnTransferToken.sol +++ b/src/test/FeeOnTransferToken.sol @@ -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 @@ -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 diff --git a/test/unit/Debit.t.sol b/test/unit/Debit.t.sol index 89ab66c..f989bd6 100644 --- a/test/unit/Debit.t.sol +++ b/test/unit/Debit.t.sol @@ -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)); @@ -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)); @@ -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); + } }