Solidity: Truffle fails while processing JSON output because of the missing `deployedGeneratedSources.ast.nodes` key

Created on 7 Oct 2020  Â·  4Comments  Â·  Source: ethereum/solidity

Description

I am running truffle test on some contracts and the truffle tests are failing with 0.7.2+ but pass with 0.7.1.

The example I am using is the same as the one from #9974.

Running truffle with 0.7.1 succeeds with

$ truffle test

Compiling your contracts...
===========================
> Compiling ./contracts/Migrations.sol
> Compiling ./contracts/Test.sol
> Artifacts written to /var/folders/3h/8n83hkk15kn72vl2_8bsw18c0000gp/T/test--53322-2ngFO246D7yd
> Compiled successfully using:
   - solc: 0.7.1+commit.f4a555be.Emscripten.clang



  Contract: All
    ✓ Test (44ms)


  1 passing (64ms)

While running with 0.7.2+ fails with

$ truffle test

Compiling your contracts...
===========================
> Compiling ./contracts/Migrations.sol
> Compiling ./contracts/Test.sol
> Compilation warnings encountered:

    Warning: This is a pre-release compiler version, please do not use it in production.

> Artifacts written to /var/folders/3h/8n83hkk15kn72vl2_8bsw18c0000gp/T/test--53352-tjf1g2K6ZZ8d
> Compiled successfully using:
   - solc: 0.7.3-develop.2020.10.7+commit.9bfce1f6.Darwin.appleclang



  Contract: All
    1) "before all" hook: prepare suite for "Test"


  0 passing (11ms)
  1 failing

  1) Contract: All
       "before all" hook: prepare suite for "Test":
     TypeError: ast.nodes is not iterable
      at WireDecoder.collectUserDefinedTypes (/Users/dejan/.nvm/versions/node/v12.18.4/lib/node_modules/truffle/build/webpack:/packages/decoder/dist/decoders.js:130:1)
      at new WireDecoder (/Users/dejan/.nvm/versions/node/v12.18.4/lib/node_modules/truffle/build/webpack:/packages/decoder/dist/decoders.js:101:10)
      at Object.<anonymous> (/Users/dejan/.nvm/versions/node/v12.18.4/lib/node_modules/truffle/build/webpack:/packages/decoder/dist/index.js:187:1)
      at Generator.next (<anonymous>)
      at /Users/dejan/.nvm/versions/node/v12.18.4/lib/node_modules/truffle/build/webpack:/packages/decoder/dist/index.js:145:1
      at new Promise (<anonymous>)
      at __awaiter (/Users/dejan/.nvm/versions/node/v12.18.4/lib/node_modules/truffle/build/webpack:/packages/decoder/dist/index.js:141:1)
      at Object.forProject (/Users/dejan/.nvm/versions/node/v12.18.4/lib/node_modules/truffle/build/webpack:/packages/decoder/dist/index.js:185:1)
      at TestRunner.initialize (/Users/dejan/.nvm/versions/node/v12.18.4/lib/node_modules/truffle/build/webpack:/packages/core/lib/testing/TestRunner.js:67:1)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
      at Context.<anonymous> (/Users/dejan/.nvm/versions/node/v12.18.4/lib/node_modules/truffle/build/webpack:/packages/core/lib/test.js:336:1)

I really don't know how to debug this further (not a JS expert).

Environment

truffle version $ truffle version Truffle v5.1.47 (core: 5.1.47) Solidity - native (solc-js) Node v12.18.4 Web3.js v1.2.1

solidity versions: 0.7.3, 0.7.2, 0.7.1

Steps to Reproduce

Download a small truffle project from here, then

  1. Edit truffle-config.js and set version: "0.7.1". Run truffle test, this one should pass.
  2. Edit truffle-config.js and set version: "0.7.2". This truffle test, this one should fail.
  3. Edit truffle-config.js and set version: "native". This one uses a compiled 0.7.3 binary in the path, and should also fail.
bug should compile without error

All 4 comments

I tracked it down. The issue is that Truffle expects to find a nodes key inside deployedGeneratedSources.ast. If it's not there or is not iterable, it fails.

deployedGeneratedSources is a new feature added in 0.7.2 (see #8807/#9053). Now, I don't know enough about the feature to tell if that key should be there or if Trufle should just not expect it and assume [] if it's not there.
@chriseth, @haltman-at?

Details

Minimal repro

Assumes that Truffle is installed and uses solc 0.7.3 that it downloads from solc-bin:

truffle init

cat << EOF > test/All.js
contract('All', function(accounts) {
  it('Test');
});
EOF

cat << EOF > contracts/Test.sol
pragma experimental ABIEncoderV2;

contract Test {
    function foo(uint[1] memory) public {}
}
EOF

cat << EOF > truffle-config.js
module.exports = {
  compilers: {
    solc: {
      version: "0.7.3"
    }
  }
}
EOF

truffle test

Adding empty nodes

Just adding an empty nodes array to the json files stored by Truffle as compilation output silences the error:

truffle compile
mv build/contracts/Test.json Test-no-ast-nodes.json
cat Test-no-ast-nodes.json | jq '.deployedGeneratedSources[0].ast.nodes = []' > build/contracts/Test.json Test-no-ast-nodes.json
truffle test
Using network 'test'.


Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.



  Contract: All
    - Test


  0 passing (19ms)
  1 pending

Hi, this would definitely seem to be a Truffle issue. Would you mind opening an issue over on Truffle and I'll take a look at it there? Thanks!

@dddejan The bug has been fixed in Truffle (https://github.com/trufflesuite/truffle/issues/3419). I have tested a new version from develop with your snippet and it works for me so I'm closing the issue. Please check it with your contract and feel free to reopen either this issue or the one in Truffle if you find there are still some problems with Solidity or Truffle respectively. Or start a new one if it's something unrelated.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

leviadam picture leviadam  Â·  4Comments

kkagill picture kkagill  Â·  4Comments

chriseth picture chriseth  Â·  4Comments

ddeclerck picture ddeclerck  Â·  3Comments

axic picture axic  Â·  3Comments