Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'legacyAST' of undefined #1679

Open
pieterhartel opened this issue Jan 30, 2019 · 9 comments

Comments

Projects
None yet
3 participants
@pieterhartel
Copy link

commented Jan 30, 2019

Issue

Solidity compilers version 0.4.8 and older do not deliver a legacyAST as it is expected by truffle. This means that older sources cannot be tested anymore with the appropriate compiler version.

Steps to Reproduce

mkdir test
cd test
truffle init
echo "module.exports = { compilers: { solc: { version: \"0.4.8\" } } }" > truffle-config.js 
echo "contract Test { }" > contracts/Test.sol 
cat - <<'end' > contracts/Migrations.sol
contract Migrations {
  address public owner;
  uint public last_completed_migration;
  modifier restricted() { if (msg.sender == owner) _; } 
  function Migrations() { owner = msg.sender; } 
  function setCompleted(uint completed) restricted { last_completed_migration = completed; }
  function upgrade(address new_address) restricted { Migrations upgraded = Migrations(new_address); upgraded.setCompleted(last_completed_migration);
  }
}
end
truffle test

Expected Behavior

A truffle test run that does not throw exceptions.

Actual Results

+ mkdir test
+ cd test
+ truffle init

✔ Preparing to download
✔ Downloading
✔ Cleaning up temporary files
✔ Setting up box

Unbox successful. Sweet!

Commands:

  Compile:        truffle compile
  Migrate:        truffle migrate
  Test contracts: truffle test

+ echo 'module.exports = { compilers: { solc: { version: "0.4.8" } } }'
+ echo 'contract Test { }'
+ cat -
+ truffle test
Compiling ./contracts/Migrations.sol...
Compiling ./contracts/Test.sol...

Compilation warnings encountered:

/Users/pieter/test/test/contracts/Migrations.sol:1:1: Warning: Source file does not specify required compiler version!Consider adding "pragma solidity ^0.4.8
contract Migrations {
^
Spanning multiple lines.
,/Users/pieter/test/test/contracts/Test.sol:1:1: Warning: Source file does not specify required compiler version!Consider adding "pragma solidity ^0.4.8
contract Test { }
^
Spanning multiple lines.

TypeError: Cannot read property 'legacyAST' of undefined
    at /Users/pieter/node_modules/truffle/build/webpack:/packages/truffle-compile/index.js:200:1
    at Array.forEach (<anonymous>)
    at /Users/pieter/node_modules/truffle/build/webpack:/packages/truffle-compile/index.js:187:1
    at Array.forEach (<anonymous>)
    at supplier.load.then.solc (/Users/pieter/node_modules/truffle/build/webpack:/packages/truffle-compile/index.js:184:1)
Truffle v5.0.2 (core: 5.0.2)
Node v10.15.0

Environment

  • Operating System: Darwin Kernel Version 18.2.0
  • Ethereum client: built into truffle
  • Truffle version (truffle version): v5.0.2 (core: 5.0.2)
  • node version (node --version): v10.15.0
  • npm version (npm --version): 6.4.1
@gnidan

This comment has been minimized.

Copy link
Member

commented Jan 30, 2019

Thanks for raising this issue.

Would it be possible for you to upgrade Solidity versions?

It's a challenge to continue supporting these old versions of solc, and I am hesitant to suggest doing so because of outstanding bugs present in these older versions.

We will continue to try to find a balance between supporting older versions while maintaining forward momentum. Let us know if you are blocked from being able to upgrade and we can consider next steps. Thank you!

@pieterhartel

This comment has been minimized.

Copy link
Author

commented Jan 31, 2019

Dear Gnidan,

Thank you for your suggestion to avoid the problem by upgrading solc. However, that won't work for me because I am trying to as it were to "recreate history". For my research I re-compile smart contracts with the same compiler version that was used to generate the binary deployed on the mainnet. I gather this information from etherscan. See for example the contract Vitaluck at [https://etherscan.io/address/0xef7c7254c290df3d167182356255cdfd8d3b400b#code]. This was compiled with v0.4.19, so I want to re-compile with the same version and deploy it in my testnet for further analysis.

Could you please fix "truffle-compile" so that it does not throw an exception, but instead sets legacyAST to a value that at least allows the truffle test to finish?

--pieter

@gnidan

This comment has been minimized.

Copy link
Member

commented Jan 31, 2019

@pieterhartel Ah, my apologies, I forgot about that use case.

It's a bit trickier than you propose because truffle-compile's profiler needs that AST. We would have to skip the profiling in this situation.

There are likely to be other incompatibilities, though, e.g. with Solidity tests. We are notionally working towards supporting multiple compiler versions at the same time, so this compatibility work would naturally fall into that effort.

In the meantime, if you feel like pursuing a fix yourself, please feel free to open a PR! The Truffle team's time is going to be limited this week and next, so we won't likely be able to get to these kinds of compatibility fixes until after that.

Thank you!

@pieterhartel

This comment has been minimized.

Copy link
Author

commented Feb 1, 2019

Dear @gnidan thanks for your feedback. I hope that it will be possible for the Truffle team to fix TypeError exception problem soonish.

--pieter

@dennymrh

This comment has been minimized.

Copy link

commented Mar 13, 2019

Hi @pieterhartel, I have the same issue as you. Have you gotten this issue fixed?

@pieterhartel

This comment has been minimized.

Copy link
Author

commented Mar 13, 2019

@dennymrh no, sorry I have not had the time to look into this, but I am still very much interested in a fix.

@dennymrh

This comment has been minimized.

Copy link

commented Mar 13, 2019

@pieterhartel Thank you for your response, is there any way to run solidity 0.4.4 with the current truffle?

@pieterhartel

This comment has been minimized.

Copy link
Author

commented Mar 13, 2019

@dennymrh I tried most of the old versions to no avail. Only 0.4.9 and up work.

@gnidan

This comment has been minimized.

Copy link
Member

commented Mar 20, 2019

So naturally legacyAST used to be called just ast. Next step here might be to update truffle-compile to detect the Solidity version and populate the artifact's legacyAST with ast in the appropriate situation.

This will mean that we won't have the artifact's ast property filled, since solc 0.4.8 won't generate that. But that will only prevent debugging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.