wighawag / hardhat-deploy

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

Typescript error when testing diamond #335

Open danielhursan opened 2 years ago

danielhursan commented 2 years ago

Describe the bug I'm running into an error when adding a test for a simple diamond use case. From what I see, it all boils down to this method call

....
diamondCutFacet = (await ethers.getContract("DiamondCutFacet", diamondTemplate.address));
....
await diamondCutFacet.diamondCut(
            [{
                facetAddress: sampleFacet.address,
                action: FacetCutAction.Add,
                functionSelectors: SAMPLE_FACET_SELECTORS
            }],
            "0x0000000000000000000000000000000000000000", 
            "0x"
        );

Error encountered is the following

An unexpected error occurred:

/Users/daniel.hursan/dev/blockchain-template/node_modules/hardhat-deploy/types.ts:2
import 'hardhat/types/runtime';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1033:15)
    at Module._compile (node:internal/modules/cjs/loader:1069:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/daniel.hursan/dev/blockchain-template/node_modules/ts-node/src/index.ts:1587:43)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/daniel.hursan/dev/blockchain-template/test/Diamond/DiamondTemplate.ts:3:1)

It seems that only that particular call triggers the error and invokes the hardhat/types/runtime at some point I've also tried to add "type": "modules" in package.json, which triggers other errors and it's not a solution, because I can't change requires with imports for dependencies of hardhat-deploy.

To Reproduce Steps to reproduce the behavior:

  1. Add a test for interacting with DiamondCutFacet contract
  2. Attempt to call diamondCut() method
  3. See error
  4. If I comment out that first piece of code, error goes away.

Expected behavior I would expect any error related to my code, missing function or whatever helpful, but stracktrace points to some internal references. Not sure if it's a conflict between hardhat-waffle and hardhat-deploy-ethers, that I understand use hardhat-ethers behind the scenes, but different forks.

versions

"devDependencies": {
        "@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers@^0.3.0-beta.13",
        "@types/chai": "^4.3.1",
        "@types/jest": "^28.1.1",
        "@types/mocha": "^9.1.1",
        "@types/node": "^17.0.42",
        "chai": "^4.3.6",
        "ethereum-waffle": "^3.4.4",
        "ethers": "^5.6.8",
        "hardhat": "^2.9.3",
        "hardhat-deploy": "^0.11.10",
        "ts-node": "^10.7.0",
        "typescript": "^4.6.4"
    },
danielhursan commented 2 years ago

@wighawag , any idea?