Cyfrin / foundry-defi-stablecoin-cu

249 stars 117 forks source link

[FAIL. Reason: Setup failed: 1e4fbdf7:] #54

Closed Bogomil-Simitchiev closed 10 months ago

Bogomil-Simitchiev commented 10 months ago

when i try forge test this shows up -> Failing tests: Encountered 1 failing test in test/unit/DSCEngineTest.t.sol:DSCEngineTest [FAIL. Reason: Setup failed: 1e4fbdf7:] setUp() (gas: 0)

Bogomil-Simitchiev commented 10 months ago

This is the code ->

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.19;

import {Test} from "../../lib/forge-std/src/Test.sol"; import {DeployDSC} from "../../script/DeployDSC.s.sol"; import {DecentralizedStableCoin} from "../../src/DecentralizedStableCoin.sol"; import {DSCEngine} from "../../src/DSCEngine.sol"; import {HelperConfig} from "../../script/HelperConfig.s.sol"; import {ERC20Mock} from "../../lib/openzeppelin-contracts/contracts/mocks/token/ERC20Mock.sol";

contract DSCEngineTest is Test { DeployDSC deployer;

DecentralizedStableCoin dsc;
DSCEngine dsce;
HelperConfig config;

address ethUsdPriceFeed;
address weth;

address public USER = makeAddr("user");
uint256 public constant AMOUNT_COLLATERAL = 10 ether;
uint256 public constant STARTING_BALANCE = 10 ether;

function setUp() external {
    deployer = new DeployDSC();
    (dsc, dsce, config) = deployer.run();
    (ethUsdPriceFeed, , weth, , ) = config.activeNetworkConfig();

    ERC20Mock(weth).mint(USER, STARTING_BALANCE);
}

//////////////////
// Price Tests //
//////////////////
function testGetUsdValue() public {
    uint256 ethAmount = 15e18;
    // 15e18 * 2000/Eth = 30,3000e18
    uint256 expectedUsd = 30000e18;
    uint256 actualUsd = dsce.getUsdValue(weth, ethAmount);
    assertEq(expectedUsd, actualUsd);
}

///////////////////////////////////////
// depositCollateral Tests //
///////////////////////////////////////

function testRevertsIfCollateralZero() public {
    vm.startPrank(USER);
    ERC20Mock(weth).approve(address(dsce), AMOUNT_COLLATERAL);

    vm.expectRevert(DSCEngine.DSCEngine__NeedsMoreThanZero.selector);
    dsce.depositCollateral(weth,0);
    vm.stopPrank();
}

}

khadni commented 10 months ago

Hi @Bogomil-Simitchiev

It seems your tests aren't running because the setup itself is failing. A good starting point is to run forge test -vvvvv in your terminal. This command provides more detailed output, which can be crucial for pinpointing the exact issue.

One potential cause might relate to the version of the OpenZeppelin library you're using. I observed from your ERC20Mock import path that you could be using a different version than what was used in Patrick's tutorial (he used v4.8.3). Pls refer to Chronological updates - Lesson 12.

Bogomil-Simitchiev commented 10 months ago

Thank you! I installed version 4.8.3 and it worked