I have the following code below
const { deployments, ethers, getNamedAccounts } = require("hardhat")
describe("FundMe", async () => {
beforeEach(async () => {
const { deployer } = await getNamedAccounts()
await deployments.fixture(["all"])
fundMe = await ethers.getContract("FundMe")
console.log(fundMe, "fundMe")
})
it("test", () => {})
describe("constructor", async () => {})
})
I am running the mocks contract and the fundme contract before getting the fundme contract. However, I was wondering why we needed this? If these are my only two contracts it would work without deployments.fixture because it seems that hardhat runs all the contracts by default if no fixtures are specified?
I tried looking at the hardhat documentation.
fixture
is used in testing to create a proper test environment. for example, if you write a smart contract which uses or interacts with some ERC20 tokens, in order to deploy the contract, you have to deploy those contracts. Or maybe some contracts inherits from interface and you need to provide those interfaces. that is what fixture is used to provide all necessary data in order to use your smart contract