Skip to content

Commit

Permalink
test: pool facet tests by smt
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandr-masl committed Oct 7, 2024
1 parent c03343b commit f7ce1e7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
6 changes: 3 additions & 3 deletions packages/contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ force = false
mainnet = "https://rpc.ankr.com/eth"

[profile.SMT.model_checker]
contracts = { }
contracts = { "test/formal/diamond/facets/UbiquityPoolFacetSMT.t.sol" = ["UbiquityPoolFacetSMT"]}
engine = 'chc'
solvers = ['z3']
show_unproved = true
timeout = 0
timeout = 5000
targets = [
'assert',
'constantCondition',
Expand All @@ -45,4 +45,4 @@ runs = 16500000 # 5h 30m
max_test_rejects = 144000000

[profile.intense.invariant]
runs = 350000 # 5h 40m
runs = 350000 # 5h 40m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {MockCurveStableSwapNG} from "../../../../src/dollar/mocks/MockCurveStabl
import {MockCurveTwocryptoOptimized} from "../../../../src/dollar/mocks/MockCurveTwocryptoOptimized.sol";
import {SafeMath} from "@openzeppelin/contracts/utils/math/SafeMath.sol";

contract UbiquityPoolFacetFormalTest is DiamondTestSetup {
contract UbiquityPoolFacetSMT is DiamondTestSetup {
using SafeMath for uint256;

// mock three tokens: collateral token, stable token, wrapped ETH token
Expand Down Expand Up @@ -147,23 +147,42 @@ contract UbiquityPoolFacetFormalTest is DiamondTestSetup {
// user approves the pool to transfer collateral
vm.prank(user);
collateralToken.approve(address(ubiquityPoolFacet), 100e18);

vm.prank(user);
ubiquityPoolFacet.mintDollar(0, 1e18, 0.9e18, 1e18, 0, true);
}

function testInitialCollateralSetup() public {
LibUbiquityPool.CollateralInformation
memory collateralInformation = ubiquityPoolFacet
.collateralInformation(address(collateralToken));
function testCannotMintMoreDollarsThanCollateral() public view {
(
uint256 totalDollarSupplyInUsd,
uint256 collateralUsdBalance
) = getDollarSupplyAndCollateralBalance();
assert(totalDollarSupplyInUsd <= collateralUsdBalance);
}

assertTrue(
collateralInformation.isEnabled,
"Collateral token should be enabled initially"
);
function testCannotRedeemMoreCollateralThanDollarValue() public view {
(
uint256 totalDollarSupplyInUsd,
uint256 collateralUsdBalance
) = getDollarSupplyAndCollateralBalance();
assert(collateralUsdBalance >= totalDollarSupplyInUsd);
}

uint256 expectedCeiling = 50_000e18; // Pool ceiling defined in setUp
assertEq(
collateralInformation.poolCeiling,
expectedCeiling,
"Collateral ceiling should be 50,000 tokens"
);
function getDollarSupplyAndCollateralBalance()
public
view
returns (uint256 totalDollarSupplyInUsd, uint256 collateralUsdBalance)
{
uint256 totalDollarSupply = IERC20Ubiquity(
managerFacet.dollarTokenAddress()
).totalSupply();

collateralUsdBalance = ubiquityPoolFacet.collateralUsdBalance();

require(collateralUsdBalance > 0, "Collateral balance is zero");
require(totalDollarSupply > 0, "Dollar supply is zero");

uint256 dollarPrice = ubiquityPoolFacet.getDollarPriceUsd();
totalDollarSupplyInUsd = totalDollarSupply.mul(dollarPrice).div(1e6);
}
}

0 comments on commit f7ce1e7

Please sign in to comment.