-
Notifications
You must be signed in to change notification settings - Fork 12k
Support testing with an in-process ethereum provider #1918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hello @cgewecke! We of course will want to try out the new |
Hi @nventuro!
Good question! An in-process ganache lets us access the VM directly and listen to a "step" event it emits each time an opcode is run. Solidity-coverage instruments contracts with statements which push a bytes32 data hash onto the evm stack. By watching the evm step we can detect the hash and mark it as a line or branch hit in a coverage map. We need to collect opcode trace data for both 0xProject's trace tools get around this restriction by replaying Using an in-process provider tries to avoid that complexity... fwiw it should be possible to adapt SC's design to work with a client like Parity which supports both traceTransaction and traceCall, although filtering might be necessary there as well.
It is strongly decoupled from Truffle. When the new version is released it will be available as both a Buidler and Truffle plugin and the API should allow integration with any JS ethereum dev stack or build process. |
(this is mostly me being curious) Ohh, I see. And I'm guessing it is not possible to listen to edit: to clarify, I'm asking because there are instances where we find it valuable to run tests on a standalone ganache instance, and want to see if there is a way to no drop that capability. |
Like a websocket subscription or something? That would be really cool and has been proposed at ganache but not sure what its status is.
I am curious about this - that seems very important. What do you see as the differences between in-process and standalone? The exposed API will be something like the
|
Right, it technically wouldn't need to go over the network since it's running on the same machine, but that would work.
My main use case is while debugging: I run some tests (a subset of them) on a standalone ganache, and then connect to it (e.g. via |
It seems to me though that it should be possible to have a sort of 'coverage-node', a stand-alone process that wraps ganache and exposes the |
I have to think about this a bit... some of the redesign goals are that the tool is :
The coverage API is trying to limit its concerns to rewriting solidity files, storing them in a pre-defined temporary folder and attaching to the client to get a trace. How the user compiles and tests, and which client version they use is ideally up to their tooling.
Just making a note here ... in your model :
Does that seem right? Very specifically for truffle I think it might be possible to point the console at a network that uses an in-process provider, run the However you've raised a really important use case - will think about this further... |
Pretty much, yes. I assume by 'consume a ganache' you mean that it is launched from within node? Also, from my shallow understanding of the matter, we wouldn't have to do anything special to handle the 'call forwarding'. Sorry to have thwarted your plans! 😅 |
@nventuro Maybe I am misunderstanding but to me this seems a little complicated - a special server wrapper around the provider (which supports http + websockets) and which has to be launched separately for coverage. This is similar to the current approach but I've been thinking it's preferable not to have a different client for every task (e.g normal test, test w/ coverage). I actually really don't want to do what you're proposing ha ha!! It's simpler to handle as much as possible in the same process & memory as the tests. However I just remembered that Oraclize has that bridge and is a case similar to your GSN deployer. So in-process is definitely a problem for some very important testing contexts.... |
Also for clarification, the way we need to access the vm trace is a little tortured. It has to be in memory and the attachment step looks something like this... const self = this;
const provider = ganache.provider(options);
const blockchain = provider.engine.manager.state.blockchain;
const createVM = blockchain.createVMFromStateTrie;
// Attach to VM which ganache has already instantiated and
// which it uses to execute eth_send
blockchain.vm.on('step', self.collector.step.bind(self.collector));
// Hijack createVM method which ganache uses to run eth_calls
blockchain.createVMFromStateTrie = function(state, activatePrecompiles) {
const vm = createVM.apply(blockchain, arguments);
vm.on('step', self.collector.step.bind(self.collector));
return vm;
} |
To be fair, I don't think you need to: from our discussion here and my understanding of the proposed API it seems to me like it shouldn't be hard to get By the way, I just realized I never replied to the GSN deployment bit: that'll be a non-issue, our gsn-helpers already support being called from JavaScript directly, so that migration will be simple. |
Ok well you've persuaded me this is likely necessary anyway. If you'd like to collaborate in some way I'd be very happy to. |
@nventuro Thanks so much for your advice in this thread - incredibly helpful. Have now modified solidity-coverage to run ganache as an http server and added async hook options that allow the user to launch whatever external processes they want and connect to the coverage server as required. Have opened #1923 upgrading solidity-coverage using this approach for GSN. It's not exactly what you suggested but it preserves the stand-alone server launch for regular tests. . . Closing in favor #1923. |
Uh oh!
There was an error while loading. Please reload this page.
🧐 Motivation
solidity-coverage is being rewritten so that it has fewer quirks and problems. One element of the new design is that it listens to the ethereumjs-vm opcode step emitter of an in-process ganache instance. In Truffle terms, it runs on a network which looks like:
Have been testing it on Zeppelin and the only issue is that some GSN tests rely on an oz-gsn utility run in test.sh which connects to ganache-cli as a stand-alone server.
I'm wondering if anyone has any views are about moving away from
test.sh
towards an in-process provider approach.I think the main changes this would involve are:
Pros
Cons/Caveats
Happy to help with PRs etc if this is something you're interested in.
The text was updated successfully, but these errors were encountered: