From 88478b74c8e757201b65d68ca7463b5eebafbc64 Mon Sep 17 00:00:00 2001 From: clemlak Date: Fri, 21 Jun 2024 16:40:06 +0400 Subject: [PATCH] test: add debit tests --- test/unit/Debit.t.sol | 50 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/test/unit/Debit.t.sol b/test/unit/Debit.t.sol index 79ce270..89ab66c 100644 --- a/test/unit/Debit.t.sol +++ b/test/unit/Debit.t.sol @@ -2,13 +2,49 @@ pragma solidity ^0.8.13; 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"; -// These imports will be used for extra tests -import {FeeOnTransferToken} from "../../src/test/FeeOnTransferToken.sol"; -import {ReturnsTooLittleToken} from "solmate/test/utils/weird-tokens/ReturnsTooLittleToken.sol"; -import {ReturnsTooMuchToken} from "solmate/test/utils/weird-tokens/ReturnsTooMuchToken.sol"; -import {MissingReturnToken} from "solmate/test/utils/weird-tokens/MissingReturnToken.sol"; -import {ReturnsFalseToken} from "solmate/test/utils/weird-tokens/ReturnsFalseToken.sol"; +contract DebitTest is Test { + MockRMM rmm; + + function test_debit_TransfersTokens() public { + rmm = new MockRMM(address(0), "", ""); + 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)); + uint256 preBalanceUser = token.balanceOf(address(this)); + + rmm.debit(address(token), amount); + + assertEq(token.balanceOf(address(rmm)), preBalanceRMM + amount); + assertEq(token.balanceOf(address(this)), preBalanceUser - amount); + } + + 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)); + uint256 preBalanceUser = token.balanceOf(address(this)); + + rmm.debit(address(token), amountWAD); -contract DebitTest is Test {} + assertEq(token.balanceOf(address(rmm)), preBalanceRMM + amountNative); + assertEq(token.balanceOf(address(this)), preBalanceUser - amountNative); + } +}