You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dear community, I kindly request your help with invariant testing
I'm getting this error: cj@Mac foundry-defi-stablecoin-f25 % forge test --match-test invariant_protocolMustHaveMoreValueThanTotalSupply -vvv
[⠊] Compiling...
No files changed, compilation skipped
Ran 1 test for test/fuzz/OpenInvariantsTest.t.sol:InvariantsTest
[FAIL: failed to set up invariant testing environment: panic: assertion failed (0x01)] invariant_protocolMustHaveMoreValueThanTotalSupply() (runs: 0, calls: 0, reverts: 0)
Suite result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 16.84ms (3.58ms CPU time)
Ran 1 test suite in 196.44ms (16.84ms CPU time): 0 tests passed, 1 failed, 0 skipped (1 total tests)
Failing tests:
Encountered 1 failing test in test/fuzz/OpenInvariantsTest.t.sol:InvariantsTest
[FAIL: failed to set up invariant testing environment: panic: assertion failed (0x01)] invariant_protocolMustHaveMoreValueThanTotalSupply() (runs: 0, calls: 0, reverts: 0)
Encountered a total of 1 failing tests, 0 tests succeeded
*Below is my code, please help, I have been stuck here for days. Even AI is not helping.
// SPDX-License-Identifier: MIT
// Have our invariants aka properties
// What are our invariants
// 1. The total supply of DSC should be less than the total value of collateral
// 2. Getter view functions should never revert <- evergreen invariant
pragma solidity ^0.8.18;
import {Test, console} from "forge-std/Test.sol";
import {DecentralizedStableCoin} from "../../src/DecentralizedStableCoin.sol";
import {DSCEngine} from "../../src/DSCEngine.sol";
import {DeployDscEngine} from "../../script/DeployDscEngine.s.sol";
import {HelperConfig} from "../../script/HelperConfig.s.sol";
import {StdInvariant} from "forge-std/StdInvariant.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {ERC20Mock} from "../../test/mocks/ERC20Mock.sol";
contract InvariantsTest is StdInvariant, Test {
DeployDscEngine deployer;
DecentralizedStableCoin dsc;
DSCEngine engine;
HelperConfig config;
address weth;
address wbtc;
function setUp() external {
deployer = new DeployDscEngine();
(dsc, engine, config) = deployer.run();
(,, weth, wbtc,) = config.activeNetworkConfig();
targetContract(address(engine));
}
function invariant_protocolMustHaveMoreValueThanTotalSupply() public view {
// get the value of all the collateral in the protocol
// compare it to all the debt(dsc)
uint256 totalSupply = dsc.totalSupply();
uint256 totalWethDeposited = IERC20(weth).balanceOf(address(engine));
uint256 totalWbtcDeposited = IERC20(wbtc).balanceOf(address(engine));
uint256 wethValue = engine.getValueInUsd(weth, totalWethDeposited);
uint256 wbtcValue = engine.getValueInUsd(wbtc, totalWbtcDeposited);
assert(wethValue + wbtcValue > totalSupply);
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Dear community, I kindly request your help with invariant testing
I'm getting this error: cj@Mac foundry-defi-stablecoin-f25 % forge test --match-test invariant_protocolMustHaveMoreValueThanTotalSupply -vvv
[⠊] Compiling...
No files changed, compilation skipped
Ran 1 test for test/fuzz/OpenInvariantsTest.t.sol:InvariantsTest
[FAIL: failed to set up invariant testing environment: panic: assertion failed (0x01)] invariant_protocolMustHaveMoreValueThanTotalSupply() (runs: 0, calls: 0, reverts: 0)
Suite result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 16.84ms (3.58ms CPU time)
Ran 1 test suite in 196.44ms (16.84ms CPU time): 0 tests passed, 1 failed, 0 skipped (1 total tests)
Failing tests:
Encountered 1 failing test in test/fuzz/OpenInvariantsTest.t.sol:InvariantsTest
[FAIL: failed to set up invariant testing environment: panic: assertion failed (0x01)] invariant_protocolMustHaveMoreValueThanTotalSupply() (runs: 0, calls: 0, reverts: 0)
Encountered a total of 1 failing tests, 0 tests succeeded
*Below is my code, please help, I have been stuck here for days. Even AI is not helping.
// SPDX-License-Identifier: MIT
// Have our invariants aka properties
// What are our invariants
// 1. The total supply of DSC should be less than the total value of collateral
// 2. Getter view functions should never revert <- evergreen invariant
pragma solidity ^0.8.18;
import {Test, console} from "forge-std/Test.sol";
import {DecentralizedStableCoin} from "../../src/DecentralizedStableCoin.sol";
import {DSCEngine} from "../../src/DSCEngine.sol";
import {DeployDscEngine} from "../../script/DeployDscEngine.s.sol";
import {HelperConfig} from "../../script/HelperConfig.s.sol";
import {StdInvariant} from "forge-std/StdInvariant.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {ERC20Mock} from "../../test/mocks/ERC20Mock.sol";
contract InvariantsTest is StdInvariant, Test {
DeployDscEngine deployer;
DecentralizedStableCoin dsc;
DSCEngine engine;
HelperConfig config;
address weth;
address wbtc;
}
Below is my foundry.toml
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
remappings = [
"@chainlink/contracts/=lib/chainlink-brownie-contracts/contracts/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
]
[profile.default.invariant]
runs = 128
depth = 128
fail_on_revert = false
Beta Was this translation helpful? Give feedback.
All reactions