wighawag / hardhat-deploy

hardhat deployment plugin
MIT License
1.19k stars 292 forks source link

function getContract() not loading contract #332

Closed dcamps-hacken closed 2 years ago

dcamps-hacken commented 2 years ago

Describe the bug getContract() seems to not be able to load the deployed contract, showing the following error:

Error: No Contract deployed with name EventLog
      at Object.getContract (node_modules\@nomiclabs\hardhat-ethers\src\internal\helpers.ts:447:11)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at Context.<anonymous> (test\unit\EventLog.test.js:12:20)

To Reproduce Steps to reproduce the behavior:

  1. Deploy a contract, in my case I deployed with:
    
    const { networkConfig, developmentChains } = require("../helper-hardhat-config")
    const { network, ethers } = require("hardhat")
    const { verify } = require("../utils/verify")

module.exports = async (hre) => { const { getNamedAccounts, deployments } = hre const { deploy, log, get } = deployments const { deployer } = await getNamedAccounts()

const eventLog = await deploy("EventLog", {
    contract: "contracts/EventLog.sol:EventLog",
    from: deployer,
    log: true,
})

} module.exports.tags = ["all", "eventLog"]


2. Test the contract using getContract() --> run "yarn hardhat test"

The test file:

const { inputToConfig } = require("@ethereum-waffle/compiler") const { assert } = require("chai") const { deployments, ethers, getNamedAccounts } = require("hardhat")

describe("EventLog", async function () { let eventLog, deployer beforeEach(async function () { deployer = (await getNamedAccounts()).deployer deployments.fixture(["all"]) eventLog = await ethers.getContract("EventLog", deployer) })

describe("constructor", async function () {
    it("sets the number of events correctly", async function () {
        const numberOfEvents = await log.getNumberOfEvents()
        assert.equal(numberOfEvents, 0)
    })
})

})



**Expected behavior**
Retrieve the contract EventLog by using getContract()

**versions**
    "@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers",
    "@nomiclabs/hardhat-etherscan": "^3.0.0",
    "@nomiclabs/hardhat-waffle": "^2.0.0",
    "chai": "^4.2.0",
    "ethereum-waffle": "^3.0.0",
    "ethers": "^5.6.8",
    "hardhat": "^2.9.7",
    "hardhat-deploy": "^0.11.10",

**Additional context**
The contract was deployed and showed up as a log on the hardhat node terminal:
deploying "EventLog" (tx: 0x354af893172d75a1289de2b61f271e55902f65757e99efc56dd183f15cb62e40)...: deployed at 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 with 2558179 gas
wighawag commented 2 years ago

looks like you are missing an await for deployments.fixture(["all"])

dcamps-hacken commented 2 years ago

Right, solved!