Skip to content

Commit

Permalink
feat: add supply and create market integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Grimal committed Jul 28, 2023
1 parent d308bab commit f785921
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 17 deletions.
30 changes: 18 additions & 12 deletions test/forge/BlueBase.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.20;
pragma solidity 0.8.21;

import "forge-std/Test.sol";
import "forge-std/console.sol";
Expand All @@ -12,17 +12,17 @@ import {IrmMock as Irm} from "src/mocks/IrmMock.sol";
contract BlueBaseTest is Test {
using FixedPointMathLib for uint256;

address private constant BORROWER = address(1234);
address private constant LIQUIDATOR = address(5678);
uint256 private constant LLTV = 0.8 ether;
address private constant OWNER = address(0xdead);

Blue private blue;
ERC20 private borrowableAsset;
ERC20 private collateralAsset;
Oracle private borrowableOracle;
Oracle private collateralOracle;
Irm private irm;
address internal constant BORROWER = address(1234);
address internal constant LIQUIDATOR = address(5678);
uint256 internal constant LLTV = 0.8 ether;
address internal constant OWNER = address(0xdead);

Blue internal blue;
ERC20 internal borrowableAsset;
ERC20 internal collateralAsset;
Oracle internal borrowableOracle;
Oracle internal collateralOracle;
Irm internal irm;
Market public market;
Id public id;

Expand Down Expand Up @@ -93,4 +93,10 @@ contract BlueBaseTest is Test {
uint256 totalBorrow = blue.totalBorrow(id);
return borrowerShares.divWadUp(totalShares).mulWadUp(totalBorrow);
}

function neq(Market memory a, Market memory b) internal pure returns (bool) {
return a.borrowableAsset != b.borrowableAsset || a.collateralAsset != b.collateralAsset
|| a.borrowableOracle != b.borrowableOracle || a.collateralOracle != b.collateralOracle || a.lltv != b.lltv
|| a.irm != b.irm;
}
}
14 changes: 14 additions & 0 deletions test/forge/integration/TestIntegrationCreateMarket.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.21;

import "test/forge/BlueBase.t.sol";

contract IntegrationCreateMarketTest is BlueBaseTest {
function testCreateMarketWithNotEnabledIrm(Market memory marketFuzz) public {
vm.assume(marketFuzz.irm != irm);

vm.prank(OWNER);
vm.expectRevert(bytes(Errors.IRM_NOT_ENABLED));
blue.createMarket(marketFuzz);
}
}
31 changes: 26 additions & 5 deletions test/forge/integration/TestIntegrationSupply.sol
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.20;
pragma solidity 0.8.21;

import "test/forge/BlueBase.t.sol";

contract BlueBaseTest is BlueBaseTest {
contract IntegrationSupplyTest is BlueBaseTest {


function testSupplyUnknownMarket(Market memory marketFuzz) public {
vm.assume(neq(marketFuzz, market));

vm.expectRevert("unknown market");
blue.supply(marketFuzz, 1, address(this));
}

function testSupplyUnknownMarket() public {
function testSupplyZeroAmount() public {
vm.expectRevert("zero amount");
blue.supply(market, 0, address(this));
}

function testSupply(uint256 amount) {}
function testSupply(uint256 amount) public {
amount = bound(amount, 1, 2 ** 64);

borrowableAsset.setBalance(address(this), amount);
blue.supply(market, amount, address(this));

assertEq(blue.supplyShare(id, address(this)), amount * SharesMath.VIRTUAL_SHARES, "supply share");
assertEq(borrowableAsset.balanceOf(address(this)), 0, "lender balance");
assertEq(borrowableAsset.balanceOf(address(blue)), amount, "blue balance");
}

function testSupplyOnBehalf(uint256 amount, address onBehalf) public {
vm.assume(onBehalf != address(blue));
amount = bound(amount, 1, 2 ** 64);

function testSupplyOnBehalf(uint256 amount, address onBehalf) {}
borrowableAsset.setBalance(address(this), amount);
blue.supply(market, amount, onBehalf);

assertEq(blue.supplyShare(id, onBehalf), amount * SharesMath.VIRTUAL_SHARES, "supply share");
assertEq(borrowableAsset.balanceOf(onBehalf), 0, "lender balance");
assertEq(borrowableAsset.balanceOf(address(blue)), amount, "blue balance");
}
}

0 comments on commit f785921

Please sign in to comment.