0

I am getting the following error while trying to test a FundMe contract.

I am following:

Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course by Patrick Collins on FreeCodeCamp YT channel

I got this error while I was at 11:18:00 on the above course. I tried almost everything but nothing helped I found where the problem was.

Question: Where do I find the problem in the test file?

For me, I don't know how to fix it because the error is almost the same question I had when deploying, and I just add a few codes in the hardhat.config.js file. But in the testing, I had the same problem but it doesn't work.

namedAccounts: {
    deployer: {
        default: 0, // here this will by default take the first account as deployer
    },
},

For my FundMe.test.js

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

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.getPriceFeed()
            assert.equal(response, mockV3Aggregator.address)
        })
    })
})

Here is the error:

  FundMe
    constructor

      1) "before each" hook for "sets the aggregator addresses correctly"


  0 passing (1s)
  1 failing

  1) FundMe
       "before each" hook for "sets the aggregator addresses correctly":
   
   ERROR processing /Users/namnguyen/Workspace/blockchain/smart-contract-programming/hardhat-fund-me/deploy/01-deploy-fund-me.js:
TypeError: Cannot read property 'length' of undefined
    at getFrom (/Users/namnguyen/Workspace/blockchain/smart-contract-programming/hardhat-fund-me/node_modules/hardhat-deploy/src/helpers.ts:1713:14)
    at fetchIfDifferent (/Users/namnguyen/Workspace/blockchain/smart-contract-programming/hardhat-fund-me/node_modules/hardhat-deploy/src/helpers.ts:939:38)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at runNextTicks (internal/process/task_queues.js:64:3)
    at listOnTimeout (internal/timers.js:526:9)
    at processTimers (internal/timers.js:500:7)
    at _deployOne (/Users/namnguyen/Workspace/blockchain/smart-contract-programming/hardhat-fund-me/node_modules/hardhat-deploy/src/helpers.ts:1002:24)
    at Object.module.exports [as func] (/Users/namnguyen/Workspace/blockchain/smart-contract-programming/hardhat-fund-me/deploy/01-deploy-fund-me.js:13:34)
    at DeploymentsManager.executeDeployScripts (/Users/namnguyen/Workspace/blockchain/smart-contract-programming/hardhat-fund-me/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1219:22)
    at DeploymentsManager.runDeploy (/Users/namnguyen/Workspace/blockchain/smart-contract-programming/hardhat-fund-me/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
  Error: ERROR processing /Users/namnguyen/Workspace/blockchain/smart-contract-programming/hardhat-fund-me/deploy/01-deploy-fund-me.js:
  TypeError: Cannot read property 'length' of undefined
      at getFrom (node_modules/hardhat-deploy/src/helpers.ts:1713:14)
      at fetchIfDifferent (node_modules/hardhat-deploy/src/helpers.ts:939:38)
      at processTicksAndRejections (internal/process/task_queues.js:95:5)
      at runNextTicks (internal/process/task_queues.js:64:3)
      at listOnTimeout (internal/timers.js:526:9)
      at processTimers (internal/timers.js:500:7)
      at _deployOne (node_modules/hardhat-deploy/src/helpers.ts:1002:24)
      at Object.module.exports [as func] (deploy/01-deploy-fund-me.js:13:34)
      at DeploymentsManager.executeDeployScripts (node_modules/hardhat-deploy/src/DeploymentsManager.ts:1219:22)
      at DeploymentsManager.runDeploy (node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
      at DeploymentsManager.executeDeployScripts (node_modules/hardhat-deploy/src/DeploymentsManager.ts:1222:19)
      at processTicksAndRejections (internal/process/task_queues.js:95:5)
      at runNextTicks (internal/process/task_queues.js:64:3)
      at listOnTimeout (internal/timers.js:526:9)
      at processTimers (internal/timers.js:500:7)
      at DeploymentsManager.runDeploy (node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
      at Object.fixture (node_modules/hardhat-deploy/src/DeploymentsManager.ts:315:9)
      at Context.<anonymous> (test/unit/FundMe.test.js:12:9)

Thanks for your help!

1 Answer 1

0

Usually, this is because the config of namedAccount is missing in the file hardhat.config.js. The config tells the plugin hardhat-deploy which account it should use to deploy contracts.

Check the hardhat.config.js, and add the snippet codes below to the file:

  namedAccounts: {
    deployer: {
      default: 0, 
      1: 0, 
    },

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.