Comments (12)
@kronosapiens Unfortunately the ganache support in the code is potemkin and exists because the test suite continues to use it (scheduled for removal in #839). The docs are out of date - solidity-coverage stopped working with the most recent major version of ganache and now it's deprecated.
Is it possible to run solidity-coverage against a generic RPC node? In our case, an instance of npx hardhat node, but potentially anything.
Could you give an example in the Colony code where you were doing this so I can understand how it might be replicated?
from solidity-coverage.
Here's an example of pointing an accessory service to the RPC node.
It seems like in this case, generalizing the handling of external nodes would be a sufficient solution. Mimicking how Hardhat itself handles the --network
flag might sort it, using that to pull up the hardhat.config.js
network information and setting up a provider based off of that.
from solidity-coverage.
Great, that's perfect. Will look into this....
from solidity-coverage.
@cgewecke thanks for that. Looks like the solution of having two in-process providers isn't quite what we need, but your idea of implementing a coverage-compliant external node is something I'll keep looking into. Talking to Alex, it seems like the previous in-process Ganache provider accepted external RPC calls, so it might not be as simple as I'd hoped to migrate that behavior over to Hardhat.
from solidity-coverage.
@cgewecke turns out it wasn't as hard as we'd feared to make the in-process node available externally. Alex came up with this workaround which has been serving us just fine:
task("coverage", "Run coverage with an open port").setAction(async () => {
const app = express();
const port = 8555;
app.use(bodyParser.json());
app.post("/", async function (req, res) {
const response = await hre.network.provider.request(req.body);
res.send({ jsonrpc: "2.0", result: response, id: req.body.id });
});
app.listen(port, function () {
console.log(`Exposing the provider on port ${port}!`);
});
await runSuper();
});
from solidity-coverage.
@kronosapiens Wow, nice! I thought it would be a lot harder than that 😄
from solidity-coverage.
We are essentially doing this:
npx hardhat node & npx hardhat test --network localhost
I'd like to be able to do something similar with coverage, along the lines of
npx hardhat node --port 8555 & npx hardhat coverage --network coverage
Assuming the coverage
network is properly defined in hardhat.config.js
. Looking at the coverage code, it seems like the branch only considers in-process hardhat nodes or external Ganache clients. Seems like the culprit is right around here, since the external node returns false
for that flag (or at least that's what I think is going on).
from solidity-coverage.
@kronosapiens Ok. Ganache was also always launched "in-process" here but it listens on a port like a server
Line 185 in fbed395
Am going to have to look at the Hardhat code more closely to what can be done here to support this. If you could show me an example of an "inter-process RPC call to an external Ethereum node" it would help to build a test case here.
from solidity-coverage.
@kronosapiens I've made a sample project which shows how you can have two blockchains available in the unit tests here:
https://github.com/cgewecke/multi-provider-hardhat-example
These are two chains in the same process, instead of IPC. Hardhat's default network client (the one solidity-coverage hijacks) doesn't listen on a port and accept outside calls.
It's also conceivable that you could roll your own coverage-enabled standalone hardhat node by:
- using the solidity-coverage API and
- overloading the task defined in hardhat's built-in
node
task
from solidity-coverage.
@cgewecke thanks for looking into this! I can't view your repo, is it private?
from solidity-coverage.
@kronosapiens Yes ....it was, really sorry. It's public now.
from solidity-coverage.
There's an example of using the second blockchain in the final test in the test file.
from solidity-coverage.
Related Issues (20)
- Small docs Improvements
- Unskip stack-too-deep unit test HOT 1
- Try/Catch should be treated as branch
- 0% coverage when using hardhat-foundry & foundry.toml is present HOT 15
- Add tests for file level function declarations
- feature: track config state in Hardhat cache
- Tracking Issue: using viaIR in versions >= 0.8.7 HOT 2
- Branch coverage decreases after upgrading to 0.8.7 HOT 10
- Verify skipFiles works as expected when using hardhat-foundry HOT 3
- Line Coverage Decreases in v0.8.9 + viaIR=true HOT 9
- Error: Bytecode is not a valid hex string using OZ upgrades deployProxy HOT 4
- Tests Fail when using `hardhat-viem` plugin HOT 5
- zkSync Support HOT 8
- Coverage missing when using solc v0.4.x HOT 2
- Fix zeppelin in CI
- EISDIR error when `paths.sources` directory name contains `.` HOT 2
- Compilation failure when whitespace between `require` and terminating semi-colon HOT 2
- Getting 0% coverage results HOT 2
- Compilation fails when return type is a function HOT 2
- Support for Cobertura XML output HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from solidity-coverage.