-
Notifications
You must be signed in to change notification settings - Fork 58
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
Refactor: Use exvcr to record eth/rootchain network requests #1037
Conversation
When we use the `@tag fixtures:` functionality, it calls out to `DevGeth` and etc ... which will send out a request from Ethereumex to ensure that geth is loaded. This whoever causes the request id to increment and causes all the cassettes to not much when you remove the fixtures call. We explicitly reset the counter before we start the actual interactions in the tests.
Need to reset the :rpc_counter on Ethereuemex so that we can have the exvcr cassettes record it in a predicatble manner(start with id 1)
skipped a few tests due to some issues see comments for more details: * `hasToken` not the ALD contract function anymore * `get_deposits/3` running into output encoding errors
I think the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just some comments first to ramp up, as this is a Draft
for now, but looks good 👍
My biggest concern for now is:
- how do I actually record the cassettes from scratch? There is a section in the PR description, but I'm not sure if this is complete. I'd assume one would need to bypass
exvcr
replaying of cassettes and instead have it record them? How are thejson
files updated in practice - related but a bit separate: how do I just run those tests with
exvcr
entirely bypassed, usinggeth
,parity
(organache
, since it's supported now)?
# The problem is the fixtures would send a first request out(this request). When you remove the fixtures, | ||
# Ethereumex thinks we are sending the first request, missing the matching cassettes by request_body. | ||
# So, we reset the counter so the cassettes can reply correctly without the fixtures: | ||
:ets.insert(:rpc_requests_counter, {:rpc_counter, 0}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about splitting this one-liner into its function (can be put under test/support
) so that the docs can be put there too. Then it will make the docs find-able for anyone looking at any of the 6 occurrences of this insert
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think about this?
apps/omg_eth/test/fixtures/vcr_cassettes/root_chain/ganache/get_deposits.json
Outdated
Show resolved
Hide resolved
also on this:
I don't have any hints yet, why this would hurt
Also to troubleshoot a bit more, can you run
for Ping me if you get stuck, I'll try to reproduce the problem on my end. |
Ha, actually I played around with this and got something. If you run the Hence the econnrefused are coming from attempts to talk to ganache and record the cassettes. Not sure how to make |
THIS IS MAJOR 👏 👏 👏 <3 <3 <3 |
This reverts commit e92e7a9.
7a793d9
to
34cc58d
Compare
34cc58d
to
e851855
Compare
Wrapping the code executing the network request will update the json. Depending on your matching preference, it will automatically re-record if it does not have an existing record.
Haven't tried this but seems like the approach is to pass in another option like: use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney, options: [clear_mock: true] |
@@ -0,0 +1,22 @@ | |||
version: "3.4" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we get some docs around this so that we know how to record for new "tests"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 minor follow-ups to the previous comments
# The problem is the fixtures would send a first request out(this request). When you remove the fixtures, | ||
# Ethereumex thinks we are sending the first request, missing the matching cassettes by request_body. | ||
# So, we reset the counter so the cassettes can reply correctly without the fixtures: | ||
:ets.insert(:rpc_requests_counter, {:rpc_counter, 0}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think about this?
📋 #709
TODO
skip
test forhas_token/2
due to ald contract function changeskip
test forget_deposits
due to invalid output encoding--umbrella
breaks theexvcr
usage.Overview
This PR introduces
exvcr
to record the response we get from the Ethereum client for testing withOMG.Eth
,OMG.Eth.RootChain
and the rest of its ilk. This will record our tests and allows us to turn down the service and test against those responses instead of spinning up, and tearing down thegeth
process each time for each test case.It also introduces another way for us to run our tests against an ethereum client by setting up a docker service to bring up the client instead of using
DevHelpers
to bring up and teardown thegeth
process.Recording VCR Cassettes with Docker + ExVCR
Spin up the docker instance for ganache/plasma-contracts:
This will spin up
ganache
in a deterministic mode and deploy the ALD contracts fromplasma_framework
see hereIn your test cases, you can specify the pre-determined addresses (see
ganache
output in docker) in the setup block. Then just wrap your network calls inuse_cassette
:Changes
exvcr
and recordgeth
responses 9e6148feth_test.exs
androot_chain_test.exs
9e6148fEthereuemex
into request counter so that we can have a consistent recording. This changes theDevHelpers
and test setup block to explicitly reset the counter to 0. 5d9d9f1 8e38bb9docker-compose-fixtures.yml
to spin upganache
andplasma-contracts
. Note, currently dumped the service here and can consolidate it after. 14d009fTesting