Skip to content

Commit 425bec0

Browse files
committed
add mint flow tests and extend ZToken mock for internal logic
1 parent 12fadea commit 425bec0

4 files changed

Lines changed: 57 additions & 12 deletions

File tree

src/ZToken.sol

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,20 @@ abstract contract ZToken is IZToken, ERC20 {
3939
borrowIndex = 1e18;
4040
}
4141

42+
function _mint(uint256 _zTokenAmount) internal returns (uint256) { }
43+
4244
function _getUtilization() internal pure returns (uint256) { }
4345

46+
function getTotalCash() external view returns (uint256) {
47+
return totalCash;
48+
}
49+
50+
function getReserves() external view returns (uint256) {
51+
return totalReserve;
52+
}
53+
54+
function getExchangeRate() external view returns (uint256) { }
55+
4456
function getUnderlyingToken() external view returns (address) {
4557
return UNDERLYING_TOKEN;
4658
}

test/mocks/ZTokenMock.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ import { IZToken, ZToken } from "src/ZToken.sol";
55

66
contract ZTokenMock is ZToken {
77
constructor(IZToken.MarketConfig memory _config) ZToken(_config) { }
8+
9+
function mint(uint256 _zTokenAmount) external returns (uint256) {
10+
uint256 underLyingAmount = _mint(_zTokenAmount);
11+
return underLyingAmount;
12+
}
13+
814
function name() public view override returns (string memory) { }
915
function symbol() public view override returns (string memory) { }
1016
}

test/unit/ZToken.t.sol

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity 0.8.28;
33

4-
import { Test } from "forge-std/Test.sol";
5-
import { IZToken, ZTokenMock } from "../mocks/ZTokenMock.sol";
6-
import { MockERC20 } from "../mocks/MockERC20.sol";
4+
import {Test} from "forge-std/Test.sol";
5+
6+
import {IZToken, ZTokenMock} from "../mocks/ZTokenMock.sol";
7+
import {MockERC20} from "../mocks/MockERC20.sol";
8+
import {FixedPointMathLib} from "solady/utils/FixedPointMathLib.sol";
9+
import {IERC20} from "forge-std/interfaces/IERC20.sol";
710

811
contract ZToken is Test {
12+
using FixedPointMathLib for uint256;
13+
914
ZTokenMock public zToken;
1015
MockERC20 public underlyingToken;
1116

@@ -43,15 +48,33 @@ contract ZToken is Test {
4348

4449
function test_Mint_WhenTheAmountIsZero() external {
4550
// it reverts
46-
vm.skip(true);
51+
vm.expectRevert();
52+
zToken.mint(0);
4753
}
4854

49-
function test_Mint_WhenTheAmountIsGreaterThanZero() external {
55+
function test_Mint_WhenTheAmountIsGreaterThanZero(uint256 _zTokenAmount) external {
56+
_minValue(_zTokenAmount);
57+
58+
uint256 underlyingTokenAmount = zToken.mint(_zTokenAmount);
59+
5060
// it converts the zToken amount to underlying value
61+
assertEq(zToken.getExchangeRate().mulDiv(_zTokenAmount, FixedPointMathLib.WAD), underlyingTokenAmount);
5162
// it transfers the underlying tokens to the contract
63+
assertEq(IERC20(address(underlyingToken)).balanceOf(address(zToken)), underlyingTokenAmount);
5264
// it mints the corresponding zTokens to the user
65+
assertEq(zToken.balanceOf(address(this)), _zTokenAmount);
5366
// it updates the total cash balance
67+
assertEq(zToken.getTotalCash(), underlyingTokenAmount);
5468
// it updates the reserve values and interest rate
55-
vm.skip(true);
69+
assertEq(zToken.getReserves(), 0);
70+
}
71+
72+
function test_Mint_WhenMultipleDepositAtInterval() external {
73+
// it reserve should be zero
74+
// it interest rate should still be zerp
75+
}
76+
77+
function _minValue(uint256 _amount) internal view {
78+
_amount = bound(_amount, 1e18, type(uint64).max);
5679
}
5780
}

test/unit/ZToken.tree

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ ZToken::constructor
1212
ZToken::mint
1313
├── when the amount is zero
1414
│ └── it reverts
15-
└── when the amount is greater than zero
16-
├── it converts the zToken amount to underlying value
17-
├── it transfers the underlying tokens to the contract
18-
├── it mints the corresponding zTokens to the user
19-
├── it updates the total cash balance
20-
└── it updates the reserve values and interest rate
15+
├── when the amount is greater than zero
16+
│ ├── it converts the zToken amount to underlying value
17+
│ ├── it transfers the underlying tokens to the contract
18+
│ ├── it mints the corresponding zTokens to the user
19+
│ ├── it updates the total cash balance
20+
│ ├── it updates the reserve values and interest rate
21+
│ └── it borrow snapshot should be initial borrow index
22+
└── when multiple deposit at interval
23+
├── it reserve should be zero
24+
└── it interest rate should still be zerp

0 commit comments

Comments
 (0)