Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Truffle solc pragma causes the exception Cannot destructure property 'contractName' #4863

Closed
1 task done
shadmatic opened this issue Mar 13, 2022 · 5 comments
Closed
1 task done

Comments

@shadmatic
Copy link


Issue

In our repo codebase we are using many contracts dependencies from different solidity versions. Thus, we are using the truffle config pragma. Problem is happening in our CI, we are experiencing the error: TypeError: Cannot destructure property 'contractName' of 'contract' as it is undefined..

Steps to Reproduce

Create and import a few contracts with different versions, for instance:

  • ChainLink LinkToken uses ^0.4.11
  • ChainLink VRFMock uses 0.6.6

Create a basic contract using pragma solidity ^0.8.0; and import above contracts which has mixed versions.

In your truffle-config.js file, just set your solc to pragma:

//...
  compilers: {
    solc: {
      version: "pragma", // Fetch exact version from solc-bin (default: truffle's version)
// ...

Expected Behavior

The contracts to be built successfully. I realized that in truffle v5.4.26 it actually works

Actual Results

TypeError: Cannot destructure property 'contractName' of 'contract' as it is undefined.
    at forContract (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-common/dist/src/shims/NewToLegacy.js:5:12)
    at Array.map (<anonymous>)
    at Object.save (/usr/local/lib/node_modules/truffle/build/webpack:/packages/workflow-compile/index.js:[123](https://github.com/StarterXyz/effective-system/runs/5463281701?check_suite_focus=true#step:5:123):1)
    at Object.compileAndSave (/usr/local/lib/node_modules/truffle/build/webpack:/packages/workflow-compile/index.js:96:1)
    at Object.compileContractsWithTestFilesIfNeeded (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/testing/Test.js:239:38)
    at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/testing/Test.js:97:27)
    at Object.module.exports [as run] (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/test/run.js:102:1)
    at Command.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:189:1)
Truffle v5.4.33 (core: 5.4.33)
Node v16.14.0

Environment

  • Operating System: ubuntu
  • Ethereum client: N/A
  • Truffle version (truffle version): 5.4.33
  • node version (node --version): v16.14.0
@eggplantzzz
Copy link
Contributor

Thank you @shadmatic for reporting this! Is your code on GitHub somewhere so that we can use it to reproduce the error you are receiving?

@shadmatic
Copy link
Author

Unfortunately our code is closed source for now. I hope with my above steps you have enough to reproduce 👍

@eggplantzzz
Copy link
Contributor

eggplantzzz commented Mar 15, 2022

Ok, I will try really quickly to see what happens and report back.

Note that you cannot have contracts importing other contracts for which there exists no Solidity version that satisfies both pragma expressions. For example, if A.sol imports B.sol and the pragma expressions are pragma solidity "^0.4.11" and pragma solidity "0.5.0" respectively. This will not work as they both need to be compiled together by the same version of the Solidity compiler.

So actually looking back at your reproduction steps it looks like you are doing something that is currently unsupported by Truffle. There is a feature request for this here

@eggplantzzz
Copy link
Contributor

Ah actually it does look like there is a bug here with the "pragma" setting. If you try and compile on a fresh metacoin box project with "pragma" set then you get this error. I will investigate this and try to get a fix out soon. Thanks @shadmatic!

@haltman-at
Copy link
Contributor

OK, this should be fixed in 5.5.6!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants