sc-forks / solidity-coverage

Code coverage for Solidity smart-contracts
MIT License
975 stars 263 forks source link

Getting 0% coverage results #886

Closed GitSwarmOrg closed 5 months ago

GitSwarmOrg commented 5 months ago

Reproduction code is on this repository on the solidity-coverage branch: https://github.com/GitSwarmOrg/contracts/tree/solidity-coverage

There are several tests for the Delegates contract implemented that pass so result should be more than 0%.

Getting same result with and without the optimizer or viaIR enabled.

cgewecke commented 5 months ago

@GitSwarmOrg Hi.

The coverage plugin only works if your tests run on the default built-in Hardhat network. You're setting the provider yourself to use a stand-alone localhost client at the top of the test file.

The normal way to use hardhat is to define all networks in hardhat.config.ts and toggle between them using the --network command line flag. If you let hardhat and hardhat-ethers manage provider instantiation and consume it from the hardhat runtime environment imported in the tests as necessary, any other other plugins you're using are more likely to work correctly.

cgewecke commented 5 months ago

Closing for now since this isn't a bug and should be resolved by following the conventions established in the hardhat docs.