update lending script
This commit is contained in:
@@ -177,7 +177,7 @@ contract YtLendingTest is Test {
|
||||
vm.stopPrank();
|
||||
|
||||
// 验证余额
|
||||
assertEq(lending.balanceOf(alice), 10000e18, "Alice balance should be 10,000 USDC");
|
||||
assertEq(lending.supplyBalanceOf(alice), 10000e18, "Alice balance should be 10,000 USDC");
|
||||
assertEq(lending.getTotalSupply(), 10000e18, "Total supply should be 10,000 USDC");
|
||||
|
||||
// 验证 principal(初始时 index=1,所以 principal=balance)
|
||||
@@ -195,8 +195,8 @@ contract YtLendingTest is Test {
|
||||
lending.supply(5000e18);
|
||||
|
||||
// 验证
|
||||
assertEq(lending.balanceOf(alice), 10000e18, "Alice balance");
|
||||
assertEq(lending.balanceOf(bob), 5000e18, "Bob balance");
|
||||
assertEq(lending.supplyBalanceOf(alice), 10000e18, "Alice balance");
|
||||
assertEq(lending.supplyBalanceOf(bob), 5000e18, "Bob balance");
|
||||
assertEq(lending.getTotalSupply(), 15000e18, "Total supply should be 15,000 USDC");
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ contract YtLendingTest is Test {
|
||||
vm.prank(alice);
|
||||
lending.withdraw(10000e18);
|
||||
|
||||
assertEq(lending.balanceOf(alice), 0, "Alice balance should be 0");
|
||||
assertEq(lending.supplyBalanceOf(alice), 0, "Alice balance should be 0");
|
||||
assertEq(lending.getTotalSupply(), 0, "Total supply should be 0");
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ contract YtLendingTest is Test {
|
||||
vm.prank(alice);
|
||||
lending.withdraw(3000e18);
|
||||
|
||||
assertEq(lending.balanceOf(alice), 7000e18, "Alice balance should be 7,000 USDC");
|
||||
assertEq(lending.supplyBalanceOf(alice), 7000e18, "Alice balance should be 7,000 USDC");
|
||||
assertEq(lending.getTotalSupply(), 7000e18, "Total supply should be 7,000 USDC");
|
||||
}
|
||||
|
||||
@@ -325,7 +325,7 @@ contract YtLendingTest is Test {
|
||||
// rate = base + (utilization × slope)
|
||||
// = 0% + (80% × 3%) = 2.4%
|
||||
// 预期余额 = 10,000 × 1.024 = 10,240 USDC
|
||||
uint256 aliceBalance = lending.balanceOf(alice);
|
||||
uint256 aliceBalance = lending.supplyBalanceOf(alice);
|
||||
assertApproxEqRel(aliceBalance, 10240e18, 0.001e18, "Alice should earn 2.4% interest (0.1% tolerance)");
|
||||
|
||||
// Borrow APY 计算:
|
||||
@@ -360,7 +360,7 @@ contract YtLendingTest is Test {
|
||||
// 验证复利效果(按秒计算的利息应该增长余额)
|
||||
// Alice 占总存款的 1/3 (10k / 30k),所以获得约 1/3 的供应利息
|
||||
// 利用率 = 8k / 30k ≈ 27%,供应利率较低
|
||||
uint256 aliceBalance = lending.balanceOf(alice);
|
||||
uint256 aliceBalance = lending.supplyBalanceOf(alice);
|
||||
assertTrue(aliceBalance > 10000e18, "Compound interest should grow balance");
|
||||
}
|
||||
|
||||
@@ -482,7 +482,7 @@ contract YtLendingTest is Test {
|
||||
|
||||
// 抵押品价值(打折后)= 17,500 * 0.95 = 16,625
|
||||
// 可以覆盖 16,000 债务,还剩 625
|
||||
assertTrue(lending.balanceOf(bob) > 0, "Bob should have positive balance from excess collateral");
|
||||
assertTrue(lending.supplyBalanceOf(bob) > 0, "Bob should have positive balance from excess collateral");
|
||||
}
|
||||
|
||||
function test_16_AbsorbMultiple_Batch() public {
|
||||
@@ -886,7 +886,7 @@ contract YtLendingTest is Test {
|
||||
lending.accrueInterest();
|
||||
|
||||
// 5. 验证利息累积
|
||||
uint256 aliceBalance = lending.balanceOf(alice);
|
||||
uint256 aliceBalance = lending.supplyBalanceOf(alice);
|
||||
assertTrue(aliceBalance > 50000e18, "Alice should earn interest");
|
||||
|
||||
uint256 bobDebt = lending.borrowBalanceOf(bob);
|
||||
|
||||
Reference in New Issue
Block a user