sc-forks / solidity-coverage

Code coverage for Solidity smart-contracts
MIT License
977 stars 264 forks source link

Error: Invalid JSON RPC response: "" when using Truffle #634

Closed David-Kneel closed 3 years ago

David-Kneel commented 3 years ago

When run truffle run coverage, the expectRevert command results in a failure.

❯ yarn coveralls
yarn run v1.22.10
$ yarn coverage && cat coverage/lcov.info | coveralls
$ truffle run coverage

> Using Truffle library from local node_modules.

> server:            http://127.0.0.1:8555
> truffle:           v5.3.6
> ganache-core:      v2.13.0
> solidity-coverage: v0.7.16

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

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

> abdk-libraries-solidity/ABDKMath64x64.sol
> abdk-libraries-solidity/ABDKMathQuad.sol
> YieldFarming.sol
> YieldFarmingToken.sol

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

> Migrations.sol

Compiling your contracts...
===========================
✔ Fetching solc version list from solc-bin. Attempt #1
> Compiling ./.coverage_contracts/Migrations.sol
> Compiling ./.coverage_contracts/YieldFarming.sol
> Compiling ./.coverage_contracts/YieldFarmingToken.sol
> Compiling ./.coverage_contracts/abdk-libraries-solidity/ABDKMath64x64.sol
> Compiling ./.coverage_contracts/abdk-libraries-solidity/ABDKMathQuad.sol
> Compiling @openzeppelin/contracts/access/Ownable.sol
> Compiling @openzeppelin/contracts/token/ERC20/ERC20.sol
> Compiling @openzeppelin/contracts/token/ERC20/IERC20.sol
> Compiling @openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol
> Compiling @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol
> Compiling @openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol
> Compiling @openzeppelin/contracts/token/ERC20/utils/TokenTimelock.sol
> Compiling @openzeppelin/contracts/utils/Address.sol
> Compiling @openzeppelin/contracts/utils/Context.sol
✔ Fetching solc version list from solc-bin. Attempt #1
> Artifacts written to /home/daniel/Workspaces/Tachyonic/Personal/faster-than-light/.coverage_artifacts/contracts
> Compiled successfully using:
   - solc: 0.8.4+commit.c7e474f2.Emscripten.clang

Compiling your contracts...
===========================
✔ Fetching solc version list from solc-bin. Attempt #1
> Everything is up to date, there is nothing to compile.

  Contract: YieldFarming
    ✓ Ownership (136ms)
    Release token
      ✓ after unlock (2144ms)

  2 passing (3s)

------------------------------------|----------|----------|----------|----------|----------------|
File                                |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
------------------------------------|----------|----------|----------|----------|----------------|
 contracts/                         |      100 |       50 |      100 |      100 |                |
  YieldFarming.sol                  |      100 |       50 |      100 |      100 |                |
  YieldFarmingToken.sol             |      100 |      100 |      100 |      100 |                |
 contracts/abdk-libraries-solidity/ |      100 |      100 |    15.79 |    15.79 |                |
  ABDKMath64x64.sol                 |      100 |      100 |        0 |        0 |... 659,678,728 |
  ABDKMathQuad.sol                  |      100 |      100 |       30 |       30 |... 66,990,1198 |
------------------------------------|----------|----------|----------|----------|----------------|
All files                           |      100 |       50 |       25 |    33.33 |                |
------------------------------------|----------|----------|----------|----------|----------------|

> Istanbul reports written to ./coverage/ and ./coverage.json
> solidity-coverage cleaning up, shutting down ganache server
Done in 28.92s.
❯ yarn coveralls
yarn run v1.22.10
$ yarn coverage && cat coverage/lcov.info | coveralls
$ truffle run coverage

> Using Truffle library from local node_modules.

> server:            http://127.0.0.1:8555
> truffle:           v5.3.6
> ganache-core:      v2.13.0
> solidity-coverage: v0.7.16

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

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

> abdk-libraries-solidity/ABDKMath64x64.sol
> abdk-libraries-solidity/ABDKMathQuad.sol
> YieldFarming.sol
> YieldFarmingToken.sol

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

