Last active
June 25, 2025 14:15
-
-
Save m-waqas88/9e3abe0a10478735424ee1d9b391ea96 to your computer and use it in GitHub Desktop.
Test Template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity 0.8.27; | |
contract Main { | |
function test_name() external { | |
//! Inputs | |
//! Pre States | |
//! Pre-requisites Action 1 | |
//! Action 1 | |
//! Post States Action 1 | |
//! Pre-requisites Action 2 | |
//! Action 2 | |
//! Post States Action 2 | |
//! Assertions | |
} | |
function test_matchOrderUsingIdleCapitalOnly() external { | |
//! Inputs | |
uint256 lendOrderAmount = 1000e6; | |
uint256 fillOrderAmount = 1000e6; | |
uint256 killMatchedOrderAmount = 1000e6; | |
//! Pre states | |
uint256 openDepthPre = bloomPool.openDepth(); | |
uint256 lenderAmountOpenPre = bloomPool.amountOpen(lender1); | |
uint256 bloomPoolAssetBalancePre = stable.balanceOf(address(bloomPool)); | |
//! Action 1 | |
_createLendOrder(lender1, lendOrderAmount); | |
//! Post states 1 | |
uint256 openDepthPost1 = bloomPool.openDepth(); | |
uint256 lenderAmountOpenPost1 = bloomPool.amountOpen(lender1); | |
uint256 bloomPoolAssetBalancePost1 = stable.balanceOf(address(bloomPool)); | |
uint256 matchedOrdersCountPre2 = bloomPool.matchedOrderCount(lender1); | |
uint256 matchedDepthPost1 = bloomPool.matchedDepth(); | |
//! Pre-requisites Action 2 | |
vm.startPrank(owner); | |
bloomPool.whitelistBorrower(borrower1, true); | |
vm.stopPrank(); | |
//! Action 2 | |
(uint256 filled, uint256 borrowAmount) = _fillOrder(borrower1, lender1, fillOrderAmount); | |
//! Post States 2 | |
uint256 openDepthPost2 = bloomPool.openDepth(); | |
uint256 lenderAmountOpenPost2 = bloomPool.amountOpen(lender1); | |
uint256 bloomPoolAssetBalancePost2 = stable.balanceOf(address(bloomPool)); | |
uint256 matchedOrdersCountPost2 = bloomPool.matchedOrderCount(lender1); | |
uint256 matchedDepthPost2 = bloomPool.matchedDepth(); | |
uint256 matchedOrderLCollateralPost2 = bloomPool.matchedOrder(lender1, 0).lCollateral; | |
uint256 matchedOrderBCollateralPost2 = bloomPool.matchedOrder(lender1, 0).bCollateral; | |
address matchedOrderBorrowerPost2 = bloomPool.matchedOrder(lender1, 0).borrower; | |
uint256 aliceMatchedOrderDepthPost2 = bloomPool.amountMatched(lender1); | |
uint256 stableBalanceLender1Post2 = stable.balanceOf(lender1); | |
uint256 stableBalanceBorrower1Post2 = stable.balanceOf(borrower1); | |
uint256 bobIdleCapitalPost2 = bloomPool.idleCapital(borrower1); | |
//! Action 3 | |
vm.startPrank(lender1); | |
uint256 totalRemoved = bloomPool.killMatchOrder(killMatchedOrderAmount); | |
vm.stopPrank(); | |
//! Post States 3 | |
uint256 openDepthPost3 = bloomPool.openDepth(); | |
uint256 bobIdleCapitalPost3 = bloomPool.idleCapital(borrower1); | |
console.log("file: Main.t.sol:127 --> test_matchOrderUsingIdleCapitalOnly --> bobIdleCapitalPost3:", bobIdleCapitalPost3); | |
uint256 matchedDepthPost3 = bloomPool.matchedDepth(); | |
uint256 stableBalanceLender1Post3 = stable.balanceOf(lender1); | |
uint256 stableBalanceBorrower1Post3 = stable.balanceOf(borrower1); | |
//! Assertions 3 | |
//! Pre-requisites Action 4 | |
uint256 lendOrderAmount4 = 2000e6; | |
uint256 newMatchOrderAmount = bobIdleCapitalPost3.mulWad(initialLeverage); | |
console.log("file: Main.t.sol:138 --> test_matchOrderUsingIdleCapitalOnly --> newMatchOrderAmount:", newMatchOrderAmount); | |
_createLendOrder(lender2, lendOrderAmount4); | |
//! Action 4 | |
(uint256 filled4, uint256 borrowAmount4) = _fillOrder(borrower1, lender2, newMatchOrderAmount); | |
//! Post States 4 | |
uint256 openDepthPost4 = bloomPool.openDepth(); | |
uint256 bobIdleCapitalPost4 = bloomPool.idleCapital(borrower1); | |
uint256 matchedDepthPost4 = bloomPool.matchedDepth(); | |
//! Assertions Pre | |
assertEq(filled, lenderAmountOpenPost1 - lenderAmountOpenPost2, "1"); | |
assertEq(filled, openDepthPost1 - openDepthPost2, "2"); | |
assertEq(filled, matchedDepthPost2 - matchedDepthPost1, "3"); | |
assertEq(filled, matchedOrderLCollateralPost2, "4"); | |
assertEq(borrower1, matchedOrderBorrowerPost2, "5"); | |
assertEq(borrowAmount, matchedOrderBCollateralPost2, "6"); | |
assertEq(borrowAmount, bloomPoolAssetBalancePost2 - bloomPoolAssetBalancePost1, "7"); | |
assertEq(bobIdleCapitalPost3, matchedOrderBCollateralPost2, "8"); | |
assertEq(matchedOrderLCollateralPost2, killMatchedOrderAmount, "9"); | |
assertLe(totalRemoved, killMatchedOrderAmount, "10"); | |
assertEq(matchedDepthPost3, matchedDepthPost2 - totalRemoved, "11"); | |
assertEq(stableBalanceLender1Post3, stableBalanceLender1Post2 + totalRemoved, "12"); | |
//! Assertions Action 4 | |
assertEq(bobIdleCapitalPost4, 0, "13"); | |
assertEq(matchedDepthPost4, matchedDepthPost3 + filled4, "14"); | |
assertEq(matchedDepthPost4, borrowAmount4.mulWad(initialLeverage), "15"); | |
assertEq(openDepthPost4, lendOrderAmount4 - lendOrderAmount, "16"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment