Solidity

用松露執行solidity-coverage會出錯:找不到’coverageEnv/migrations'

  • February 12, 2022

執行solidity-coverage 會出現以下錯誤:

$npm run coverage
...
Writing artifacts to ./build/contracts


Launched testrpc on port 8555
Running: node --max-old-space-size=4096 ../node_modules/.bin/truffle test --network coverage ../tests/test0.js
(this can take a few seconds)...
Using network 'coverage'.

Error: ENOENT: no such file or directory, stat '/Users/solo/git/my-contract/coverageEnv/migrations'
Cleaning up...
Shutting down testrpc-sc (pid 5715)
Event trace could not be read.
Error: ENOENT: no such file or directory, open './allFiredEvents'
Exiting without generating coverage...
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-contract@0.0.1 coverage: `solidity-coverage`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-contract@0.0.1 coverage script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/solo/.npm/_logs/2018-10-07T17_16_27_017Z-debug.log

.solcover.js

module.exports = {
   copyPackages: ['zeppelin-solidity'],
   compileCommand: 'node --max-old-space-size=4096 ../node_modules/.bin/truffle compile --network coverage',
   testCommand: 'node --max-old-space-size=4096 ../node_modules/.bin/truffle test --network coverage ../tests/test0.js',
   port: '8555',
   skipFiles: []
};

松露配置:…

module.exports = {
 networks: {
   ...
   coverage: {
     host: 'localhost',
     network_id: '*', // eslint-disable-line camelcase
     port: 8555,
     gas: 0xfffffffffff,
     gasPrice: 0x01,
   }
 },
};

執行 testrpc 和手動測試就可以了。但是當使用solidity-coverage 執行時,由於某種原因它無法migrationscoverageEnv.

任何指示將不勝感激。謝謝!

編輯:

雖然可能有更優雅的方法來修復它,但我設法通過複製遷移腳本作為 testCommand 的一部分來解決這個問題:testCommand: 'cp -a ../migrations ../coverageEnv && node --max-old-space-size=4096 ../node_modules/.bin/truffle test --network coverage ../tests/test0.js',

Solidity-coverage 根據您的文件夾目錄創建一個臨時目錄,我建議將您的測試命令更改為您的測試目錄的路徑,而不是特定文件。

通常我使用 openzeppelin-solidity 而不是 zeppelin-solidity。

你的文件目錄是什麼樣的?

在文件中.solcover.js

  1. 更改zeppelin-solidityopenzeppelin-solidity
  2. 更改.bin/truffletruffle/build/cli.bundled.js(2 次出現)

引用自:https://ethereum.stackexchange.com/questions/60126