Chapter 7 - Hardhat Fund Me : Error - No Contract deployed with name FundMe #5114
-
I am getting the error while compiling: I tried all the solutions given in the discussions but none worked. Please help me what to do. yarn run v1.22.19
warning package.json: No license field
$ /Users/shivam/Documents/Blockchain/hardhat-fund-me/node_modules/.bin/hardhat test
FundMe
constructor
1) "before each" hook for "it sets the aggregator addresses directly"
0 passing (660ms)
1 failing
1) FundMe
"before each" hook for "it sets the aggregator addresses directly":
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 runNextTicks (node:internal/process/task_queues:65:3)
at listOnTimeout (node:internal/timers:528:9)
at processTimers (node:internal/timers:502:7)
at Context.<anonymous> (test/unit/FundMe.test.js:27:18)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. 00-deploy-mock.js file: const { network } = require('hardhat')
const {
developmentChain,
DECIMALS,
INITIAL_ANSWER,
} = require('../helper-hardhat-config')
//async nameless function using arrrow notation
module.exports = async ({ getNamedAccounts, deployments }) => {
//deployments object to get 2 functions: deploy and log
const { deploy, log } = deployments
//getNamedAccounts is a way to get named accounts
const { deployer } = await getNamedAccounts()
const chainId = network.config.chainId
// our helper-hardhat-config is using name
if (developmentChain.includes(network.name)) {
log('local network detected!!')
await deploy('MockV3Aggregator', {
contract: 'MockV3Aggregator',
from: deployer,
log: true,
args: [DECIMALS, INITIAL_ANSWER],
})
log('Mocks Deployed')
log('-----------------------')
}
}
module.exports.tags = ['all', 'mocks'] 01-deploy-fund-me.js file //import
const { network } = require('hardhat')
require('@nomiclabs/hardhat-etherscan')
require('dotenv').config()
const { networkConfig, developmentChain } = require('../helper-hardhat-config')
const { verify } = require('../utils/verify')
//async nameless function using arrrow notation
module.exports = async ({ getNamedAccounts, deployments }) => {
//deployments object to get 2 functions: deploy and log
const { deploy, log } = deployments
//getNamedAccounts is a way to get named accounts
const { deployer } = await getNamedAccounts()
const chainId = network.config.chainId
//If chaidId is X use address Y
//If chainId is Z use address A
// const ethUsdPriceFeeAddress = networkConfig[chainId]['ethUsdPriceFeed']
let ethUsdPriceFeeAddress
if (developmentChains.includes(network.name)) {
//get the most recent deploymet using 'get'. It takes name of contract that we deployed
const ethUsdAggregator = await deployments.get('MockV3Aggregator')
ethUsdPriceFeeAddress = ethUsdAggregator.address
} else {
//if we didnt deploy the mock
ethUsdPriceFeeAddress = networkConfig[chainId]['ethUsdPriceFeed']
}
//when we want to work in localhost or hardhat env, we use mock
//with hardhat-deploy, we can use deploy function
//name of contract to deply and list of overrides that we want to add
const args = [ethUsdPriceFeeAddress]
const fundMe = await deploy('FundMe', {
from: deployer,
//we can pass arguments to the destructor
args: args, //put price feed address
log: true,
waitConfirmations: network.config.blockConfirmations || 1,
})
//if network is not a development network
if (
!developmentChain.includes(network.name) &&
process.env.ETHERSCAN_API_KEY
) {
await verify(fundMe.address, args)
}
log('--------------------------------------------')
}
module.exports.tag = ['all', 'fundMe'] FundMe.test.js file //first by pulling deployment object from hardhat, we can deploy
const { deployments, ethers, getNamedAccounts } = require('hardhat')
const { assert } = require('chai')
describe('FundMe', function () {
//deploy before testing FundMe contract
let fundMe //as we have mocks as well to deploy
let deployer
let mockV3Aggregator
beforeEach(async function () {
//deploy our fundme using hardhat deploy
//another way to get different accounts directly from hardhat-config
//it returns whatever is present in account section of hardhat.config.js
//if on default account hardhat, it gives 10 fake account to work with
// const accounts = await ethers.getSigners()
// const accountZero = accounts[0]
//we can tell ether which account to connect to fundme
deployer = (await getNamedAccounts()).deployer
//fixture allows us to run deploy folder with as many tags as we want
//it help us to deploy both the files
await deployments.fixture(['all'])
//getContract gets the most recent deployment that we tell
//and connect fundme with deployer account
fundMe = await ethers.getContract('FundMe', deployer)
//make sure priceFeed is same as MockV3Aggregator as we're running the test locally
mockV3Aggregator = await ethers.getContract(
'MockV3Aggregator',
deployer
)
})
//test for constructor
describe('constructor', async function () {
it('it sets the aggregator addresses directly', async function () {
//priceFeed is present in FundMe.sol contract
const response = await fundMe.getPriceFeed()
assert.equal(response, mockV3Aggregator.address)
})
})
}) |
Beta Was this translation helpful? Give feedback.
Answered by
alymurtazamemon
Mar 17, 2023
Replies: 1 comment 1 reply
-
@Saivite It is -module.exports.tag = ['all', 'fundMe']
+module.exports.tags = ['all', 'fundMe'] |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Saivite
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Saivite It is
tags