Solidity-coverage: "TypeError: Cannot read property 'length' of undefined" on MetaCoin truffle box

Created on 30 Oct 2020  ·  6Comments  ·  Source: sc-forks/solidity-coverage

Hi!
I'm unable to test coverage on the MetaCoin Truffle sample project. Here are the steps to reproduce

$ mkdir MetaCoin
$ cd MetaCoin
$ truffle unbox metacoin
[...]
$ vim truffle-config.js # this is for adding the solidity-coverage plugin
$ npm install --save-dev solidity-coverage
[...]
$ truffle run coverage
- Fetching solc version list from solc-bin. Attempt #1

> Using Truffle library from global node_modules.

> server:            http://127.0.0.1:8555
> truffle:           v5.1.42
> ganache-core:      v2.11.2
> solidity-coverage: v0.7.11

Network Info
============
> id:      *
> port:    8555
> network: soliditycoverage


Instrumenting for coverage...
=============================

> ConvertLib.sol
> MetaCoin.sol

Coverage skipped for:
=====================

> Migrations.sol

Compiling your contracts...
===========================
> Compiling ./.coverage_contracts/ConvertLib.sol
> Compiling ./.coverage_contracts/MetaCoin.sol
> Compiling ./.coverage_contracts/Migrations.sol
TypeError: Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined

/Users/diegoll/.config/truffle/compilers/node_modules/soljson-v0.5.16+commit.9c3226ce.js:1
[...]
abort(TypeError: Cannot read property 'length' of undefined). Build with -s ASSERTIONS=1 for more info.
(Use `node --trace-uncaught ...` to show where the exception was thrown)

All 6 comments

Hi @diega I wasn't able to reproduce this.

I ran:

npm install --save-dev [email protected]
npm install --save-dev solidity-coverage
truffle unbox metacoin --force

My system:

  • MacOSX
  • Node v12.16.0

...and got the output below. Do you see any relevant differences between these?

Users-MacBook-Air:tr-sc cgewecke$ npx truffle run coverage

> Using Truffle library from local node_modules.

> server:            http://127.0.0.1:8555
> truffle:           v5.1.42
> ganache-core:      v2.11.2
> solidity-coverage: v0.7.11

Network Info
============
> id:      *
> port:    8555
> network: soliditycoverage


Instrumenting for coverage...
=============================

> ConvertLib.sol
> MetaCoin.sol

Coverage skipped for:
=====================

> Migrations.sol

Compiling your contracts...
===========================
> Compiling ./.coverage_contracts/ConvertLib.sol
> Compiling ./.coverage_contracts/MetaCoin.sol
> Compiling ./.coverage_contracts/Migrations.sol
> Artifacts written to /Users/cgewecke/code/tr-sc/.coverage_artifacts/contracts
> Compiled successfully using:
   - solc: 0.5.16+commit.9c3226ce.Emscripten.clang

⚠️  This plugin cannot run Truffle's native solidity tests: 1 test(s) will be skipped.


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



  Contract: MetaCoin
    ✓ should put 10000 MetaCoin in the first account (56ms)
    ✓ should call a function that depends on a linked library (102ms)
    ✓ should send coin correctly (245ms)


  3 passing (466ms)

-----------------|----------|----------|----------|----------|----------------|
File             |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
-----------------|----------|----------|----------|----------|----------------|
 contracts/      |       90 |       50 |      100 |      100 |                |
  ConvertLib.sol |      100 |      100 |      100 |      100 |                |
  MetaCoin.sol   |    88.89 |       50 |      100 |      100 |                |
-----------------|----------|----------|----------|----------|----------------|
All files        |       90 |       50 |      100 |      100 |                |
-----------------|----------|----------|----------|----------|----------------|

> Istanbul reports written to ./coverage/ and ./coverage.json
> solidity-coverage cleaning up, shutting down ganache server

well, the main difference I can see is that mine says
> Using Truffle library from global node_modules.
and yours
> Using Truffle library from local node_modules.

I have truffle installed globally as they recommend and I run all commands through npx (omitted in my original report I don't know why).
Bellow is my global _truffle_ report but that's not the same version shown in the output of the npx truffle run coverage command

$ npx truffle version
- Fetching solc version list from solc-bin. Attempt #1
Truffle v5.1.51 (core: 5.1.51)
Solidity v0.5.16 (solc-js)
Node v12.18.3
Web3.js v1.2.9

having that said, installing truffle locally with the npm install --save-dev [email protected] command that you provided, made it work (also for v5.1.51) and after running that command I can see the same Using Truffle library from local node_modules message as yours

Ah yes! Will investigate...

I triggered this once but now I can't figure out which combination causes it. When it happened I was running truffle as a global command and also had truffle installed as a local dev dep.

Using a globally installed Truffle (without locally installed Truffle) seems to work with both npx and just truffle.

Perhaps it's something about how Truffle resolves the compiler cache globally / locally? Tbh don't think solidity-coverage will be able to fix this...it might be an obscure bug that affects any plugin that runs the compile command.

yes, It's quite possible. I've also found out that npx may have its own version of the libraries installed under ~/.npm/_npx.
Feel free to close this issue, at least I can confirm the workaround of using the locally the --save-dev local version works fine

Ok interesting, sounds good. This issue should be easily discoverable for anyone running into the same problem...

Thanks for reporting!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matthiasgeihs picture matthiasgeihs  ·  3Comments

cgewecke picture cgewecke  ·  6Comments

alsco77 picture alsco77  ·  6Comments

FreshmanQ picture FreshmanQ  ·  4Comments

fabianorodrigo picture fabianorodrigo  ·  6Comments