Deployer not defined error while running FundMe.testme.js #6634
Replies: 2 comments
-
import require("@nomiclabs/hardhat-ethers") in hardhat.config.js |
Beta Was this translation helpful? Give feedback.
0 replies
-
To fix the deployer not defined error, you need to retrieve the deployer account using getNamedAccounts and use it in your test. Here's how you can do it: Updated FundMe.test.js const { deployments, ethers, getNamedAccounts } = require("hardhat");
const { assert } = require("chai");
describe("FundMe", async () => {
let FundMe;
let deployer; // Define deployer here
let MockV3Aggregator;
const sendValue = ethers.parseEther("1");
beforeEach(async () => {
// Retrieve the deployer account using getNamedAccounts
const { deployer: deployerAccount } = await getNamedAccounts();
deployer = deployerAccount; // Assign the deployer account to the deployer variable
const accounts = await ethers.getSigners();
const signer = accounts[0]; // Use signer if needed, but deployer is already available
await deployments.fixture(["all"]);
// Use deployer as the signer for the contract
const FundMeDeployment = await deployments.get("FundMe");
FundMe = await ethers.getContractAt(
FundMeDeployment.abi,
FundMeDeployment.address,
deployer // Use deployer as the signer
);
const MockV3AggregatorDeployment = await deployments.get("MockV3Aggregator");
MockV3Aggregator = await ethers.getContractAt(
MockV3AggregatorDeployment.abi,
MockV3AggregatorDeployment.address,
deployer // Use deployer as the signer
);
});
describe("constructor", async () => {
it("sets the aggregator address correctly", async () => {
const response = await FundMe.priceFeed();
assert.equal(response, MockV3Aggregator.target);
});
});
describe("fund", async () => {
it("it fails if you don't send enough ETH", async () => {
await expect(FundMe.fund()).to.be.revertedWith(
"You need to spend more ETH!"
);
});
it("updates the amount funded data structure", async () => {
await FundMe.fund({ value: sendValue });
const response = await FundMe.addressToAmountFunded(deployer); // Use deployer here
assert.equal(response.toString(), sendValue.toString());
});
});
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
hello guys while running Fundme.test.js there is an error showing deployer not defined
can anyone tell where the error is ?could anyone tell whats the error with deployer defined in hardhat code below?
Fundme.test.js code
hardhat.config.js code is
could anyone tell whats the deployer not defined error?
Beta Was this translation helpful? Give feedback.
All reactions