PatrickAlphaC / hardhat-fund-me-fcc

82 stars 183 forks source link

No Contract deployed with Name "FundMe" #44

Closed Nikhil8847 closed 2 years ago

Nikhil8847 commented 2 years ago

while creating unit test for FundMe Contract, I have got this error.

Error: No Contract deployed with name FundMe

The testing code is below

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

describe("FundMe", async function() {
    let fundMe
    let deployer
    let mockV3Aggregator
    beforeEach(async function() {
        // const { accounts } = await ethers.getSigners()
        // const accountsZero = accounts[0]
        deployer = (await getNamedAccounts()).deployer
        deployments.fixture(["all"])
        fundMe = await ethers.getContract("FundMe", deployer)
        mockV3Aggregator = await ethers.getContract(
            "MockV3Aggregator",
            deployer
        )
    })
    describe("constructor", async function() {
        it("Sets the Aggregator address correctly", async function() {
            const response = await fundMe.priceFeed()
            assert.equal(response, mockV3Aggregator.address)
        })
    })
})

I have checked the deployments folder and it too show the deployments have been made: Screenshot from 2022-07-23 16-52-26 The full error is as follows:

  FundMe
    constructor

      1) "before each" hook for "Sets the Aggregator address correctly"

  0 passing (1s)
  1 failing

  1) FundMe
       "before each" hook for "Sets the Aggregator address correctly":
     Error: No Contract deployed with name FundMe
      at Object.getContract (node_modules/@nomiclabs/hardhat-ethers/src/internal/helpers.ts:447:11)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at Context.<anonymous> (test/unit/FundMe.test.js:13:18)

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I have tried redeploying using yarn hardhat deploy and deploy happens without any error, but test still doesn't detect the deployments. I have tried other hit and trials methods too, but no luck. Does anyone know some troublsheeoting tips.

Nikhil8847 commented 2 years ago

Ok, I got it fixture is async function, but I forgot to put await.