Skip to content

Commit

Permalink
test: add debit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlak committed Jun 21, 2024
1 parent 8bd62ef commit 88478b7
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions test/unit/Debit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 88478b7

Please sign in to comment.