|
1 | | -// //SPDX-License-Identifier:MIT |
| 1 | +//SPDX-License-Identifier:MIT |
2 | 2 |
|
3 | | -// pragma solidity 0.8.24; |
| 3 | +pragma solidity 0.8.24; |
4 | 4 |
|
5 | | -// //have our invariants aka properties that our system should always hold |
| 5 | +//have our invariants aka properties that our system should always hold |
6 | 6 |
|
7 | | -// //Okay now what are our invariants here ? |
| 7 | +//Okay now what are our invariants here ? |
8 | 8 |
|
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 |
11 | 11 |
|
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"; |
18 | 18 |
|
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"; |
21 | 21 |
|
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; |
27 | 27 |
|
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; |
33 | 33 |
|
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(); |
38 | 38 |
|
39 | | -// console.log(address(engine)); |
40 | | -// targetContract(address(engine)); |
41 | | -// } |
| 39 | + console.log(address(engine)); |
| 40 | + targetContract(address(engine)); |
| 41 | + } |
42 | 42 |
|
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) |
46 | 46 |
|
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)); |
50 | 50 |
|
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; |
54 | 54 |
|
55 | | -// assert( totalDSCSupply <= totalUSDValueOfCollaterals); |
56 | | -// } |
| 55 | + assert( totalDSCSupply <= totalUSDValueOfCollaterals); |
| 56 | + } |
57 | 57 |
|
58 | | -// } |
| 58 | +} |
0 commit comments