PatrickAlphaC / hardhat-fund-me-fcc

82 stars 184 forks source link

Error with the Aggregator #173

Open Tuafo opened 1 year ago

Tuafo commented 1 year ago
const { deployments, ethers, getNamedAccounts } = require("hardhat")
const { assert, expect } = require("chai")
const { developmentChains } = require("../../helper-hardhat-config")

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

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

this is my code and it's not working, this is the following error when i run 'yarn hardhat test':

Compiled 1 Solidity file successfully

  FundMe
    constructor
      1) sets the aggregator addresses correctly

  0 passing (1s)
  1 failing

  1) FundMe
       constructor
         sets the aggregator addresses correctly:
     TypeError: no matching function (argument="key", value="getPriceFeed", code=INVALID_ARGUMENT, version=6.6.4)
      at makeError (node_modules/ethers/src.ts/utils/errors.ts:670:21)
      at assert (node_modules/ethers/src.ts/utils/errors.ts:694:25)
      at assertArgument (node_modules/ethers/src.ts/utils/errors.ts:706:5)
      at Interface.getFunctionName (node_modules/ethers/src.ts/abi/interface.ts:542:23)
      at buildWrappedMethod (node_modules/ethers/src.ts/contract/contract.ts:334:34)
      at Contract.getFunction (node_modules/ethers/src.ts/contract/contract.ts:859:22)
      at Object.get (node_modules/ethers/src.ts/contract/contract.ts:757:39)
      at Context.<anonymous> (test/unit/FundMe.test.js:23:43)

error Command failed with exit code 1.

it was supossed to work, since i already have check every line of code and it's the same from the tutorial. the video link in the part of the code i'm in https://youtu.be/gyMwXuJrbJQ?t=40700

Tuafo commented 1 year ago

Here is the guide for solving the specific problem i've encountering.

Instructions:

Step 1: Update hardhat.config.js

Navigate to the GitHub repository at https://github.com/PatrickAlphaC/hardhat-fund-me-fcc/blob/main. Find the hardhat.config.js file, copy its requires, and then replace the corresponding sections in your local hardhat.config.js file.

Replace the content of your local hardhat.config.js with the content from the repository

Step 2: Update package.json

In the same GitHub repository, locate the package.json file, copy its contents, and replace the content in your local package.json file.

Replace the content of your local package.json with the content from the repository

Step 3: Delete node_modules and Reinstall Dependencies

After updating your configuration and package files, you should delete your local node_modules directory to remove potentially conflicting dependencies.

Then, in your terminal, run the following command to reinstall all your dependencies:

Reinstall all dependencies

npm i --force

The problem i've been experiencing appears to be related to dependency conflicts. Following these steps should help resolve the issue.

Remember to follow all the instructions in the specified order. If you encounter any problems, please don't hesitate to ask for assistance.

Tuafo commented 1 year ago

I'll let this issue open in case someone need him

the-first-elder commented 1 year ago

Hello i noticd using .target dets the address of the contract, while .address gets the adrress where the code is been deployed. You can try the following below

describe("constructor", async function () {
        it("sets the aggregator addresses correctly", async () => {
            const response = await fundMe.priceFeed()
            assert.equal(response, mockV3Aggregator.target)
        })
    }) 
stDean commented 1 year ago

Hello, this is the code i used in solving the issue

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

describe("Fund Me Contract Test", async () => {
  let fundMe
  let mockV3Aggregator

  beforeEach(async () => {
    // deploy all contracts
    await deployments.fixture(["all"])
    fundMe = await deployments.get("FundMe")
    mockV3Aggregator = await deployments.get("MockV3Aggregator")
    fundMe = await ethers.getContractAt(fundMe.abi, fundMe.address)
    mockV3Aggregator = await ethers.getContractAt(
      mockV3Aggregator.abi,
      mockV3Aggregator.address
    )
  })

  describe("constructor", async () => {
    it("should set aggregator addresses correctly", async () => {
      const response = await fundMe.priceFeed()
      assert.equal(response, mockV3Aggregator.target)
    })
  })
})