PatrickAlphaC / hardhat-fund-me-fcc

82 stars 182 forks source link

LESSON 7 - UNIT TESTING -TESTING FUND ME LOT OF ERRORS #170

Closed Maximesol closed 1 year ago

Maximesol commented 1 year ago

Could someone update the FundMe.test.js files and the rest because I see a lot of error. I myself have been blocked for many hours. I see several dependencies and version compatibility errors that make errors like these:

Someone kind please update the files for this part please. The original code that is no longer relevant was this:

const { assert } = require("chai")
const { deployments, ethers, getNamedAccounts } = require("hardhat")

describe("FundMe", async function() {
    let fundMe
    let deployer
    let mockV3Aggregator
    beforeEach(async function() {
        // deploy FundMe contract using hardhat deploy
        // const accounts = await ethers.getSigners()
        // const accountZero = accounts[0]
        deployer = (await getNamedAccounts()).deployer
        await deployments.fixture(["all"])
        fundMe = await ethers.getContract("FundMe", deployer)
        mockV3Aggregator = await ethers.getContract(
            "MockV3Aggregator",
            deployer
        )
    })

    describe("constructor", async function() {
        it("Sets the aggregator addresses correctly", async function() {
            const response = await fundMe.priceFeed()
            assert.equal(response, mockV3Aggregator.address)
        })
    })
})

Thanks fam !

Maximesol commented 1 year ago

PROBLEM SOLVED ?

Ok so I maybe fixed the problem, not in a very nice way but I couldn't find a better one. I think there are dependency conflicts because the course is dated and new versions have appeared. I proceeded like this, I copied and pasted the package.json available on the repo associated with the course:

{
  "name": "hardhat-fund-me-fcc",
  "devDependencies": {
    "@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers@^0.3.0-beta.13",
    "@nomiclabs/hardhat-etherscan": "^3.0.0",
    "@nomiclabs/hardhat-waffle": "^2.0.2",
    "chai": "^4.3.4",
    "ethereum-waffle": "^3.4.0",
    "ethers": "^5.5.3",
    "hardhat": "^2.8.3",
    "hardhat-deploy": "^0.9.29",
    "hardhat-gas-reporter": "^1.0.7",
    "solidity-coverage": "^0.7.18",
    "@chainlink/contracts": "^0.3.1",
    "dotenv": "^14.2.0",
    "prettier-plugin-solidity": "^1.0.0-beta.19",
    "solhint": "^3.3.7"
  },

I then deleted node_module, artifact, cache and yarn.lock from my working folder

Then I did a :

yarn install --force 

in the terminal of my environment to remove the packages already installed and reinstall the dependencies corresponding to the package.json file

Not sure if this is a perfect way but in any case it works for me. I'm a beginner so I couldn't analyze which dependency conflicts with another but this solution will surely help

If someone with experience could give their opinion that would be great, thank you!

PatrickAlphaC commented 1 year ago

this is great!

Yes, packages get outdated pretty quickly in the JS world. So this is a good option to make sure stuff works the same as in the video.

tzuhsuan0o0 commented 12 months ago

use await mockV3Aggregator.getAddress() instead of mockV3Aggregator.address

ghost commented 11 months ago

@tzuhsuanchangX thanks, it worked without doing much things with new dependencies !