sets the aggregator addresses correctly: ReferenceError: fundMe is not defined #6539
Answered
by
NIAZELOPER
karthikeh02
asked this question in
Q&A
-
ive been getting this error at 11:18:10 when i run yarn hardhat test in terminal this is my repo if anyone would look into it,it would be helpful |
Beta Was this translation helpful? Give feedback.
Answered by
NIAZELOPER
Apr 5, 2024
Replies: 1 comment
-
The error says that there is no variable named fundme. This is because you have initialized fundme and MockV3Aggregator variables inside the BeforeEach() , therefore describe block of constructor does not know fundme variable. To fix issue Change the code from: describe("FundMe", async () => {
beforeEach(async function () {
let fundMe
let deployer
let MockV3Aggregator
//deploy our fundme contract
// using hardhat deploy
deployer = (await getNamedAccounts()).deployer
await deployments.fixture(["all"])
fundMe = await ethers.getContractAt("FundMe", deployer)
MockV3Aggregator = await ethers.getContractAt(
"MockV3Aggregator",
deployer,
)
})
```
TO:
```javascript
describe("FundMe", async () => {
let fundMe
let deployer
let MockV3Aggregator
beforeEach(async function () {
//deploy our fundme contract
// using hardhat deploy
deployer = (await getNamedAccounts()).deployer
await deployments.fixture(["all"])
fundMe = await ethers.getContractAt("FundMe", deployer)
MockV3Aggregator = await ethers.getContractAt(
"MockV3Aggregator",
deployer,
)
})
```
The change in the code is that the fundme, deployer and MockV3Aggregator variavbles are initialized outside the beforeEach so that decribe("Constructor") block knows these variable.
Hope this helps :) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
karthikeh02
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The error says that there is no variable named fundme. This is because you have initialized fundme and MockV3Aggregator variables inside the BeforeEach() , therefore describe block of constructor does not know fundme variable.
To fix issue Change the code from: