-
I am having an error on my depositCallateral function test after adding mintDsc in my handler. forge test --mt invariant_protocolMustHaveMoreValueThanTotallSupply -vvvv
[⠊] Compiling...
[⠒] Compiling 2 files with Solc 0.8.27
[⠑] Solc 0.8.27 finished in 1.48s
Compiler run successful!
Ran 1 test for test/fuzz/InvariantsTest.t.sol:InvariantsTest
[FAIL: invariant_protocolMustHaveMoreValueThanTotallSupply replay failure]
[Sequence]
sender=0x00000000000000000000001961a541E15841b076 addr=[test/fuzz/Handler.t.sol:Handler]0x2e234DAe75C793f67A35089C9d99245E1C58470b calldata=depositeCollateral(uint256,uint256) args=[39560706476785038755679430821 [3.956e28], 672700926431490119484263488950076325611034650633015652263822667785311069 [6.727e71]]
sender=0x00000000000000000000001961a541E15841b076 addr=[test/fuzz/Handler.t.sol:Handler]0x2e234DAe75C793f67A35089C9d99245E1C58470b calldata=mintDsc(uint256) args=[1432]
invariant_protocolMustHaveMoreValueThanTotallSupply() (runs: 1, calls: 1, reverts: 1)
Logs:
Bound result 1763125541979788303892091374
Bound result 1432
weth value in USD 0
wbtc value in USD 0
total supply value in USD 1432
Traces:
[11486501] InvariantsTest::setUp()
├─ [4600863] → new DeployDSC@0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f
│ └─ ← [Return] 22867 bytes of code
├─ [5317937] DeployDSC::run()
│ ├─ [3341120] → new HelperConfig@0x104fBc016F4bb334D775a19E8A6510109AC63E00
│ │ ├─ [0] VM::startBroadcast()
│ │ │ └─ ← [Return]
│ │ ├─ [372255] → new MockV3Aggregator@0x90193C961A926261B756D1E5bb255e67ff9498A1
│ │ │ └─ ← [Return] 1082 bytes of code
│ │ ├─ [516505] → new ERC20Mock@0xA8452Ec99ce0C64f20701dB7dD3abDb607c00496
│ │ │ ├─ emit Transfer(from: 0x0000000000000000000000000000000000000000, to: DeployDSC: [0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f], value: 1000000000000 [1e12])
│ │ │ └─ ← [Return] 2117 bytes of code
│ │ ├─ [372255] → new MockV3Aggregator@0xBb2180ebd78ce97360503434eD37fcf4a1Df61c3
│ │ │ └─ ← [Return] 1082 bytes of code
│ │ ├─ [516505] → new ERC20Mock@0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76
│ │ │ ├─ emit Transfer(from: 0x0000000000000000000000000000000000000000, to: DeployDSC: [0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f], value: 1000000000000 [1e12])
│ │ │ └─ ← [Return] 2117 bytes of code
│ │ ├─ [0] VM::stopBroadcast()
│ │ │ └─ ← [Return]
│ │ └─ ← [Return] 6368 bytes of code
│ ├─ [934] HelperConfig::activeNetworkConfig() [staticcall]
│ │ └─ ← [Return] MockV3Aggregator: [0x90193C961A926261B756D1E5bb255e67ff9498A1], MockV3Aggregator: [0xBb2180ebd78ce97360503434eD37fcf4a1Df61c3], ERC20Mock: [0xA8452Ec99ce0C64f20701dB7dD3abDb607c00496], ERC20Mock: [0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76], 77814517325470205911140941194401928579557062014761831930645393041380819009408 [7.781e76]
│ ├─ [0] VM::startBroadcast(<pk>)
│ │ └─ ← [Return]
│ ├─ [591455] → new DecentralizedStableCoin@0x5FbDB2315678afecb367f032d93F642f64180aa3
│ │ ├─ emit OwnershipTransferred(previousOwner: 0x0000000000000000000000000000000000000000, newOwner: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266)
│ │ └─ ← [Return] 2610 bytes of code
│ ├─ [1099514] → new DSCEngine@0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
│ │ └─ ← [Return] 4814 bytes of code
│ ├─ [2424] DecentralizedStableCoin::transferOwnership(DSCEngine: [0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512])
│ │ ├─ emit OwnershipTransferred(previousOwner: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266, newOwner: DSCEngine: [0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512])
│ │ └─ ← [Stop]
│ ├─ [0] VM::stopBroadcast()
│ │ └─ ← [Return]
│ └─ ← [Return] DecentralizedStableCoin: [0x5FbDB2315678afecb367f032d93F642f64180aa3], DSCEngine: [0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512], HelperConfig: [0x104fBc016F4bb334D775a19E8A6510109AC63E00]
├─ [934] HelperConfig::activeNetworkConfig() [staticcall]
│ └─ ← [Return] MockV3Aggregator: [0x90193C961A926261B756D1E5bb255e67ff9498A1], MockV3Aggregator: [0xBb2180ebd78ce97360503434eD37fcf4a1Df61c3], ERC20Mock: [0xA8452Ec99ce0C64f20701dB7dD3abDb607c00496], ERC20Mock: [0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76], 77814517325470205911140941194401928579557062014761831930645393041380819009408 [7.781e76]
├─ [1312501] → new Handler@0x2e234DAe75C793f67A35089C9d99245E1C58470b
│ ├─ [1400] DSCEngine::getCollateralTokens() [staticcall]
│ │ └─ ← [Return] [0xA8452Ec99ce0C64f20701dB7dD3abDb607c00496, 0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76]
│ └─ ← [Return] 5876 bytes of code
└─ ← [Stop]
[133529] Handler::depositeCollateral(39560706476785038755679430821 [3.956e28], 672700926431490119484263488950076325611034650633015652263822667785311069 [6.727e71])
├─ [0] console::log("Bound result", 1763125541979788303892091374 [1.763e27]) [staticcall]
│ └─ ← [Stop]
├─ [0] VM::startPrank(0x00000000000000000000001961a541E15841b076)
│ └─ ← [Return]
├─ [29712] ERC20Mock::mint(0x00000000000000000000001961a541E15841b076, 1763125541979788303892091374 [1.763e27])
│ ├─ emit Transfer(from: 0x0000000000000000000000000000000000000000, to: 0x00000000000000000000001961a541E15841b076, value: 1763125541979788303892091374 [1.763e27])
│ └─ ← [Stop]
├─ [24739] ERC20Mock::approve(DSCEngine: [0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512], 1763125541979788303892091374 [1.763e27])
│ ├─ emit Approval(owner: 0x00000000000000000000001961a541E15841b076, spender: DSCEngine: [0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512], value: 1763125541979788303892091374 [1.763e27])
│ └─ ← [Return] true
├─ [58682] DSCEngine::depositCollateral(ERC20Mock: [0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76], 1763125541979788303892091374 [1.763e27])
│ ├─ emit CollateralDeposited(user: 0x00000000000000000000001961a541E15841b076, token: ERC20Mock: [0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76], amount: 1763125541979788303892091374 [1.763e27])
│ ├─ [26088] ERC20Mock::transferFrom(0x00000000000000000000001961a541E15841b076, DSCEngine: [0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512], 1763125541979788303892091374 [1.763e27])
│ │ ├─ emit Transfer(from: 0x00000000000000000000001961a541E15841b076, to: DSCEngine: [0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512], value: 1763125541979788303892091374 [1.763e27])
│ │ └─ ← [Return] true
│ └─ ← [Stop]
├─ [0] VM::stopPrank()
│ └─ ← [Return]
└─ ← [Stop]
[140972] Handler::mintDsc(1432)
├─ [43718] DSCEngine::getAccountInformation(0x00000000000000000000001961a541E15841b076) [staticcall]
│ ├─ [8993] MockV3Aggregator::latestRoundData() [staticcall]
│ │ └─ ← [Return] 1, 250000000000 [2.5e11], 1, 1, 1
│ ├─ [8993] MockV3Aggregator::latestRoundData() [staticcall]
│ │ └─ ← [Return] 1, 650000000000 [6.5e11], 1, 1, 1
│ └─ ← [Return] 0, 11460316022868623975298593931000 [1.146e31]
├─ [0] console::log("Bound result", 1432) [staticcall]
│ └─ ← [Stop]
├─ [0] VM::startPrank(0x00000000000000000000001961a541E15841b076)
│ └─ ← [Return]
├─ [84569] DSCEngine::mintDsc(1432)
│ ├─ [993] MockV3Aggregator::latestRoundData() [staticcall]
│ │ └─ ← [Return] 1, 250000000000 [2.5e11], 1, 1, 1
│ ├─ [993] MockV3Aggregator::latestRoundData() [staticcall]
│ │ └─ ← [Return] 1, 650000000000 [6.5e11], 1, 1, 1
│ ├─ [49149] DecentralizedStableCoin::mint(0x00000000000000000000001961a541E15841b076, 1432)
│ │ ├─ emit Transfer(from: 0x0000000000000000000000000000000000000000, to: 0x00000000000000000000001961a541E15841b076, value: 1432)
│ │ └─ ← [Return] true
│ └─ ← [Stop]
├─ [0] VM::stopPrank()
│ └─ ← [Return]
└─ ← [Stop]
[63539] InvariantsTest::invariant_protocolMustHaveMoreValueThanTotallSupply()
├─ [2349] DecentralizedStableCoin::totalSupply() [staticcall]
│ └─ ← [Return] 1432
├─ [2607] ERC20Mock::balanceOf(DecentralizedStableCoin: [0x5FbDB2315678afecb367f032d93F642f64180aa3]) [staticcall]
│ └─ ← [Return] 0
├─ [2607] ERC20Mock::balanceOf(DecentralizedStableCoin: [0x5FbDB2315678afecb367f032d93F642f64180aa3]) [staticcall]
│ └─ ← [Return] 0
├─ [15003] DSCEngine::getUsdValue(ERC20Mock: [0xA8452Ec99ce0C64f20701dB7dD3abDb607c00496], 0) [staticcall]
│ ├─ [8993] MockV3Aggregator::latestRoundData() [staticcall]
│ │ └─ ← [Return] 1, 250000000000 [2.5e11], 1, 1, 1
│ └─ ← [Return] 0
├─ [15003] DSCEngine::getUsdValue(ERC20Mock: [0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76], 0) [staticcall]
│ ├─ [8993] MockV3Aggregator::latestRoundData() [staticcall]
│ │ └─ ← [Return] 1, 650000000000 [6.5e11], 1, 1, 1
│ └─ ← [Return] 0
├─ [0] console::log("weth value in USD", 0) [staticcall]
│ └─ ← [Stop]
├─ [0] console::log("wbtc value in USD", 0) [staticcall]
│ └─ ← [Stop]
├─ [0] console::log("total supply value in USD", 1432) [staticcall]
│ └─ ← [Stop]
└─ ← [Revert] panic: assertion failed (0x01)
Suite result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 4.70ms (1.80ms CPU time)
Ran 1 test suite in 908.51ms (4.70ms CPU time): 0 tests passed, 1 failed, 0 skipped (1 total tests)
Failing tests:
Encountered 1 failing test in test/fuzz/InvariantsTest.t.sol:InvariantsTest
[FAIL: invariant_protocolMustHaveMoreValueThanTotallSupply replay failure]
[Sequence]
sender=0x00000000000000000000001961a541E15841b076 addr=[test/fuzz/Handler.t.sol:Handler]0x2e234DAe75C793f67A35089C9d99245E1C58470b calldata=depositeCollateral(uint256,uint256) args=[39560706476785038755679430821 [3.956e28], 672700926431490119484263488950076325611034650633015652263822667785311069 [6.727e71]]
sender=0x00000000000000000000001961a541E15841b076 addr=[test/fuzz/Handler.t.sol:Handler]0x2e234DAe75C793f67A35089C9d99245E1C58470b calldata=mintDsc(uint256) args=[1432]
invariant_protocolMustHaveMoreValueThanTotallSupply() (runs: 1, calls: 1, reverts: 1)
Encountered a total of 1 failing tests, 0 tests succeeded I tried looking through the trace but I have no idea why the call to depositCollateral fails. I did a forge clean, deleted the cache, did a forge build. My handler.t.sol test // SPDX-License-Identifier: MIT
// Is going to narrow down the way functions are called
pragma solidity ^0.8.24;
import {console2, Test} from "forge-std/Test.sol";
import {DSCEngine} from "src/DSCEngine.sol";
import {DecentralizedStableCoin} from "src/DecentralizedStableCoin.sol";
import {ERC20Mock} from "test/mocks/ERC20Mock.sol";
contract Handler is Test {
DecentralizedStableCoin dsc;
DSCEngine dscEngine;
ERC20Mock weth;
ERC20Mock wbtc;
uint256 MAX_DEPOSIT_SIZE = type(uint96).max; // max uint96 value
constructor(DSCEngine _dscEngine, DecentralizedStableCoin _dsc) {
dscEngine = _dscEngine;
dsc = _dsc;
address[] memory collateralTokens = dscEngine.getCollateralTokens();
weth = ERC20Mock(collateralTokens[0]);
wbtc = ERC20Mock(collateralTokens[1]);
}
function depositeCollateral(uint256 collateralSeed, uint256 amountCollateral) public {
ERC20Mock collateral = _getCollateralFromSeed(collateralSeed);
amountCollateral = bound(amountCollateral, 1, MAX_DEPOSIT_SIZE);
vm.startPrank(msg.sender);
collateral.mint(msg.sender, amountCollateral);
collateral.approve(address(dscEngine), amountCollateral);
dscEngine.depositCollateral(address(collateral), amountCollateral);
vm.stopPrank();
}
function mintDsc(uint256 amountDscToMint) public {
(uint256 totalDscMinted, uint256 collateralValueInUsd) = dscEngine.getAccountInformation(msg.sender);
int256 maxDscToMint = (int256(collateralValueInUsd) / 2) - int256(totalDscMinted);
if (maxDscToMint < 0) return;
amountDscToMint = bound(amountDscToMint, 0, uint256(maxDscToMint));
if (amountDscToMint == 0) return;
vm.startPrank(msg.sender);
dscEngine.mintDsc(amountDscToMint);
vm.stopPrank();
}
function reddeemCollateral(uint256 collateralSeed, uint256 amountCollateral) public {
ERC20Mock collateral = _getCollateralFromSeed(collateralSeed);
uint256 maxCollateralToRedeem = dscEngine.getCollateralBalanceOfUser(address(collateral), msg.sender);
amountCollateral = bound(amountCollateral, 0, maxCollateralToRedeem);
if (amountCollateral == 0) return;
dscEngine.redeemCollateral(address(collateral), amountCollateral);
}
// Helper function
function _getCollateralFromSeed(uint256 collateralSeed) private view returns (ERC20Mock) {
if (collateralSeed % 2 == 0) {
return weth;
}
return wbtc;
}
} invariantTest.t.sol // SPDX-License-Identifier: MIT
// What are our invariants
/**
* 1. The totall value of collateral should be more than the total value of DSC supply
* 2. OUR GETTER VIEW FUNCTION SHOULD NERVER REVERT
* 3. and many more that can be an invariant property
*
*/
pragma solidity ^0.8.24;
import {console2, Test} from "forge-std/Test.sol";
import {StdInvariant} from "forge-std/StdInvariant.sol";
import {DecentralizedStableCoin} from "src/DecentralizedStableCoin.sol";
import {DSCEngine} from "src/DSCEngine.sol";
import {DeployDSC} from "script/DeployDSC.s.sol";
import {HelperConfig} from "script/HelperConfig.s.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {Handler} from "./Handler.t.sol";
contract InvariantsTest is StdInvariant, Test {
DecentralizedStableCoin dsc;
DSCEngine dscEngine;
DeployDSC deployer;
HelperConfig helperConfig;
address weth;
address wbtc;
Handler handler;
function setUp() external {
deployer = new DeployDSC();
(dsc, dscEngine, helperConfig) = deployer.run();
(,, weth, wbtc,) = helperConfig.activeNetworkConfig();
handler = new Handler(dscEngine, dsc);
// The following line of code tells foundry to go wild on the specified contract
// but with respect how the handler specifies
targetContract(address(handler));
}
function invariant_protocolMustHaveMoreValueThanTotallSupply() public view {
// get the value all the collateral in the protocol
// and compare it to all the dept (dsc)
uint256 totalSupply = dsc.totalSupply();
uint256 totalWethDeposited = IERC20(weth).balanceOf(address(dsc));
uint256 totalWbtcDeposited = IERC20(wbtc).balanceOf(address(dsc));
uint256 wethValueInUsd = dscEngine.getUsdValue(weth, totalWethDeposited);
uint256 wbtcValueInUsd = dscEngine.getUsdValue(wbtc, totalWbtcDeposited);
console2.log("weth value in USD", wethValueInUsd);
console2.log("wbtc value in USD", wbtcValueInUsd);
console2.log("total supply value in USD", totalSupply);
assert((wethValueInUsd + wbtcValueInUsd) >= totalSupply);
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 11 replies
-
Hello @Totiruzi, Why is the balance of the two collateral tokens showing [63539] InvariantsTest::invariant_protocolMustHaveMoreValueThanTotallSupply()
├─ [2349] DecentralizedStableCoin::totalSupply() [staticcall]
│ └─ ← [Return] 1432
├─ [2607] ERC20Mock::balanceOf(DecentralizedStableCoin: [0x5FbDB2315678afecb367f032d93F642f64180aa3]) [staticcall]
│ └─ ← [Return] 0
├─ [2607] ERC20Mock::balanceOf(DecentralizedStableCoin: [0x5FbDB2315678afecb367f032d93F642f64180aa3]) [staticcall]
│ └─ ← [Return] 0 Even though the user clearly deposited into the ├─ [58682] DSCEngine::depositCollateral(ERC20Mock: [0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76], 1763125541979788303892091374 [1.763e27])
│ ├─ emit CollateralDeposited(user: 0x00000000000000000000001961a541E15841b076, token: ERC20Mock: [0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76], amount: 1763125541979788303892091374 [1.763e27])
│ ├─ [26088] ERC20Mock::transferFrom(0x00000000000000000000001961a541E15841b076, DSCEngine: [0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512], 1763125541979788303892091374 [1.763e27])
│ │ ├─ emit Transfer(from: 0x00000000000000000000001961a541E15841b076, to: DSCEngine: [0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512], value: 1763125541979788303892091374 [1.763e27])
│ │ └─ ← [Return] true
│ └─ ← [Stop] |
Beta Was this translation helpful? Give feedback.
-
@EngrPips stack trace forge test --mt invariant_protocolMustHaveMoreValueThanTotallSupply -vvvv
[⠊] Compiling...
[⠑] Compiling 2 files with Solc 0.8.27
[⠘] Solc 0.8.27 finished in 1.55s
Compiler run successful!
Ran 1 test for test/fuzz/InvariantsTest.t.sol:InvariantsTest
[FAIL: invariant_protocolMustHaveMoreValueThanTotallSupply replay failure]
[Sequence]
sender=0x00000000000000005DAcC8FDe4F4ED72379329C6 addr=[test/fuzz/Handler.t.sol:Handler]0x2e234DAe75C793f67A35089C9d99245E1C58470b calldata=depositeCollateral(uint256,uint256) args=[4831, 837364611 [8.373e8]]
sender=0x00000000000000005DAcC8FDe4F4ED72379329C6 addr=[test/fuzz/Handler.t.sol:Handler]0x2e234DAe75C793f67A35089C9d99245E1C58470b calldata=mintDsc(uint256) args=[514]
invariant_protocolMustHaveMoreValueThanTotallSupply() (runs: 1, calls: 1, reverts: 1)
Logs:
weth address in Handler 0xA8452Ec99ce0C64f20701dB7dD3abDb607c00496
wbtc address in Handler 0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76
Bound result 837364611
weth address in Handler 0xA8452Ec99ce0C64f20701dB7dD3abDb607c00496
wbtc address in Handler 0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76
Bound result 514
weth address in Handler 0xA8452Ec99ce0C64f20701dB7dD3abDb607c00496
wbtc address in Handler 0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76
weth value in USD 0
wbtc value in USD 0
total supply value in USD 514
weth address in Invariant 0xA8452Ec99ce0C64f20701dB7dD3abDb607c00496
wbtc address in Invariant 0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76
Time mint is called: 1
Traces:
[11633696] InvariantsTest::setUp()
├─ [4600863] → new DeployDSC@0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f
│ └─ ← [Return] 22867 bytes of code
├─ [5317937] DeployDSC::run()
│ ├─ [3341120] → new HelperConfig@0x104fBc016F4bb334D775a19E8A6510109AC63E00
│ │ ├─ [0] VM::startBroadcast()
│ │ │ └─ ← [Return]
│ │ ├─ [372255] → new MockV3Aggregator@0x90193C961A926261B756D1E5bb255e67ff9498A1
│ │ │ └─ ← [Return] 1082 bytes of code
│ │ ├─ [516505] → new ERC20Mock@0xA8452Ec99ce0C64f20701dB7dD3abDb607c00496
│ │ │ ├─ emit Transfer(from: 0x0000000000000000000000000000000000000000, to: DeployDSC: [0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f], value: 1000000000000 [1e12])
│ │ │ └─ ← [Return] 2117 bytes of code
│ │ ├─ [372255] → new MockV3Aggregator@0xBb2180ebd78ce97360503434eD37fcf4a1Df61c3
│ │ │ └─ ← [Return] 1082 bytes of code
│ │ ├─ [516505] → new ERC20Mock@0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76
│ │ │ ├─ emit Transfer(from: 0x0000000000000000000000000000000000000000, to: DeployDSC: [0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f], value: 1000000000000 [1e12])
│ │ │ └─ ← [Return] 2117 bytes of code
│ │ ├─ [0] VM::stopBroadcast()
│ │ │ └─ ← [Return]
│ │ └─ ← [Return] 6368 bytes of code
│ ├─ [934] HelperConfig::activeNetworkConfig() [staticcall]
│ │ └─ ← [Return] MockV3Aggregator: [0x90193C961A926261B756D1E5bb255e67ff9498A1], MockV3Aggregator: [0xBb2180ebd78ce97360503434eD37fcf4a1Df61c3], ERC20Mock: [0xA8452Ec99ce0C64f20701dB7dD3abDb607c00496], ERC20Mock: [0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76], 77814517325470205911140941194401928579557062014761831930645393041380819009408 [7.781e76]
│ ├─ [0] VM::startBroadcast(<pk>)
│ │ └─ ← [Return]
│ ├─ [591455] → new DecentralizedStableCoin@0x5FbDB2315678afecb367f032d93F642f64180aa3
│ │ ├─ emit OwnershipTransferred(previousOwner: 0x0000000000000000000000000000000000000000, newOwner: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266)
│ │ └─ ← [Return] 2610 bytes of code
│ ├─ [1099514] → new DSCEngine@0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
│ │ └─ ← [Return] 4814 bytes of code
│ ├─ [2424] DecentralizedStableCoin::transferOwnership(DSCEngine: [0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512])
│ │ ├─ emit OwnershipTransferred(previousOwner: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266, newOwner: DSCEngine: [0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512])
│ │ └─ ← [Stop]
│ ├─ [0] VM::stopBroadcast()
│ │ └─ ← [Return]
│ └─ ← [Return] DecentralizedStableCoin: [0x5FbDB2315678afecb367f032d93F642f64180aa3], DSCEngine: [0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512], HelperConfig: [0x104fBc016F4bb334D775a19E8A6510109AC63E00]
├─ [934] HelperConfig::activeNetworkConfig() [staticcall]
│ └─ ← [Return] MockV3Aggregator: [0x90193C961A926261B756D1E5bb255e67ff9498A1], MockV3Aggregator: [0xBb2180ebd78ce97360503434eD37fcf4a1Df61c3], ERC20Mock: [0xA8452Ec99ce0C64f20701dB7dD3abDb607c00496], ERC20Mock: [0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76], 77814517325470205911140941194401928579557062014761831930645393041380819009408 [7.781e76]
├─ [1459597] → new Handler@0x2e234DAe75C793f67A35089C9d99245E1C58470b
│ ├─ [1400] DSCEngine::getCollateralTokens() [staticcall]
│ │ └─ ← [Return] [0xA8452Ec99ce0C64f20701dB7dD3abDb607c00496, 0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76]
│ ├─ [0] console::log("weth address in Handler", ERC20Mock: [0xA8452Ec99ce0C64f20701dB7dD3abDb607c00496]) [staticcall]
│ │ └─ ← [Stop]
│ ├─ [0] console::log("wbtc address in Handler", ERC20Mock: [0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76]) [staticcall]
│ │ └─ ← [Stop]
│ └─ ← [Return] 6590 bytes of code
└─ ← [Stop]
[136583] Handler::depositeCollateral(4831, 837364611 [8.373e8])
├─ [0] console::log("Bound result", 837364611 [8.373e8]) [staticcall]
│ └─ ← [Stop]
├─ [0] console::log("weth address in Handler", ERC20Mock: [0xA8452Ec99ce0C64f20701dB7dD3abDb607c00496]) [staticcall]
│ └─ ← [Stop]
├─ [0] console::log("wbtc address in Handler", ERC20Mock: [0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76]) [staticcall]
│ └─ ← [Stop]
├─ [0] VM::startPrank(0x00000000000000005DAcC8FDe4F4ED72379329C6)
│ └─ ← [Return]
├─ [29712] ERC20Mock::mint(0x00000000000000005DAcC8FDe4F4ED72379329C6, 837364611 [8.373e8])
│ ├─ emit Transfer(from: 0x0000000000000000000000000000000000000000, to: 0x00000000000000005DAcC8FDe4F4ED72379329C6, value: 837364611 [8.373e8])
│ └─ ← [Stop]
├─ [24739] ERC20Mock::approve(DSCEngine: [0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512], 837364611 [8.373e8])
│ ├─ emit Approval(owner: 0x00000000000000005DAcC8FDe4F4ED72379329C6, spender: DSCEngine: [0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512], value: 837364611 [8.373e8])
│ └─ ← [Return] true
├─ [58682] DSCEngine::depositCollateral(ERC20Mock: [0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76], 837364611 [8.373e8])
│ ├─ emit CollateralDeposited(user: 0x00000000000000005DAcC8FDe4F4ED72379329C6, token: ERC20Mock: [0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76], amount: 837364611 [8.373e8])
│ ├─ [26088] ERC20Mock::transferFrom(0x00000000000000005DAcC8FDe4F4ED72379329C6, DSCEngine: [0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512], 837364611 [8.373e8])
│ │ ├─ emit Transfer(from: 0x00000000000000005DAcC8FDe4F4ED72379329C6, to: DSCEngine: [0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512], value: 837364611 [8.373e8])
│ │ └─ ← [Return] true
│ └─ ← [Stop]
├─ [0] VM::stopPrank()
│ └─ ← [Return]
└─ ← [Stop]
[168908] Handler::mintDsc(514)
├─ [43718] DSCEngine::getAccountInformation(0x00000000000000005DAcC8FDe4F4ED72379329C6) [staticcall]
│ ├─ [8993] MockV3Aggregator::latestRoundData() [staticcall]
│ │ └─ ← [Return] 1, 250000000000 [2.5e11], 1, 1, 1
│ ├─ [8993] MockV3Aggregator::latestRoundData() [staticcall]
│ │ └─ ← [Return] 1, 650000000000 [6.5e11], 1, 1, 1
│ └─ ← [Return] 0, 5442869971500 [5.442e12]
├─ [0] console::log("Bound result", 514) [staticcall]
│ └─ ← [Stop]
├─ [0] VM::startPrank(0x00000000000000005DAcC8FDe4F4ED72379329C6)
│ └─ ← [Return]
├─ [84569] DSCEngine::mintDsc(514)
│ ├─ [993] MockV3Aggregator::latestRoundData() [staticcall]
│ │ └─ ← [Return] 1, 250000000000 [2.5e11], 1, 1, 1
│ ├─ [993] MockV3Aggregator::latestRoundData() [staticcall]
│ │ └─ ← [Return] 1, 650000000000 [6.5e11], 1, 1, 1
│ ├─ [49149] DecentralizedStableCoin::mint(0x00000000000000005DAcC8FDe4F4ED72379329C6, 514)
│ │ ├─ emit Transfer(from: 0x0000000000000000000000000000000000000000, to: 0x00000000000000005DAcC8FDe4F4ED72379329C6, value: 514)
│ │ └─ ← [Return] true
│ └─ ← [Stop]
├─ [0] VM::stopPrank()
│ └─ ← [Return]
├─ [0] console::log("weth address in Handler", ERC20Mock: [0xA8452Ec99ce0C64f20701dB7dD3abDb607c00496]) [staticcall]
│ └─ ← [Stop]
├─ [0] console::log("wbtc address in Handler", ERC20Mock: [0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76]) [staticcall]
│ └─ ← [Stop]
└─ ← [Stop]
[73305] InvariantsTest::invariant_protocolMustHaveMoreValueThanTotallSupply()
├─ [2349] DecentralizedStableCoin::totalSupply() [staticcall]
│ └─ ← [Return] 514
├─ [2607] ERC20Mock::balanceOf(DecentralizedStableCoin: [0x5FbDB2315678afecb367f032d93F642f64180aa3]) [staticcall]
│ └─ ← [Return] 0
├─ [2607] ERC20Mock::balanceOf(DecentralizedStableCoin: [0x5FbDB2315678afecb367f032d93F642f64180aa3]) [staticcall]
│ └─ ← [Return] 0
├─ [15003] DSCEngine::getUsdValue(ERC20Mock: [0xA8452Ec99ce0C64f20701dB7dD3abDb607c00496], 0) [staticcall]
│ ├─ [8993] MockV3Aggregator::latestRoundData() [staticcall]
│ │ └─ ← [Return] 1, 250000000000 [2.5e11], 1, 1, 1
│ └─ ← [Return] 0
├─ [15003] DSCEngine::getUsdValue(ERC20Mock: [0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76], 0) [staticcall]
│ ├─ [8993] MockV3Aggregator::latestRoundData() [staticcall]
│ │ └─ ← [Return] 1, 650000000000 [6.5e11], 1, 1, 1
│ └─ ← [Return] 0
├─ [0] console::log("weth value in USD", 0) [staticcall]
│ └─ ← [Stop]
├─ [0] console::log("wbtc value in USD", 0) [staticcall]
│ └─ ← [Stop]
├─ [0] console::log("total supply value in USD", 514) [staticcall]
│ └─ ← [Stop]
├─ [0] console::log("weth address in Invariant", ERC20Mock: [0xA8452Ec99ce0C64f20701dB7dD3abDb607c00496]) [staticcall]
│ └─ ← [Stop]
├─ [0] console::log("wbtc address in Invariant", ERC20Mock: [0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76]) [staticcall]
│ └─ ← [Stop]
├─ [2361] Handler::timeMintIscalled() [staticcall]
│ └─ ← [Return] 1
├─ [0] console::log("Time mint is called: ", 1) [staticcall]
│ └─ ← [Stop]
└─ ← [Revert] panic: assertion failed (0x01)
Suite result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 9.50ms (1.41ms CPU time)
Ran 1 test suite in 9.73s (9.50ms CPU time): 0 tests passed, 1 failed, 0 skipped (1 total tests)
Failing tests:
Encountered 1 failing test in test/fuzz/InvariantsTest.t.sol:InvariantsTest
[FAIL: invariant_protocolMustHaveMoreValueThanTotallSupply replay failure]
[Sequence]
sender=0x00000000000000005DAcC8FDe4F4ED72379329C6 addr=[test/fuzz/Handler.t.sol:Handler]0x2e234DAe75C793f67A35089C9d99245E1C58470b calldata=depositeCollateral(uint256,uint256) args=[4831, 837364611 [8.373e8]]
sender=0x00000000000000005DAcC8FDe4F4ED72379329C6 addr=[test/fuzz/Handler.t.sol:Handler]0x2e234DAe75C793f67A35089C9d99245E1C58470b calldata=mintDsc(uint256) args=[514]
invariant_protocolMustHaveMoreValueThanTotallSupply() (runs: 1, calls: 1, reverts: 1)
Encountered a total of 1 failing tests, 0 tests succeeded |
Beta Was this translation helpful? Give feedback.
Hello @Totiruzi, In the below line of code you should be getting the balance of
DSCE
and notdsc