Replies: 6 comments 14 replies
-
Hello @NickyBenz, Can you please check that |
Beta Was this translation helpful? Give feedback.
-
Mind adding your main test also? |
Beta Was this translation helpful? Give feedback.
-
From the output you shared, I noticed that the address that was used when the fuzzer called │ ├─ [641] DSCEngine::getTokenAddresses(0) [staticcall]
│ │ └─ ← [Return] 0xA8452Ec99ce0C64f20701dB7dD3abDb607c00496 <= first token address
│ ├─ [641] DSCEngine::getTokenAddresses(1) [staticcall]
│ │ └─ ← [Return] 0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76 <= second token address
[214] Handler::depositCollateral(0x6675c9C78c7a6D335b85f23992cf7e07a7B38cD4, 1967808702692547613377325 [1.967e24])
└─ ← [Revert] EvmError: Revert
Can you carefully check your test suite and ensure you didn't wrongly assign values to variables? |
Beta Was this translation helpful? Give feedback.
-
Handler Contract contract Handler is Test {
DSCEngine dsc_engine;
DecentralizedStableCoin dsc;
HelperConfig config;
address weth;
address wbtc;
uint256 constant MAX_DEPOSIT_NUMBER = type(uint96).max;
address user = makeAddr("user");
constructor(DSCEngine _dsc_engine, DecentralizedStableCoin _dsc, HelperConfig _config) {
dsc = _dsc;
dsc_engine = _dsc_engine;
config = _config;
(,, weth, wbtc,) = config.activeConfig();
}
//redeem collateral
//call when u have collateral
function depositCollateral(uint256 collateral_seed, uint256 amount_collateral) public {
(ERC20Mock collateraltoken) = _getCollateralfromSeed(collateral_seed);
vm.startPrank(user);
collateraltoken.mint(user, amount_collateral);
amount_collateral = bound(amount_collateral, 1, MAX_DEPOSIT_NUMBER);
dsc_engine.depositCollateral(address(collateraltoken), amount_collateral);
vm.stopPrank();
}
function _getCollateralfromSeed(uint256 collateral_seed) private view returns (ERC20Mock) {
ERC20Mock token_to_deposit;
if (collateral_seed % 2 == 0) {
token_to_deposit = ERC20Mock(weth);
} else {
token_to_deposit = ERC20Mock(wbtc);
}
return (token_to_deposit);
}
} |
Beta Was this translation helpful? Give feedback.
-
Not an answer but facing a smiliar issue wherein my Handler is not working. //Handler is going to narrow down the ways that we call functions so that we don't waste runs
// SPDX-License-Identifier:MIT
pragma solidity ^0.8.23;
import {Test , console} from "forge-std/Test.sol";
import {StdInvariant} from "forge-std/StdInvariant.sol";
import {DeployScript} from "../../script/DeployDSC.s.sol";
import {DSCEngine} from "../../src/DSCEngine.sol";
import {DecentralizedStableCoin} from "../../src/DecentralizedStableCoin.sol";
import {HelperConfig} from "../../script/HelperConfig.s.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {ERC20Mock} from "@openzeppelin/contracts/mocks/token/ERC20Mock.sol";
contract Handler is Test{
DSCEngine dsc_engine;
DecentralizedStableCoin dsc;
HelperConfig config;
address weth;
address wbtc;
uint256 constant MAX_DEPOSIT_NUMBER = type(uint96).max;
address user = makeAddr("user");
constructor(DSCEngine _dsc_engine, DecentralizedStableCoin _dsc, HelperConfig _config) {
dsc = _dsc;
dsc_engine = _dsc_engine;
config = _config;
(,, weth, wbtc,) = config.activeConfig();
}
//redeem collateral
//call when u have collateral
function depositCollateral(uint256 collateral_seed, uint256 amount_collateral) public {
(ERC20Mock collateraltoken) = _getCollateralfromSeed(collateral_seed);
vm.startPrank(user);
collateraltoken.mint(user, amount_collateral);
amount_collateral = bound(amount_collateral, 1, MAX_DEPOSIT_NUMBER);
dsc_engine.depositCollateral(address(collateraltoken), amount_collateral);
vm.stopPrank();
}
function _getCollateralfromSeed(uint256 collateralSeed) private view returns(ERC20Mock){
ERC20Mock token_to_deposit;
if(collateralSeed % 2 ==0){
token_to_deposit = ERC20Mock(weth);
} else {
token_to_deposit = ERC20Mock(wbtc);
}
return token_to_deposit;
}
} Here is my Invariant test: //This file should have our invariants... aka properties of the system that should always hold
/**
* Some invariants in our project:
* 1. The total supply of DSC should be lesser than total value of collateral
* 2. Getter view functions should never revert
*/
// SPDX-License-Identifier:MIT
pragma solidity ^0.8.23;
import {Test } from "forge-std/Test.sol";
import {StdInvariant} from "forge-std/StdInvariant.sol";
import {DeployScript} from "../../script/DeployDSC.s.sol";
import {DSCEngine} from "../../src/DSCEngine.sol";
import {DecentralizedStableCoin} from "../../src/DecentralizedStableCoin.sol";
import {HelperConfig} from "../../script/HelperConfig.s.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {Handler} from "./Handler.t.sol";
contract Invariants is StdInvariant , Test{
DSCEngine dsce;
DecentralizedStableCoin dsc;
HelperConfig config;
Handler handler;
address weth;
address wbtc;
function setUp() public {
DeployScript deployer = new DeployScript();
(dsc , dsce , config ) = deployer.run();
handler = new Handler(dsce, dsc , config);
targetContract(address(handler)); //Tells foundry to go absolutely wild on this
( , , weth , wbtc , ) = config.activeConfig();
}
function invariant_protocolMustHaveMoreValueThanTotalSupply() external view {
//get the value of all the collateral in the protocol
// compare it to the total DSC supply
uint256 totalSupply = dsc.totalSupply();
uint256 totalWethDeposited = IERC20(weth).balanceOf(address(dsce));
uint256 totalWbtcDeposited = IERC20(wbtc).balanceOf(address(dsce));
uint256 wethValue = dsce.getUSDAmount(weth , totalWethDeposited);
uint256 wbtcValue = dsce.getUSDAmount(wbtc , totalWbtcDeposited);
assert((wethValue + wbtcValue) >= (totalSupply));
}
} And lastly, this is my error's log:
It says ERC20InsufficientAllowance so I don't know what's going on. I am following from the yt vids and don't know what's wrong. A little help would be appreciated |
Beta Was this translation helpful? Give feedback.
-
Hello @NickyBenz, tough to catch what is wrong here, but can you make your address[] memory collateral_tokens = dsc_engine.get_collateral_tokens();
weth = ERC20Mock(collateral_tokens[0]);
wbtc = ERC20Mock(collateral_tokens[1]); |
Beta Was this translation helpful? Give feedback.
-
Hi, I've been following the code for the handler function which is on lesson 20 in the Cyfrin course,
Here is my code
`contract Handler is Test {
DSCEngine dsc_engine;
DecentralizedStableCoin dsc;
HelperConfig config;
address weth;
address wbtc;
uint256 constant MAX_DEPOSIT_NUMBER = type(uint96).max;
address user = makeAddr("user");
}
`
When I run this code and put the -vvvv thing it tells me that I have this error
'[192] Handler::depositCollateral(0x6675c9C78c7a6D335b85f23992cf7e07a7B38cD4, 1967808702692547613377325 [1.967e24])
└─ ← [Revert] EvmError: Revert'
I am unsure as to what is causing this error, the only thing that this seems to tell me is that it occurs in the 'deposit collateral' function of my handler. Can someone please help me understand where this error is?
Thank you very much in advance
Beta Was this translation helpful? Give feedback.
All reactions