Giter Club home page Giter Club logo

Comments (12)

cgewecke avatar cgewecke commented on August 15, 2024 1

@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.

kronosapiens avatar kronosapiens commented on August 15, 2024 1

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.

cgewecke avatar cgewecke commented on August 15, 2024 1

Great, that's perfect. Will look into this....

from solidity-coverage.

kronosapiens avatar kronosapiens commented on August 15, 2024 1

@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.

kronosapiens avatar kronosapiens commented on August 15, 2024 1

@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.

cgewecke avatar cgewecke commented on August 15, 2024 1

@kronosapiens Wow, nice! I thought it would be a lot harder than that 😄

from solidity-coverage.

kronosapiens avatar kronosapiens commented on August 15, 2024

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.

cgewecke avatar cgewecke commented on August 15, 2024

@kronosapiens Ok. Ganache was also always launched "in-process" here but it listens on a port like a server

await pify(this.server.listen)(this.port);

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.

cgewecke avatar cgewecke commented on August 15, 2024

@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:

from solidity-coverage.

kronosapiens avatar kronosapiens commented on August 15, 2024

@cgewecke thanks for looking into this! I can't view your repo, is it private?

from solidity-coverage.

cgewecke avatar cgewecke commented on August 15, 2024

@kronosapiens Yes ....it was, really sorry. It's public now.

from solidity-coverage.

cgewecke avatar cgewecke commented on August 15, 2024

There's an example of using the second blockchain in the final test in the test file.

from solidity-coverage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.