Solidity-coverage: Fail to find node_module dependencies

Created on 13 Sep 2018  路  5Comments  路  Source: sc-forks/solidity-coverage

I have a contract that "extends" open-zeppelin one from node modules like:

pragma solidity ^0.4.24;

import "../node_modules/openzeppelin-solidity/contracts/token/ERC20/MintableToken.sol";

contract MyToken is MintableToken {
  ...
}

But when I run npm run coverage, for the standard script SOLIDITY_COVERAGE=true ./node_modules/.bin/solidity-coverage, I get:

SOLIDITY_COVERAGE=true ./node_modules/.bin/solidity-coverage

Generating coverage environment
Running: truffle compile  
(this can take a few seconds)...
Error: Could not find MYPATH/coverageEnv/node_modules/openzeppelin-solidity/contracts/token/ERC20/MintableToken.sol from any sources; imported from /MYPATH/coverageEnv/contracts/MyToken.sol
    at /home/user/.nvm/versions/node/v8.11.1/lib/node_modules/truffle/build/webpack:/packages/truffle-resolver/index.js:76:1
    at /home/user/.nvm/versions/node/v8.11.1/lib/node_modules/truffle/build/webpack:/~/async/internal/onlyOnce.js:12:1
    at next (/home/user/.nvm/versions/node/v8.11.1/lib/node_modules/truffle/build/webpack:/~/async/whilst.js:68:1)
    at /home/user/.nvm/versions/node/v8.11.1/lib/node_modules/truffle/build/webpack:/packages/truffle-resolver/index.js:64:1
    at /home/user/.nvm/versions/node/v8.11.1/lib/node_modules/truffle/build/webpack:/packages/truffle-resolver/fs.js:85:1
    at /home/user/.nvm/versions/node/v8.11.1/lib/node_modules/truffle/build/webpack:/~/async/internal/once.js:12:1
    at replenish (/home/user/.nvm/versions/node/v8.11.1/lib/node_modules/truffle/build/webpack:/~/async/internal/eachOfLimit.js:61:1)
    at iterateeCallback (/home/user/.nvm/versions/node/v8.11.1/lib/node_modules/truffle/build/webpack:/~/async/internal/eachOfLimit.js:50:1)
    at /home/user/.nvm/versions/node/v8.11.1/lib/node_modules/truffle/build/webpack:/~/async/internal/onlyOnce.js:12:1
    at ReadFileContext.callback (/home/user/.nvm/versions/node/v8.11.1/lib/node_modules/truffle/build/webpack:/packages/truffle-resolver/fs.js:81:1)
ls: no such file or directory: ./coverageEnv/build/contracts/*.json

And then it just hangs for ever doing:

Instrumenting  ./coverageEnv/contracts/MyToken.sol

Any thought on this? Thanks in advance!

All 5 comments

@jmendiola222 Could you see if the crash goes away if you write the import line like this?

import "openzeppelin-solidity/contracts/token/ERC20/MintableToken.sol";

Yes @cgewecke that actually removed the error (even if now I get the solium linting error), but seems that the hanging issue has not related with this error, because it still hangs while "Instrumenting" one of my contracts.
Is there a --verbose option I could use to see in more detail were it does actually hangs?

@jmendiola222 We're having some issues instrumenting contracts that have large numbers of view/pure functions or many conditional statements with unbracketed bodies like this:

if (x > 0) y = 5;

The algorithm for instrumenting is inefficient - it just takes a long time. Happy to take a look at your project if it's open-source to see if there's any obvious way of speeding it up.

Working on this problem this week at the preprocessor-improvements branch.

No @cgewecke, the project is not yet open-source, we'll look forward to future improvements then and check if future versiones solve our issue.
Update: After about an hour, I got this output:

Writing artifacts to ./build/contracts

Cleaning up...
Cleaning up...
Shutting down testrpc-sc (pid 1825)
Done.
fs.js:646
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^

Error: ENOENT: no such file or directory, open 'MYPATH/coverageEnv/installed_contracts/oraclize-api/contracts/usingOraclize.sol'
    at Object.fs.openSync (fs.js:646:18)
    at Object.fs.writeFileSync (fs.js:1299:33)
    at shell.ls.filter.forEach.file (MYPATH/node_modules/solidity-coverage/lib/app.js:191:14)
    at Array.forEach (<anonymous>)
    at App.instrumentTarget (MYPATH/node_modules/solidity-coverage/lib/app.js:178:8)
    at Object.<anonymous> (MYPATH/node_modules/solidity-coverage/bin/exec.js:14:5)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
fs.js:646
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^

Error: ENOENT: no such file or directory, open 'MYPATH/coverageEnv/installed_contracts/oraclize-api/contracts/usingOraclize.sol'
    at Object.fs.openSync (fs.js:646:18)
    at Object.fs.writeFileSync (fs.js:1299:33)
    at shell.ls.filter.forEach.file (MYPATH/node_modules/solidity-coverage/lib/app.js:191:14)
    at Array.forEach (<anonymous>)
    at App.instrumentTarget (MYPATH/node_modules/solidity-coverage/lib/app.js:178:8)
    at Object.<anonymous> (MYPATH/node_modules/solidity-coverage/bin/exec.js:14:5)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)

Removing usingOraclize.sol (wich we not longer have as a dependency) from installed_contracts forder solved the issue. Now the coverage works. :tada:

Hope this error helps you on your speeding quest. :smile:

Thanks!

@jmendiola222 Ah ok yes, Oraclize is a known problem... Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BrendanChou picture BrendanChou  路  6Comments

jo-es picture jo-es  路  6Comments

FreshmanQ picture FreshmanQ  路  4Comments

alsco77 picture alsco77  路  6Comments

matthiasgeihs picture matthiasgeihs  路  3Comments