> Migrations.sol

Compiling your contracts...
===========================
✔ Fetching solc version list from solc-bin. Attempt #1
> Compiling ./.coverage_contracts/Migrations.sol
> Compiling ./.coverage_contracts/YieldFarming.sol
> Compiling ./.coverage_contracts/YieldFarmingToken.sol
> Compiling ./.coverage_contracts/abdk-libraries-solidity/ABDKMath64x64.sol
> Compiling ./.coverage_contracts/abdk-libraries-solidity/ABDKMathQuad.sol
> Compiling @openzeppelin/contracts/access/Ownable.sol
> Compiling @openzeppelin/contracts/token/ERC20/ERC20.sol
> Compiling @openzeppelin/contracts/token/ERC20/IERC20.sol
> Compiling @openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol
> Compiling @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol
> Compiling @openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol
> Compiling @openzeppelin/contracts/token/ERC20/utils/TokenTimelock.sol
> Compiling @openzeppelin/contracts/utils/Address.sol
> Compiling @openzeppelin/contracts/utils/Context.sol
✔ Fetching solc version list from solc-bin. Attempt #1
> Artifacts written to /home/daniel/Workspaces/Tachyonic/Personal/faster-than-light/.coverage_artifacts/contracts
> Compiled successfully using:
   - solc: 0.8.4+commit.c7e474f2.Emscripten.clang

Compiling your contracts...
===========================
✔ Fetching solc version list from solc-bin. Attempt #1
> Everything is up to date, there is nothing to compile.

  Contract: YieldFarming
    ✓ Ownership (200ms)
    Release token
      1) before unlock

    Events emitted during test:
    ---------------------------

    Ownable.OwnershipTransferred(
      previousOwner: <indexed> 0x0000000000000000000000000000000000000000 (type: address),
      newOwner: <indexed> 0x8C62793E27cf14e3074be39817F84faabc39c8be (type: address)
    )

    Ownable.OwnershipTransferred(
      previousOwner: <indexed> 0x0000000000000000000000000000000000000000 (type: address),
      newOwner: <indexed> 0x6a4F343faC135136b6482B280df8305B03018F51 (type: address)
    )

    IERC20.Transfer(
      from: <indexed> 0x0000000000000000000000000000000000000000 (type: address),
      to: <indexed> 0x6d0982d6A0f46aE78141cDB761a5455241D4812f (type: address),
      value: 14426950408889 (type: uint256)
    )

    ---------------------------
      ✓ after unlock (2141ms)

  2 passing (5s)
  1 failing

  1) Contract: YieldFarming
       Release token
         before unlock:
     Error: Invalid JSON RPC response: ""
      at Object.InvalidResponse (node_modules/@openzeppelin/test-helpers/node_modules/web3-core-helpers/lib/errors.js:43:16)
      at XMLHttpRequest.request.onreadystatechange (node_modules/@openzeppelin/test-helpers/node_modules/web3-providers-http/lib/index.js:95:32)
      at XMLHttpRequestEventTarget.dispatchEvent (node_modules/xhr2-cookies/xml-http-request-event-target.ts:44:13)
      at XMLHttpRequest._setReadyState (node_modules/xhr2-cookies/xml-http-request.ts:219:8)
      at XMLHttpRequest._onHttpRequestError (node_modules/xhr2-cookies/xml-http-request.ts:379:8)
      at ClientRequest.<anonymous> (node_modules/xhr2-cookies/xml-http-request.ts:266:37)
      at Socket.socketErrorListener (_http_client.js:427:9)
      at emitErrorNT (internal/streams/destroy.js:92:8)
      at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
      at processTicksAndRejections (internal/process/task_queues.js:84:21)

