Skip to content

Commit

Permalink
add test for approval for liquid term token
Browse files Browse the repository at this point in the history
  • Loading branch information
eukadish committed Sep 18, 2024
1 parent 2409b9b commit 2238ac3
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
83 changes: 83 additions & 0 deletions test/LiquidTerm.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,87 @@ contract LiquidTermTest is Test {
assertEq(lTerm03.balanceOf(receiver), 1e18);
assertEq(lTerm03.balanceOf(eoa4), 999e18);
}

function testTransferFrom() external {
address receiver = vm.addr(uint256(keccak256("receiver")));

term.grantRole(term.MINTER(), address(this));

term.mint(eoa1, 0, 1_000e18);
term.mint(eoa2, 1, 1_000e18);
term.mint(eoa3, 2, 1_000e18);
term.mint(eoa4, 3, 1_000e18);

// eoa1

assertEq(lTerm00.balanceOf(receiver), 0);
assertEq(lTerm00.balanceOf(eoa1), 1_000e18);

vm.prank(eoa1);
term.setApprovalForAll(address(lTerm00), true);

vm.prank(eoa1);
lTerm00.approve(address(this), 1e18);

lTerm00.transferFrom(eoa1, receiver, 1e18);

assertEq(lTerm00.balanceOf(receiver), 1e18);
assertEq(lTerm00.balanceOf(eoa1), 999e18);

assertEq(lTerm00.allowance(eoa1, receiver), 0);

// eoa2

assertEq(lTerm01.balanceOf(receiver), 0);
assertEq(lTerm01.balanceOf(eoa2), 1_000e18);

vm.prank(eoa2);
term.setApprovalForAll(address(lTerm01), true);

vm.prank(eoa2);
lTerm01.approve(address(this), 1e18);

lTerm01.transferFrom(eoa2, receiver, 1e18);

assertEq(lTerm01.balanceOf(receiver), 1e18);
assertEq(lTerm01.balanceOf(eoa2), 999e18);

assertEq(lTerm01.allowance(eoa2, receiver), 0);

// eoa3

assertEq(lTerm02.balanceOf(receiver), 0);
assertEq(lTerm02.balanceOf(eoa3), 1_000e18);

vm.prank(eoa3);
term.setApprovalForAll(address(lTerm02), true);

vm.prank(eoa3);
lTerm02.approve(address(this), 1e18);

lTerm02.transferFrom(eoa3, receiver, 1e18);

assertEq(lTerm02.balanceOf(receiver), 1e18);
assertEq(lTerm02.balanceOf(eoa3), 999e18);

assertEq(lTerm02.allowance(eoa3, receiver), 0);

// eoa4

assertEq(lTerm03.balanceOf(receiver), 0);
assertEq(lTerm03.balanceOf(eoa4), 1_000e18);

vm.prank(eoa4);
term.setApprovalForAll(address(lTerm03), true);

vm.prank(eoa4);
lTerm03.approve(address(this), 1e18);

lTerm03.transferFrom(eoa4, receiver, 1e18);

assertEq(lTerm03.balanceOf(receiver), 1e18);
assertEq(lTerm03.balanceOf(eoa4), 999e18);

assertEq(lTerm03.allowance(eoa2, receiver), 0);
}
}
1 change: 1 addition & 0 deletions test/morpho/MorphoUnderlyingAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ contract MorphoUnderlyingAdapterTest is Test {

function testRecover(uint256 _amount, address _reciever) external {
vm.assume(_reciever != address(0));
vm.assume(_reciever != address(adapter));

ERC20 testToken = new ERC20("Test Token", "TTT");
deal(address(testToken), address(adapter), _amount);
Expand Down

0 comments on commit 2238ac3

Please sign in to comment.