-
Notifications
You must be signed in to change notification settings - Fork 12
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 to non-recursive solution for target block #78
Conversation
@corydickson Thanks for the pr! The broken tests are b/c of web3's latest update - I've got a fix coming soon that should solve them |
Fix is in - if you rebase against master that should clear up the failing tests |
8404209
to
17afed8
Compare
@njgheorghita Thank you, tho I'm having trouble reproducing the failure in the latest build above to fix
|
ethpm_cli/commands/scraper.py
Outdated
delta_end = version_release_date - to_date | ||
delta_mid = version_release_date - mid_date | ||
|
||
min_delta = min(delta_mid.days, delta_start.days, abs(delta_end.days)) |
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.
I'm a little confused by what's going on here. Wouldn't the min_delta
always be delta_end.days
?
It also seems that adjusting the hunt for the next block by one is going to take a looong time. I'd try looking at this and see if you can get some better performance by following that pattern.
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.
You're right, thanks for that resource. I see now that you have to update the range you're looking at for each iteration 😓
aba7262
to
89917a6
Compare
tests/core/test_scraper.py
Outdated
@@ -166,6 +166,8 @@ def test_get_ethpm_birth_block(w3, interval): | |||
time_travel(w3, interval) | |||
actual = get_ethpm_birth_block(w3, 0, w3.eth.blockNumber, latest_block.timestamp) | |||
assert actual == latest_block.number - 1 | |||
# Not found | |||
assert get_ethpm_birth_block(w3, 0, 0, latest_block.timestamp) == -1 |
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.
Hope it's okay to add this to the existing test instead of a separate function even though it's no longer looking at only valid intervals
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.
It'd be better if it went in its own test - testing that it raises an exception (a la piper's comment). In most cases, it's better to separate testing concerns into as many functions as necessary rather than squeezing them into a single test (though I'm definitely guilty of this also)
Thank you for the swift review @njgheorghita ! Let me know if you'd like me to squash the previous commits if things look good |
ethpm_cli/commands/scraper.py
Outdated
from_block = mid + 1 | ||
else: | ||
return mid - 1 | ||
return -1 |
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.
I think this should be an exception case since otherwise it requires checking the return value which is an antipattern since it is easy to forget to do.
Add assertion for not found edge case Remove comma
c74d649
to
b590307
Compare
get_ethpm_birth_block(w3, 0, w3.eth.blockNumber, latest_block.timestamp) | ||
with pytest.raises(BlockNotFoundError): | ||
time_travel(w3, 1) | ||
get_ethpm_birth_block(w3, w3.eth.blockNumber, 0, latest_block.timestamp) |
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.
For when the to_block
is strictly larger than the from_block
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.
cool! notes like this are definitely worth a comment in the code - and honestly it might be better off as a separate test - then in the test name you can explain what's going on
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.
Sure, still trying to discern when it's bloat and when it's appropriate for clarity. Any rule of thumbs you use?
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.
Hmmm, imo with tests bloat is not such a big concern, I tend to default to the more tests the better. It's good to have only one specific cause/effect being tested per test. We like to use @pytest.mark.parametrize
(example) a lot which helps improve the testing quality while reducing bloat. ping @pipermerriam for thoughts
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.
Thanks! and ughh these cli tests are so flaky - they're working fine locally, so my guess is there's something funky b/w infura requests and circle.
@pipermerriam @njgheorghita Thank you both learned a lot ! |
Seperate test functions for different exception cases
b590307
to
d1dbb65
Compare
What was wrong?
Issue #19
How was it fixed?
The approach laid out here attempts to reach the target block by measuring the time passed between initial block and the last block given. It is considerably slower than the recursive solution, though addresses the implementation concern. Most likely I'm missing something by not taking advantage of the fact we can look at the block in-between this initial range and search on a smaller set of inputs?
Cute Animal Picture