------------------------------------|----------|----------|----------|----------|----------------|
File                                |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
------------------------------------|----------|----------|----------|----------|----------------|
 contracts/                         |      100 |       50 |      100 |      100 |                |
  YieldFarming.sol                  |      100 |       50 |      100 |      100 |                |
  YieldFarmingToken.sol             |      100 |      100 |      100 |      100 |                |
 contracts/abdk-libraries-solidity/ |      100 |      100 |    15.79 |    15.79 |                |
  ABDKMath64x64.sol                 |      100 |      100 |        0 |        0 |... 659,678,728 |
  ABDKMathQuad.sol                  |      100 |      100 |       30 |       30 |... 66,990,1198 |
------------------------------------|----------|----------|----------|----------|----------------|
All files                           |      100 |       50 |       25 |    33.33 |                |
------------------------------------|----------|----------|----------|----------|----------------|

> Istanbul reports written to ./coverage/ and ./coverage.json
> solidity-coverage cleaning up, shutting down ganache server
Error: ❌ 1 test(s) failed under coverage.
    at plugin (/home/daniel/Workspaces/Tachyonic/Personal/faster-than-light/node_modules/solidity-coverage/plugins/truffle.plugin.js:121:27)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
Truffle v5.3.6 (core: 5.3.6)
Node v12.22.1
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

This situation is evidenced in the following GitHub actions run

cgewecke commented 3 years ago

Screen Shot 2021-05-20 at 1 50 25 PM

@David-Kneel I ran this locally and everything worked.

You might try adding the flag below to your network config and see if that helps stabilize things...

module.exports = {
  // ... rest of truffle-config
  networks: {
    "<network-name>": {
      // ... rest of config for <network-name>
      disableConfirmationListener: true
    }
  }
}

From this truffle release: https://github.com/trufflesuite/truffle/releases/tag/v5.1.55

David-Kneel commented 3 years ago

Screen Shot 2021-05-20 at 1 50 25 PM

@David-Kneel I ran this locally and everything worked.

You might try adding the flag below to your network config and see if that helps stabilize things...

module.exports = {
  // ... rest of truffle-config
  networks: {
    "<network-name>": {
      // ... rest of config for <network-name>
      disableConfirmationListener: true
    }
  }
}

From this truffle release: https://github.com/trufflesuite/truffle/releases/tag/v5.1.55

I switched to truffle 5.1.55, then I uncommented the following in truffle-config.js:

    development: {
      disableConfirmationListener: true,
      host: '127.0.0.1', // Localhost (default: none)
      port: 8545, // Standard Ethereum port (default: none)
      network_id: '*' // Any network (default: none)
    }

And still the problem persists locally in my Debian distro within WSL2 and also in CI/CD, Ubuntu LTS 20 distro. By the way, the font that imitating old typing machine you pasted is amaaaaaazing!

cgewecke commented 3 years ago

I'm on OSX.

Could you try creating a network called coverage that just looks like:

coverage: {
  disableConfirmationListener: true
}

... and then running

truffle run coverage --network coverage

... to make sure it picks up the flag?

David-Kneel commented 3 years ago

I'm on OSX.

Could you try creating a network called coverage that just looks like:

coverage: {
  disableConfirmationListener: true
}

... and then running

truffle run coverage --network coverage

... to make sure it picks up the flag?

Sure. This is what happens:

npx truffle run coverage --network coverage

> Using Truffle library from local node_modules.

⚠️  No 'port' was declared in your truffle network. Using solidity-coverage's:  8555.

> server:            http://127.0.0.1:8555
> truffle:           v5.1.55
> ganache-core:      v2.13.0
> solidity-coverage: v0.7.16

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

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

> abdk-libraries-solidity/ABDKMath64x64.sol
> abdk-libraries-solidity/ABDKMathQuad.sol
> YieldFarming.sol
> YieldFarmingToken.sol

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

> Migrations.sol

