Lesson 7; Unable to run test #5006
-
I keep getting this error whenever I run yarn hardhat test
I've been on this problem for days now const { deployments, getNamedAccounts, ethers } = require("hardhat");
const { assert } = require("chai");
let fundMe;
let mockV3Aggregator;
let deployer;
describe("FundMe", async function () {
beforeEach(async function () {
deployer = (await getNamedAccounts()).deployer;
await deployments.fixture(["all"]);
mockV3Aggregator = await ethers.getContract("MockV3Aggregator", deployer);
fundMe = await ethers.getContract("FundMe", deployer);
});
describe("constructor", async function () {
it("Sets the aggregator addresses correctly", async function () {
const response = await fundMe.priceFeed();
assert.equal(response, mockV3Aggregator.address);
});
});
describe("fund", async function () {
it("Should not revert", async function () {
await expect(fundMe.fund()).to.be.revertedWith(
"You need to spend more gas"
);
});
});
}); my 01-deploy-FundMe.js file const { network } = require("hardhat");
const { developmentChains, networkConfig } = require("../helper-hardhat");
module.exports = async function ({ deployments, getNamedAccounts }) {
const { deploy, log } = deployments;
const chainId = network.config.chainId;
const { deployer } = await getNamedAccounts();
let ethUsdPriceFeedAddress;
if (developmentChains.includes(network.name)) {
const mockV3Aggregator = await deployments.get("MockV3Aggregator");
ethUsdPriceFeedAddress = mockV3Aggregator.address;
} else {
ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeedAddress"];
}
log("Deploying fundMe");
const fundMe = await deploy("FundMe", {
from: deployer,
args: [ethUsdPriceFeedAddress],
log: true,
});
log(`FundMe contract address: ${fundMe.address}`);
};
module.exports.tags = ["all", "fundMe"]; my 00-deployMockV3Aggregator.js file const { network } = require("hardhat");
const { developmentChains } = require("../helper-hardhat");
module.exports = async function ({ deployments, getNamedAccounts }) {
const { deploy, log } = deployments;
const { deployer } = await getNamedAccounts();
const chainId = network.config.chainId;
const DECIMALS = 8;
const INITIAL_ANSWER = 200000000;
if (developmentChains.includes(network.name)) {
log("Deploying mockV3Aggregator");
const mockV3Aggregator = await deploy("MockV3Aggregator", {
contract: "MockV3Aggregator",
from: deployer,
args: [DECIMALS, INITIAL_ANSWER],
log: true,
});
log(`mockV3Aggregator contract address: ${mockV3Aggregator.address}`);
}
};
module.exports.tags = ["all", "mocks"]; my hardhat-config.js file require("@nomicfoundation/hardhat-toolbox");
require("hardhat-deploy");
require("dotenv").config();
require("solidity-coverage");
require("@nomiclabs/hardhat-etherscan");
/** @type import('hardhat/config').HardhatUserConfig */
const GOERLI_RPC_URL = process.env.GOERLI_RPC_URL;
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const COINMARKETCAP_API_KEY = process.env.COINMARKETCAP_API_KEY;
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY;
module.exports = {
defaultNetwork: "hardhat",
solidity: {
compilers: [{ version: "0.8.7" }, { version: "0.6.6" }],
},
networks: {
goerli: {
url: GOERLI_RPC_URL,
accounts: [PRIVATE_KEY],
chainId: 5,
// blockConfirmations: 6,
},
},
gasReporter: {
enabled: true,
noColours: true,
currency: "USD",
outputFile: "gas-report.txt",
coinmarketcap: COINMARKETCAP_API_KEY,
},
etherscan: {
apiKey: ETHERSCAN_API_KEY,
},
namedAccounts: {
deployer: {
default: 0,
},
},
};
|
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 15 replies
-
In your hardhat.config you didn't specify the solidity version. specify whatever solidty version you are using inside module.exports at the first position as stated below. module.exports = { |
Beta Was this translation helpful? Give feedback.
-
@Cointerior I am too facing same issue have you got any solution |
Beta Was this translation helpful? Give feedback.
-
@Cointerior I solved this issue , I posted how to solve this issue on Ethereum Stackoverflow, here https://ethereum.stackexchange.com/questions/146902/before-each-hook-for-sets-the-aggregator-addresses-correctly-typeerror-cann/146903#146903 |
Beta Was this translation helpful? Give feedback.
-
@Cointerior Leave your repo link, if you are still facing the issue. |
Beta Was this translation helpful? Give feedback.
-
FYI: I solved the same issue with the latest version of |
Beta Was this translation helpful? Give feedback.
-
I changed Suddently it worked. is it fine? |
Beta Was this translation helpful? Give feedback.
@Cointerior Leave your repo link, if you are still facing the issue.