wighawag / hardhat-deploy

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

hardhat-deploy does not seem to be working together with @nomiclabs/hardhat-waffle #281

Closed DsAtHuH closed 2 years ago

DsAtHuH commented 2 years ago

Describe the bug hardhat-deploy does not seem to work together with @nomiclabs/hardhat-waffle.

Running yarn hardhat test from https://github.com/DsAtHuH/hardhat-deploy/tree/waffle currently results in the following error:

yarn run v1.22.17
$ node --require esm node_modules/.bin/hardhat test

  Token contract
    Deployment
      1) Should set the right owner
      2) Should assign the total supply of tokens to the owner
    Transactions
      3) Should transfer tokens between accounts
      4) Should fail if sender doesn’t have enough tokens
      5) Should update balances after transfers

  Token contract
    ✔  (129ms)

  1 passing (3s)
  5 failing

  1) Token contract
       Deployment
         Should set the right owner:
     TypeError: ethers.getContract is not a function
      at setup (test/Test.test.js:13:30)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at runNextTicks (node:internal/process/task_queues:65:3)
      at listOnTimeout (node:internal/timers:526:9)
      at processTimers (node:internal/timers:500:7)
      at Context.<anonymous> (test/Test.test.js:46:31)

  2) Token contract
       Deployment
         Should assign the total supply of tokens to the owner:
     TypeError: ethers.getContract is not a function
      at setup (test/Test.test.js:13:30)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at Context.<anonymous> (test/Test.test.js:52:43)

  3) Token contract
       Transactions
         Should transfer tokens between accounts:
     TypeError: ethers.getContract is not a function
      at setup (test/Test.test.js:13:30)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at Context.<anonymous> (test/Test.test.js:59:50)

  4) Token contract
       Transactions
         Should fail if sender doesn’t have enough tokens:
     TypeError: ethers.getContract is not a function
      at setup (test/Test.test.js:13:30)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at Context.<anonymous> (test/Test.test.js:71:50)

  5) Token contract
       Transactions
         Should update balances after transfers:
     TypeError: ethers.getContract is not a function
      at setup (test/Test.test.js:13:30)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at Context.<anonymous> (test/Test.test.js:80:50)

error Command failed with exit code 5.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

The problem looks to be associated with installing the dependency @nomiclabs/hardhat-waffle": "^2.0.3. If you comment the line https://github.com/DsAtHuH/hardhat-deploy/blob/waffle/hardhat.config.js#L3 from hardhat.config.js, all the tests from Test.test.js pass, but not the Waffle.test.js.

To Reproduce Steps to reproduce the behavior: Issue the command yarn hardhat test from the branch waffle from the repository https://github.com/DsAtHuH/hardhat-deploy/tree/waffle.

Expected behavior Pass all the tests specified in Test.test.js and Waffle.test.js simultaneously.

versions

wighawag commented 2 years ago

The issue is that hardhat-waffle hardcodes its dependency with @nomiclabs/hardhat-ethers

hardhat-deploy-ethers extends the types of @nomiclabs/hardhat-ethers but because it implements extra feature that cannot be provided by hardhat itself, see : https://github.com/NomicFoundation/hardhat/issues/1040, it has to be a replacemant of it

and so you should NOT install both, but install only hardhat-deploy-ethers

But because of the hardcoded dependency in hardhat-waffle you have to use an npm alias , see doc : https://github.com/wighawag/hardhat-deploy-ethers/#installation

Some users have some issue with their respective package manager though, see : https://github.com/wighawag/hardhat-deploy-ethers/issues/12

The best option is to push hardhat team to fix this issue : https://github.com/NomicFoundation/hardhat/issues/1040

because once this is resolved, hardhat-deploy-ethers can then be an extension to @nomiclabs/hardhat-ethers and not a fork like it is now

I ll close this as this is actually related to hardhat-deploy-ethers, not hardhat-deploy itself and there is already an issue for it rhere : https://github.com/wighawag/hardhat-deploy-ethers/issues/12