Compiling your contracts...
===========================
✔ Fetching solc version list from solc-bin. Attempt #1
> Compiling ./.coverage_contracts/Migrations.sol
> Compiling ./.coverage_contracts/YieldFarming.sol
> Compiling ./.coverage_contracts/YieldFarmingToken.sol
> Compiling ./.coverage_contracts/abdk-libraries-solidity/ABDKMath64x64.sol
> Compiling ./.coverage_contracts/abdk-libraries-solidity/ABDKMathQuad.sol
> Compiling @openzeppelin/contracts/access/Ownable.sol
> Compiling @openzeppelin/contracts/token/ERC20/ERC20.sol
> Compiling @openzeppelin/contracts/token/ERC20/IERC20.sol
> Compiling @openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol
> Compiling @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol
> Compiling @openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol
> Compiling @openzeppelin/contracts/token/ERC20/utils/TokenTimelock.sol
> Compiling @openzeppelin/contracts/utils/Address.sol
> Compiling @openzeppelin/contracts/utils/Context.sol
✔ Fetching solc version list from solc-bin. Attempt #1
> Artifacts written to /home/david/Workspaces/Tachyonic/faster-than-light/.coverage_artifacts/contracts
> Compiled successfully using:
   - solc: 0.8.4+commit.c7e474f2.Emscripten.clang

------------------------------------|----------|----------|----------|----------|----------------|
File                                |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
------------------------------------|----------|----------|----------|----------|----------------|
 contracts/                         |        0 |        0 |        0 |        0 |                |
  YieldFarming.sol                  |        0 |        0 |        0 |        0 |... 57,58,59,63 |
  YieldFarmingToken.sol             |        0 |      100 |        0 |        0 |             15 |
 contracts/abdk-libraries-solidity/ |      100 |      100 |        0 |        0 |                |
  ABDKMath64x64.sol                 |      100 |      100 |        0 |        0 |... 659,678,728 |
  ABDKMathQuad.sol                  |      100 |      100 |        0 |        0 |... 6,1198,1211 |
------------------------------------|----------|----------|----------|----------|----------------|
All files                           |        0 |        0 |        0 |        0 |                |
------------------------------------|----------|----------|----------|----------|----------------|

> Istanbul reports written to ./coverage/ and ./coverage.json
> solidity-coverage cleaning up, shutting down ganache server
ProviderError: 
Could not connect to your Ethereum client.
Please check that your Ethereum client:
    - is running
    - is accepting RPC connections (i.e., "--rpc" option is used in geth)
    - is accessible over the network
    - is properly configured in your Truffle configuration file (truffle-config.js)

    at /home/david/Workspaces/Tachyonic/faster-than-light/node_modules/truffle/build/webpack:/packages/provider/wrapper.js:73:1
    at /home/david/Workspaces/Tachyonic/faster-than-light/node_modules/truffle/build/webpack:/packages/provider/wrapper.js:102:1
    at XMLHttpRequest.request.onreadystatechange (/home/david/Workspaces/Tachyonic/faster-than-light/node_modules/truffle/build/webpack:/node_modules/web3/node_modules/web3-providers-http/src/index.js:111:1)
    at XMLHttpRequestEventTarget.dispatchEvent (/home/david/Workspaces/Tachyonic/faster-than-light/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:1)
    at XMLHttpRequest._setReadyState (/home/david/Workspaces/Tachyonic/faster-than-light/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:208:1)
    at XMLHttpRequest._onHttpRequestError (/home/david/Workspaces/Tachyonic/faster-than-light/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:349:1)
    at ClientRequest.<anonymous> (/home/david/Workspaces/Tachyonic/faster-than-light/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:252:47)
    at ClientRequest.emit (events.js:314:20)
    at Socket.socketErrorListener (_http_client.js:427:9)
    at Socket.emit (events.js:314:20)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
Truffle v5.1.55 (core: 5.1.55)
Node v12.22.1
David-Kneel commented 3 years ago

I setup CI/CD to also include MacOS in the operating system matrix. Still the problem is present though. More information here.

cgewecke commented 3 years ago

Got it to work by defining a coverage network that runs on 8545

coverage: {
  host: '127.0.0.1',
  port: 8545,
  network_id: '*'
}

and running truffle run coverage --network coverage

https://github.com/cgewecke/faster-than-light/actions/runs/865087452

(Editing the issue title)