Repository: NomicFoundation/hardhat

Issue #1564: Hardhat Network tracing engine doesn't work when mappings contain custom types (enums or contracts) as keys
Created: 2021-06-18T11:00:51Z
Thanks for the awesome tool!
Simple reproduction of issue:

add a revert() or similar to somewhere in some hardhat contracts you have at hand. (check it shows the stack trace correctly)
Add this anywhere in any of your contract files (doesn't need to be the one that you added the revert to):

enum EnumThatBreaksThings {Option1, Option2}
mapping(EnumThatBreaksThings => uint256) public thing;

Run the tests again, you won't get proper stack traces. Something like this will be shown instead:

at <UnrecognizedContract>.<unknown> (0xdc64a140aa3e981100a9beca4e685f962f0cf6c9)

Other info:
I have run the code with the --verbose flag and this was the output.
The Hardhat Network tracing engine could not be initialized. Run Hardhat with --verbose to learn more.
  hardhat:core:hardhat-network:node Hardhat Network tracing disabled: ContractsIdentifier failed to be initialized. Please report this to help us improve Hardhat.
  hardhat:core:hardhat-network:node  TypeError: Cannot read property 'startsWith' of undefined
    at toCanonicalAbiType (/home/jasoons/Documents/code/monorepo/contracts/node_modules/hardhat/src/internal/hardhat-network/stack-traces/compiler-to-model.ts:536:12)
    at getPublicVariableSelectorFromDeclarationAstNode (/home/jasoons/Documents/code/monorepo/contracts/node_modules/hardhat/src/internal/hardhat-network/stack-traces/compiler-to-model.ts:240:23)
    at processVariableDeclarationAstNode (/home/jasoons/Documents/code/monorepo/contracts/node_modules/hardhat/src/internal/hardhat-network/stack-traces/compiler-to-model.ts:282:5)
    at processContractAstNode (/home/jasoons/Documents/code/monorepo/contracts/node_modules/hardhat/src/internal/hardhat-network/stack-traces/compiler-to-model.ts:151:7)
    at createSourcesModelFromAst (/home/jasoons/Documents/code/monorepo/contracts/node_modules/hardhat/src/internal/hardhat-network/stack-traces/compiler-to-model.ts:80:9)
    at Object.createModelsAndDecodeBytecodes (/home/jasoons/Documents/code/monorepo/contracts/node_modules/hardhat/src/internal/hardhat-network/stack-traces/compiler-to-model.ts:37:3)
    at new HardhatNode (/home/jasoons/Documents/code/monorepo/contracts/node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:297:27)
    at Function.create (/home/jasoons/Documents/code/monorepo/contracts/node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:193:18)
    at HardhatNetworkProvider._init (/home/jasoons/Documents/code/monorepo/contracts/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:239:28)
    at HardhatNetworkProvider._send (/home/jasoons/Documents/code/monorepo/contracts/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:179:5) +0ms

Duplicate issue #1829: TypeError: Cannot read property 'startsWith' of undefined
Created: 2021-08-25T20:32:15Z
Faced this issue:
yarn test --verbose

The Hardhat Network tracing engine could not be initialized. Run Hardhat with --verbose to learn more.
  hardhat:core:hardhat-network:node Hardhat Network tracing disabled: ContractsIdentifier failed to be initialized. Please report this to help us improve Hardhat.
  hardhat:core:hardhat-network:node  TypeError: Cannot read property 'startsWith' of undefined
    at toCanonicalAbiType (/Users/k06a/Projects/protocol/node_modules/hardhat/src/internal/hardhat-network/stack-traces/compiler-to-model.ts:536:12)
    at getPublicVariableSelectorFromDeclarationAstNode (/Users/k06a/Projects/protocol/node_modules/hardhat/src/internal/hardhat-network/stack-traces/compiler-to-model.ts:240:23)
    at processVariableDeclarationAstNode (/Users/k06a/Projects/protocol/node_modules/hardhat/src/internal/hardhat-network/stack-traces/compiler-to-model.ts:282:5)
    at processContractAstNode (/Users/k06a/Projects/protocol/node_modules/hardhat/src/internal/hardhat-network/stack-traces/compiler-to-model.ts:151:7)
    at createSourcesModelFromAst (/Users/k06a/Projects/protocol/node_modules/hardhat/src/internal/hardhat-network/stack-traces/compiler-to-model.ts:80:9)
    at Object.createModelsAndDecodeBytecodes (/Users/k06a/Projects/protocol/node_modules/hardhat/src/internal/hardhat-network/stack-traces/compiler-to-model.ts:37:3)
    at new HardhatNode (/Users/k06a/Projects/protocol/node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:351:27)
    at Function.create (/Users/k06a/Projects/protocol/node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:240:18)
    at HardhatNetworkProvider._init (/Users/k06a/Projects/protocol/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:232:28)
    at HardhatNetworkProvider._send (/Users/k06a/Projects/protocol/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:180:5)
    at HardhatNetworkProvider.request (/Users/k06a/Projects/protocol/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:106:18)
    at Web3HTTPProviderAdapter._sendJsonRpcRequest (/Users/k06a/Projects/protocol/node_modules/@nomiclabs/hardhat-web3/src/web3-provider-adapter.ts:80:22) +0ms
  hardhat:sentry:subprocess starting subprocess +0ms
  hardhat:sentry:subprocess sentry event was sent +14ms

I am using:
"hardhat": "^2.6.1",
"hardhat-deploy": "^0.9.0",
"hardhat-gas-reporter": "^1.0.4",

Closing comment (2021-08-26T18:35:44Z): Thanks for the PR @k06a, we'll look into it as soon as we have some time. Btw, this might be a duplicate of #1564.