PatrickAlphaC / hardhat-fund-me-fcc

82 stars 184 forks source link

Error when testing fund(). Error: Invalid Chai property: revertedWith #169

Closed nicolasraus closed 1 year ago

nicolasraus commented 1 year ago

Hi! When trying to test the fund function from the fundMe contract I get the following error:

  1) FundMe
       fund
         fails if you don't send enough ETH:
     Error: Invalid Chai property: revertedWith
      at Object.proxyGetter [as get] (node_modules/chai/lib/chai/utils/proxify.js:78:17)
      at Context.<anonymous> (test/unit/FundMe.test.js:24:46)

error Command failed with exit code 1.

After some googling I read that now it's recommended to use require("@nomicfoundation/hardhat-chai-matchers") instead of require("@nomiclabs/hardhat-waffle") But if I do that I get an error saying that ether doesn't have a function "getContract()"

this is my package.json

{
  "devDependencies": {
    "@chainlink/contracts": "^0.6.1",
    "@ethersproject/abi": "^5.4.7",
    "@ethersproject/providers": "^5.4.7",
    "@nomicfoundation/hardhat-chai-matchers": "^2.0.1",
    "@nomicfoundation/hardhat-ethers": "^3.0.2",
    "@nomicfoundation/hardhat-network-helpers": "^1.0.0",
    "@nomicfoundation/hardhat-toolbox": "2.0.2",
    "@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers",
    "@nomiclabs/hardhat-etherscan": "^3.0.0",
    "@nomiclabs/hardhat-waffle": "^2.0.6",
    "@typechain/ethers-v5": "^10.1.0",
    "@typechain/hardhat": "^6.1.2",
    "chai": "^4.3.7",
    "dotenv": "^16.3.1",
    "ethers": "^6.6.2",
    "hardhat": "^2.16.1",
    "hardhat-deploy": "^0.11.34",
    "hardhat-gas-reporter": "^1.0.8",
    "hardhat-waffle": "^0.0.1-security",
    "solhint": "^3.4.1",
    "solidity-coverage": "^0.8.0",
    "typechain": "^8.1.0"
  }
}

and this my hardhat.config.js

require("@nomiclabs/hardhat-waffle")
require("hardhat-gas-reporter")
require("@nomiclabs/hardhat-etherscan")
require("dotenv").config()
require("solidity-coverage")
require("hardhat-deploy")

const COINMARKETCAP_API_KEY = process.env.COINMARKETCAP_API_KEY || ""
const SEPOLIA_RPC_URL =
    process.env.SEPOLIA_RPC_URL ||
    "https://eth-sepolia.g.alchemy.com/v2/YOUR-API-KEY"
const PRIVATE_KEY =
    process.env.PRIVATE_KEY ||
    "0x11ee3108a03081fe260ecdc106554d09d9d1209bcafd46942b10e02943effc4a"
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY || ""

module.exports = {
    defaultNetwork: "hardhat",
    networks: {
        hardhat: {
            chainId: 31337,
            // gasPrice: 130000000000,
        },
        sepolia: {
            url: SEPOLIA_RPC_URL,
            accounts: [PRIVATE_KEY],
            chainId: 11155111,
            blockConfirmations: 6,
        },
    },
    solidity: {
        compilers: [
            {
                version: "0.8.8",
            },
            {
                version: "0.6.6",
            },
        ],
    },
    etherscan: {
        apiKey: ETHERSCAN_API_KEY,
        // customChains: [], // uncomment this line if you are getting a TypeError: customChains is not iterable
    },
    gasReporter: {
        enabled: false,
        currency: "USD",
        outputFile: "gas-report.txt",
        noColors: true,
        coinmarketcap: COINMARKETCAP_API_KEY,
    },
    namedAccounts: {
        deployer: {
            default: 0, // here this will by default take the first account as deployer
            1: 0, // similarly on mainnet it will take the first account as deployer. Note though that depending on how hardhat network are configured, the account 0 on one network can be different than on another
        },
    },
    mocha: {
        timeout: 500000,
    },
}
PatrickAlphaC commented 1 year ago

hmm... Can you try cloning the repo and seeing if you get the same error?

nicolasraus commented 1 year ago

Yes! that worked!! probably some dependency version? Thanks a lot :)