Cyfrin / foundry-defi-stablecoin-cu

250 stars 117 forks source link

ERC20Mock File Issue. #28

Closed Ritik-Agarwal50 closed 1 year ago

Ritik-Agarwal50 commented 1 year ago

I am facing this issue while running this Command -

 forge test --match-test testGetusdValue

Error Statements -

The wrong argument count for function call: 4 arguments given but expected 0.
  --> script/HelperConfig.s.sol:55:30:
   |
55 |         ERC20Mock wethMock = new ERC20Mock("WETH", "WETH", msg.sender, 1000e8);
   |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Error (6160): Wrong argument count for function call: 4 arguments given but expected 0.
  --> script/HelperConfig.s.sol:62:30:
   |
62 |         ERC20Mock wbtcMock = new ERC20Mock("WBTC", "WBTC", msg.sender, 1000e8);

This Error says I have passed extra arguments but it expect 0 arguments.

CODE -


pragma solidity ^0.8.18;

import {Script} from "forge-std/Script.sol";
import {MockV3Aggregator} from "../test/mocks/MockV3Aggregator.sol";
//import {ERC20Mock} from "@openzeppelin/contracts/mocks/ERC20Mock.sol";
import {ERC20Mock} from "@openzeppelin/contracts/mocks/ERC20Mock.sol";

contract HelperConfig is Script {
    struct NetworkConfig {
        address wethUsdPriceFeed;
        address wbtcUsdPriceFeed;
        address weth;
        address wbtc;
        uint256 deployerKey;
    }
    uint256 private constant DEFAULT_ANVIL_KEY =
        0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80;
    uint8 public constant DECIMALS = 8;
    int256 public constant ETH_USD_PRICE = 2000e8;
    int256 public constant BTC_USD_PRICE = 1000e8;

    NetworkConfig public activeNetwrokConfig;

    constructor() {
        if (block.chainid == 11155111) {
            activeNetwrokConfig = getSepholiaEthConfig();
        } else {
            activeNetwrokConfig = getOrCreateAnvilEthConfig();
        }
    }

    function getSepholiaEthConfig() public view returns (NetworkConfig memory) {
        return
            NetworkConfig({
                wethUsdPriceFeed: 0x694AA1769357215DE4FAC081bf1f309aDC325306, // ETH / USD
                wbtcUsdPriceFeed: 0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43,
                weth: 0xdd13E55209Fd76AfE204dBda4007C227904f0a81,
                wbtc: 0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063,
                deployerKey: vm.envUint("PRIVATE_KEY")
            });
    }

    function getOrCreateAnvilEthConfig() public returns (NetworkConfig memory) {
        if (activeNetwrokConfig.wethUsdPriceFeed != address(0)) {
            return activeNetwrokConfig;
        }
        vm.startBroadcast();
        MockV3Aggregator ethUsdPriceFeed = new MockV3Aggregator(
            DECIMALS,
            ETH_USD_PRICE
        );

        ERC20Mock wethMock = new ERC20Mock("WETH", "WETH", msg.sender, 1000e8);

        MockV3Aggregator btcUsdPriceFeed = new MockV3Aggregator(
            DECIMALS,
            BTC_USD_PRICE
        );

        ERC20Mock wbtcMock = new ERC20Mock("WBTC", "WBTC", msg.sender, 1000e8);
        vm.stopBroadcast();

        return
            NetworkConfig({
                wethUsdPriceFeed: address(ethUsdPriceFeed),
                wbtcUsdPriceFeed: address(btcUsdPriceFeed),
                weth: address(wethMock),
                wbtc: address(wbtcMock),
                deployerKey: DEFAULT_ANVIL_KEY
            });
    }
}

Library Which I installed for Openzeppelin

forge install OpenZeppelin/openzeppelin-contracts --no-commit

This is how my ERC20Mock.sol File looks-

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {ERC20} from "../token/ERC20/ERC20.sol";

contract ERC20Mock is ERC20 {
    constructor() ERC20("ERC20Mock", "E20M") {}

    function mint(address account, uint256 amount) external {
        _mint(account, amount);
    }

    function burn(address account, uint256 amount) external {
        _burn(account, amount);
    }
}

For More Code Info Check Out - https://github.com/Ritik-Agarwal50/StableCoin

Rahul-Prasad-07 commented 1 year ago

They "https://github.com/openzeppelin/openzeppelin-contracts" come up with new releases @V4.9.2 .

Rahul-Prasad-07 commented 1 year ago

You can find the solutions in updated README.md and this is that PR #19 https://github.com/Cyfrin/foundry-defi-stablecoin-f23#updates

Ritik-Agarwal50 commented 1 year ago

Thanks Mate.