Lesson 7 : AssertionError: expected '0x5FbDB2315678afecb367f032d93F642f641…' to equal undefined #6015
-
I received an error when running a test using yarn hardhat test
This is the error :
My MockV3Aggregator. sol code :
My FundMe.sol code :
I'm not really sure what've been wrong. Can anyone help? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
What will you get if you deploy the contract? (Does deploy script work fine?)
|
Beta Was this translation helpful? Give feedback.
-
Try using |
Beta Was this translation helpful? Give feedback.
-
Hey @wwwbaraccuda , In v6 we use getContractAt in which it takes three argument (nameOfContract, addressOfContract, signerOfContract) All contract instances are stored in the contracts by this: const contracts = await deployments.fixture(["all"]); For the addressOfContract we use this: const fundMeAddress = contracts["FundMe"].address; For the signerOfContract we use getSigner: const signer = await ethers.getSigner(deployer); we can take the instance of the contract by this : mockV3Aggregator = contracts["MockV3Aggregator"]; then we have : const { deployments, ethers, getNamedAccounts } = require("hardhat")
const { assert } = require("chai")
describe("FundMe", async function () {
let fundMe
let deployer
let mockV3Aggregator
beforeEach(async function () {
deployer = (await getNamedAccounts()).deployer;
const contracts = await deployments.fixture(["all"]);
const signer = await ethers.getSigner(deployer);
const fundMeAddress = contracts["FundMe"].address;
fundMe = await ethers.getContractAt("FundMe", fundMeAddress, signer);
mockV3Aggregator = contracts["MockV3Aggregator"];
});
describe("constructor", async function () {
it("sets the aggregator addresses correctly", async function () {
const response = await fundMe.priceFeed()
assert.equal(response, mockV3Aggregator.address)
})
})
}) if you have any query feel free to ask. |
Beta Was this translation helpful? Give feedback.
-
You omitted to deploy mocks also...
Like this... module.exports.tags = ["all", "MockV3Aggregator"] |
Beta Was this translation helpful? Give feedback.
Hey @wwwbaraccuda , In v6 we use getContractAt in which it takes three argument (nameOfContract, addressOfContract, signerOfContract)
All contract instances are stored in the contracts by this:
For the addressOfContract we use this:
For the signerOfContract we use getSigner:
we can take the instance of the contract by this :
then we have :