Lesson 7: staging Test Error: No Contract deployed with name FundMe category:Q&A #2379
-
First of all thanks for this great course. Unfortunately I have to debug my code 70% of the time ;D. this is my hardhat-config.js: require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();
require("@nomiclabs/hardhat-etherscan")
require("hardhat-gas-reporter")
require("solidity-coverage")
require("hardhat-deploy")
const RINKEBY_RPC_URL = process.env.RINKEBY_RPC_URL;
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY;
const COINMARKET_API_KEY = process.env.COINMARKET_API_KEY;
const GOERLI_RPC_URL= process.env.GOERLI_RPC_URL;
/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
defaultNetwork: "hardhat",
networks: {
//rinkeby:{ url: RINKEBY_RPC_URL, accounts: [PRIVATE_KEY], chainId: 4,
//},
// local hardhat chain: yarn hardhat node
goerli: {
url: GOERLI_RPC_URL,
accounts: [PRIVATE_KEY],
chainId: 5,
},
localhost:{
url: "http://127.0.0.1:8545/",
chainId: 31337,
}
},
solidity: {
compilers: [
{version: "0.8.9"},
{version: "0.7.0"},
]
},
etherscan: {
apiKey: ETHERSCAN_API_KEY
},
gasReporter: {
enabled: true,
currency: "USD",
coinmarketcap: COINMARKET_API_KEY,
token: "Matic",
//outputFile: "gasReport.txt",
},
namedAccounts: {
deployer: {
default: 0,
},
users: {
default: 0,
},
}
}; this is my FundMe.sol: // SPDX-License-Identifier: MIT
//pragma
pragma solidity ^0.8.8;
//imports
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "./PriceConverter.sol";
//errors
error FundMe_NotOwner();
/** @title A contract for crowdfunding
@author clisterX
@notice This is a demmo contract
@dev implements PriceFeeds
*/
contract FundMe {
//Type declarations
using PriceConverter for uint256;
mapping(address => uint256) private s_addressToAmountFunded;
address[] private /* public falls variablen zugriff über FundMe.test.js */ s_funders;
// Could we make this constant? /* hint: no! We should make it immutable! */
address private /* immutable */ i_owner;
uint256 public constant MINIMUM_USD = 50 * 10 ** 18;
AggregatorV3Interface private s_priceFeed;
//modifier
modifier onlyOwner {
// require(msg.sender == owner);
if (msg.sender != i_owner) revert FundMe_NotOwner();
_;
}
constructor(address priceFeedAddress) {
s_priceFeed = AggregatorV3Interface(priceFeedAddress);
i_owner = msg.sender;
}
receive() external payable {
fund();
}
fallback() external payable {
fund();
}
function fund() public payable {
require(msg.value.getConversionRate(s_priceFeed) >= MINIMUM_USD, "You need to spend more ETH!");
// require(PriceConverter.getConversionRate(msg.value) >= MINIMUM_USD, "You need to spend more ETH!");
s_addressToAmountFunded[msg.sender] += msg.value;
s_funders.push(msg.sender);
}
function withdraw() payable onlyOwner public {
for (uint256 funderIndex=0; funderIndex < s_funders.length; funderIndex++){
address funder = s_funders[funderIndex];
s_addressToAmountFunded[funder] = 0;
}
s_funders = new address[](0);
(bool callSuccess, ) = payable(msg.sender).call{value: address(this).balance}("");
require(callSuccess, "Call failed");
}
function cheaperWithdraw() payable onlyOwner public {
address[] memory funders = s_funders;
for (uint256 funderIndex = 0; funderIndex < funders.length; funderIndex++){
address funder = funders[funderIndex];
s_addressToAmountFunded[funder] = 0;
}
s_funders = new address[](0);
(bool callSuccess, ) = i_owner.call{value: address(this).balance}("");
require(callSuccess, "Call failed");
}
function getOwner() public view returns (address){
return i_owner;
}
function getFunder(uint256 index) public view returns (address){
return s_funders[index];
}
function getAddressToAmountFunded(address funder) public view returns (uint256){
return s_addressToAmountFunded[funder];
}
function getPriceFeed() public view returns (AggregatorV3Interface){
return s_priceFeed;
}
} my FundMe.staging.test.js: const {getNamedAccounts, ethers, network} = require("hardhat")
const {assert} = require("chai")
const {developmentChains } = require("../../helper-hardhat-config")
if (!developmentChains.includes(network.name)){
describe("FundMe", async function(){
let fundMe
let deployer
sendValue = 1 * 10 ** 18
sendValue_str = String(sendValue)
beforeEach(async function(){
deployer = (await getNamedAccounts()).deployer
fundMe = await ethers.getContract("FundMe", deployer)
})
it("allows people to fund and withdraw", async function(){
await fundMe.fund({value: sendValue_str})
await fundMe.withdraw()
const endingBalance = await fundMe.provider.getBalance(fundMe.address)
assert.equal(endingBalance.toString(), "0")
})
})
} and finally my error Message when I run: yarn hardhat test --network goerli FundMe
1) "before each" hook for "allows people to fund and withdraw"
·-----------------------|----------------------------|-------------|----------------------------·
| Solc version: 0.8.9 · Optimizer enabled: false · Runs: 200 · Block limit: 6718946 gas │
························|····························|·············|·····························
| Methods · 11 gwei/gas · 0.80 usd/matic │
·············|··········|··············|·············|·············|·············|···············
| Contract · Method · Min · Max · Avg · # calls · usd (avg) │
·------------|----------|--------------|-------------|-------------|-------------|--------------·
0 passing (997ms)
1 failing
1) FundMe
"before each" hook for "allows people to fund and withdraw":
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/staging/FundMe.staging.test.js:14:22)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. Thanks for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Did you deploy the contract first to the testnet? Either way, deploy again and try running the test again |
Beta Was this translation helpful? Give feedback.
-
@clisterX : For deploying to a testnet, Run the command : Then run your staging test. |
Beta Was this translation helpful? Give feedback.
Did you deploy the contract first to the testnet? Either way, deploy again and try running the test again