Skip to content

Commit 43bd6d5

Browse files
committed
added fuzz test suite
1 parent cd9b4a3 commit 43bd6d5

File tree

2 files changed

+45
-45
lines changed

2 files changed

+45
-45
lines changed

foundry.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ remappings = ['@chainlink/contracts=lib/chainlink-brownie-contracts/contracts','
99

1010

1111
[invariant]
12-
runs = 1000
12+
runs = 256
1313
depth = 128 #no. of calls in a single run
14-
fail_on_revert = true
14+
fail_on_revert = false
1515

1616
[fuzz]
1717
runs = 100

test/fuzz/OpenInvariantsTest.t.sol

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,58 @@
1-
// //SPDX-License-Identifier:MIT
1+
//SPDX-License-Identifier:MIT
22

3-
// pragma solidity 0.8.24;
3+
pragma solidity 0.8.24;
44

5-
// //have our invariants aka properties that our system should always hold
5+
//have our invariants aka properties that our system should always hold
66

7-
// //Okay now what are our invariants here ?
7+
//Okay now what are our invariants here ?
88

9-
// // 1. Total value of DSC minted should be less than the total value of collateral
10-
// // 2. Getter view functions should never revert // Everngreen invariant
9+
// 1. Total value of DSC minted should be less than the total value of collateral
10+
// 2. Getter view functions should never revert // Everngreen invariant
1111

12-
// import {Test, console} from "forge-std/Test.sol";
13-
// import {StdInvariant} from "forge-std/StdInvariant.sol";
14-
// import {DeployDSC} from "../../script/DeployDSC.s.sol";
15-
// import {HelperConfig} from "../../script/HelperConfig.s.sol";
16-
// import {DSCEngine} from "../../src/DSCEngine.sol";
17-
// import {DecentralizedStableCoin} from "../../src/DecentralizedStableCoin.sol";
12+
import {Test, console} from "forge-std/Test.sol";
13+
import {StdInvariant} from "forge-std/StdInvariant.sol";
14+
import {DeployDSC} from "../../script/DeployDSC.s.sol";
15+
import {HelperConfig} from "../../script/HelperConfig.s.sol";
16+
import {DSCEngine} from "../../src/DSCEngine.sol";
17+
import {DecentralizedStableCoin} from "../../src/DecentralizedStableCoin.sol";
1818

19-
// import {ERC20Mock} from "../mocks/ERC20Mock.sol";
20-
// import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
19+
import {ERC20Mock} from "../mocks/ERC20Mock.sol";
20+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
2121

22-
// contract OpenInvariantTest is StdInvariant, Test {
23-
// // DeployDSC deployer;
24-
// DSCEngine engine;
25-
// HelperConfig helperConfig;
26-
// DecentralizedStableCoin dsc;
22+
contract OpenInvariantTest is StdInvariant, Test {
23+
// DeployDSC deployer;
24+
DSCEngine engine;
25+
HelperConfig helperConfig;
26+
DecentralizedStableCoin dsc;
2727

28-
// address public ethUsdPriceFeed;
29-
// address public btcUsdPriceFeed;
30-
// address public weth;
31-
// address public wbtc;
32-
// uint256 public deployerKey;
28+
address public ethUsdPriceFeed;
29+
address public btcUsdPriceFeed;
30+
address public weth;
31+
address public wbtc;
32+
uint256 public deployerKey;
3333

34-
// function setUp() external {
35-
// DeployDSC deployer = new DeployDSC();
36-
// (dsc, engine, helperConfig) = deployer.run();
37-
// (ethUsdPriceFeed, btcUsdPriceFeed, weth, wbtc, deployerKey) = helperConfig.activeNetworkConfig();
34+
function setUp() external {
35+
DeployDSC deployer = new DeployDSC();
36+
(dsc, engine, helperConfig) = deployer.run();
37+
(ethUsdPriceFeed, btcUsdPriceFeed, weth, wbtc, deployerKey) = helperConfig.activeNetworkConfig();
3838

39-
// console.log(address(engine));
40-
// targetContract(address(engine));
41-
// }
39+
console.log(address(engine));
40+
targetContract(address(engine));
41+
}
4242

43-
// function invariant_protocolMustHaveMoreCollateralValueThanTotalDSCSupply_() public view {
44-
// // get the value of all the collateral in protocol
45-
// // Compare it to all the debt ( DSC)
43+
function invariant_protocolMustHaveMoreCollateralValueThanTotalDSCSupply_() public view {
44+
// get the value of all the collateral in protocol
45+
// Compare it to all the debt ( DSC)
4646

47-
// uint256 totalDSCSupply = dsc.totalSupply();
48-
// uint256 ethCollateralInProtocol = ERC20Mock(weth).balanceOf(address(engine));
49-
// uint256 btcCollateralInProtocol = ERC20Mock(wbtc).balanceOf(address(engine));
47+
uint256 totalDSCSupply = dsc.totalSupply();
48+
uint256 ethCollateralInProtocol = ERC20Mock(weth).balanceOf(address(engine));
49+
uint256 btcCollateralInProtocol = ERC20Mock(wbtc).balanceOf(address(engine));
5050

51-
// uint256 ethCollateralUSDValue = engine.getUsdValue(weth, ethCollateralInProtocol);
52-
// uint256 btcCollateralUSDValue = engine.getUsdValue(wbtc, btcCollateralInProtocol);
53-
// uint256 totalUSDValueOfCollaterals = ethCollateralUSDValue + btcCollateralUSDValue;
51+
uint256 ethCollateralUSDValue = engine.getUsdValue(weth, ethCollateralInProtocol);
52+
uint256 btcCollateralUSDValue = engine.getUsdValue(wbtc, btcCollateralInProtocol);
53+
uint256 totalUSDValueOfCollaterals = ethCollateralUSDValue + btcCollateralUSDValue;
5454

55-
// assert( totalDSCSupply <= totalUSDValueOfCollaterals);
56-
// }
55+
assert( totalDSCSupply <= totalUSDValueOfCollaterals);
56+
}
5757

58-
// }
58+
}

0 commit comments

Comments
 (0)