Lesson 7 Hardhat fundMe @ 11:18:00 : "Error: No Contract deployed with name FundMe" #1491
-
Let me start by saying that this is a great course! @PatrickAlphaC rocks (he is so much in control that I almost suspect he put these issues in on purpose for learning). The Context: Followed the video's creation of FundMe.test.js up until 11:18. The solution compiles and deploys fine. Trying to test the constructor function deployment by running 'yarn hardhat test'. Here is the reply:
I have tried several things listed in previous discussions to solve the issue incl. getContractAt, hardhat-deploy-ethers. Perhaps I am just blind and there is a trivial oversight. "FundMe" seems to get deployed, which leaves the issue with 'getContract'. that is my assumption. Anyone has an idea? Here are my files: FundMe.test.js: const { assert } = require("chai")
const { deployments, ethers, getNamedAccounts } = require("hardhat")
describe("FundMe", async function () {
let fundMe
let deployer
let mockV3Aggregator
beforeEach(async function () {
//const accounts = await ethers.getSigners()
//const accountZero = accounts[0]
deployer = (await getNamedAccounts()).deployer
await deployments.fixture(["all"])
//console.log(deploy)
fundMe = await ethers.getContract("FundMe", deployer)
mockV3Aggregator = await ethers.getContract(
"MockV3Aggregator",
deployer
)
})
describe("constructor", async function () {
it("Sets the aggregator addresses correctly", async function () {
// console.log(fundMe)
console.log("bla----------")
const response = await fundMe.priceFeed()
assert.equal(response, mockV3Aggregator.address)
})
})
}) 01-deploy-fund-me.js: //import
const { getNamedAccounts, deployments, network } = require("hardhat")
const { networkConfig, developmentChains } = require("../helper-hardhat-config")
const { verify } = require("../utils/verify")
module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments
const { deployer } = await getNamedAccounts()
const chainId = network.config.chainId
let ethUsdPriceFeedAddress
if (developmentChains.includes(network.name)) {
const ethUsdAggregator = await deployments.get("MockV3Aggregator")
ethUsdPriceFeedAddress = ethUsdAggregator.address
} else {
ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"]
}
log("-----------------------")
log(network.name)
log("Deploying FundMe and waiting for confirmations")
const args = [ethUsdPriceFeedAddress]
const fundMe = await deploy("FundMe", {
from: deployer,
args: [ethUsdPriceFeedAddress], //priceFeed
log: true,
waitConfirmations: network.config.blockConfirmations || 1,
})
log("FundMe deployed!")
if (
!developmentChains.includes(network.name) &&
process.env.ETHERSCAN_API_KEY
) {
//verify
await verify(fundMe.address, [ethUsdPriceFeedAddress])
}
log("----------------------------------")
}
module.exports.tags = ("all", "fundme") FundMe.sol: // SPDX-License-Identifier: MIT
//imrproved according to style guide (SG)
// SG: pragma
pragma solidity ^0.8.8;
// SG: imports
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "./PriceConverter.sol";
// SG: error codes
error FundMe_NotOwner();
// SG: Interfaces, libraries
// contracts
/** @title A contract for crowdfunding
* @author Keld Stehr Nielsen - well really Patrick Collins
* @notice This contract is to demo a sample funding contract
* @dev This implements price feeds as our library
*/
contract FundMe {
//type declarations
using PriceConverter for uint256;
//State variables!
mapping(address => uint256) public addressToAmountFunded;
address[] public funders;
address public immutable i_owner;
uint256 public constant MINIMUM_USD = 50 * 10**18;
AggregatorV3Interface public priceFeed;
// events
// modifiers
modifier onlyOwner() {
// require(msg.sender == owner);
if (msg.sender != i_owner) revert FundMe_NotOwner();
_;
}
// functions: order: constructor, receive, fallback, external, public, internal, private, view/pure
constructor(address priceFeedAddress) {
i_owner = msg.sender;
priceFeed = AggregatorV3Interface(priceFeedAddress);
}
receive() external payable {
fund();
}
fallback() external payable {
fund();
}
function fund() public payable {
require(
msg.value.getConversionRate(priceFeed) >= MINIMUM_USD,
"You need to spend more ETH!"
);
// samesame: require(PriceConverter.getConversionRate(msg.value) >= MINIMUM_USD, "You need to spend more ETH!");
addressToAmountFunded[msg.sender] += msg.value;
funders.push(msg.sender);
}
function withdraw() public payable onlyOwner {
for (
uint256 funderIndex = 0;
funderIndex < funders.length;
funderIndex++
) {
address funder = funders[funderIndex];
addressToAmountFunded[funder] = 0;
}
funders = new address[](0);
// // transfer
// payable(msg.sender).transfer(address(this).balance);
// // send
// bool sendSuccess = payable(msg.sender).send(address(this).balance);
// require(sendSuccess, "Send failed");
// call
(bool callSuccess, ) = payable(msg.sender).call{
value: address(this).balance
}("");
require(callSuccess, "Call failed");
}
}
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
@nebelmeerwanderer1 In your module.exports.tags=["all","fundme"] You should use square brackets instead of parenthesis |
Beta Was this translation helpful? Give feedback.
-
IM HAVING THE SAME PROBLEM 01-deploy-fund-me.js
FundMe.test.js
FundMe.sol
THE ERROR
|
Beta Was this translation helpful? Give feedback.
@nebelmeerwanderer1 In your
01-deploy-fund-me.js
change themodule.exports.tags
to this :You should use square brackets instead of parenthesis