Skip to content
This repository has been archived by the owner on Jul 8, 2021. It is now read-only.

Make rlp module more readable and organized with tests. #40

Merged
merged 4 commits into from Jun 22, 2021
Merged

Make rlp module more readable and organized with tests. #40

merged 4 commits into from Jun 22, 2021

Conversation

Bhargavasomu
Copy link

@Bhargavasomu Bhargavasomu commented Jun 14, 2021

- Also fixes potential bugs in rlp module
- Add custom tests and integrate with ethereum test fixtures

What was wrong?

The rlp module was closely structured to the yellowpaper making it hard to comprehend and maintain. Also there were a few potential bugs in the code which were cleaned up. One such code bug is as follows.

Decoding an empty bytestream should throw an error instead of returning bytearray([128])

Related to Issue #18

How was it fixed?

The code was rewritten using Encoder and Decoder classes to get clarity. The bugs have also been fixed.

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@Bhargavasomu
Copy link
Author

I am yet to add testcases for this module and also integrate test fixtures for this module. @lightclient @SamWilsn @adietrichs
before I do that, can you please do a preliminary review of the code?

Copy link

@SamWilsn SamWilsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take another look once the code is restructured :)

src/eth1spec/rlp.py Outdated Show resolved Hide resolved
src/eth1spec/rlp.py Outdated Show resolved Hide resolved
@Bhargavasomu Bhargavasomu changed the title [WIP] Make rlp module more readable and organized. Make rlp module more readable and organized. Jun 15, 2021
@Bhargavasomu Bhargavasomu changed the title Make rlp module more readable and organized. Make rlp module more readable and organized with tests. Jun 15, 2021
@Bhargavasomu
Copy link
Author

@SamWilsn @lightclient @adietrichs I have added some personal tests and also integrated ethereum tests fixtures, and all of them seem to be working. Can you please review the code? Thanks.

@Bhargavasomu
Copy link
Author

@SamWilsn @lightclient @adietrichs can you please review the code? Thanks.

Copy link

@SamWilsn SamWilsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so much more readable! Great work. Just a bunch of me nitpicking really.

I did a few spot checks on the RLP test data, but we should probably make an issue to look into some differential fuzzing against other implementations (and/or steal their test suites.)

tests/test_base_types.py Outdated Show resolved Hide resolved
src/eth1spec/base_types.py Outdated Show resolved Hide resolved
src/eth1spec/base_types.py Outdated Show resolved Hide resolved
src/eth1spec/rlp.py Outdated Show resolved Hide resolved
src/eth1spec/rlp.py Show resolved Hide resolved
src/eth1spec/rlp.py Outdated Show resolved Hide resolved
src/eth1spec/utils/common.py Outdated Show resolved Hide resolved
whitelist.txt Outdated Show resolved Hide resolved
whitelist.txt Show resolved Hide resolved
whitelist.txt Outdated Show resolved Hide resolved
Copy link

@lightclient lightclient left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, nice job Somu! I left a few comments, but I think the big takeaways are:

  • Where possible, name the magic RLP lengths - and when defining them, use hex notation. Almost everyone interacts with RLP in hex representation, so it's just natural to think of these things using their hex values.
  • Avoid too much parameterization of tests and focus on readability instead.

src/eth1spec/base_types.py Outdated Show resolved Hide resolved
src/eth1spec/base_types.py Outdated Show resolved Hide resolved
src/eth1spec/rlp.py Show resolved Hide resolved
src/eth1spec/rlp.py Outdated Show resolved Hide resolved
src/eth1spec/rlp.py Outdated Show resolved Hide resolved
src/eth1spec/utils/common.py Outdated Show resolved Hide resolved
src/eth1spec/rlp.py Show resolved Hide resolved
src/eth1spec/rlp.py Outdated Show resolved Hide resolved
whitelist.txt Show resolved Hide resolved
tests/test_rlp.py Outdated Show resolved Hide resolved
        - Also fixes potential bugs in rlp module
        - Add tests and integrate with ethereum test fixtures
@codecov-commenter
Copy link

codecov-commenter commented Jun 19, 2021

Codecov Report

Merging #40 (e9b675f) into pyspec (632e395) will increase coverage by 8.31%.
The diff coverage is 98.94%.

Impacted file tree graph

@@            Coverage Diff             @@
##           pyspec      #40      +/-   ##
==========================================
+ Coverage   84.08%   92.40%   +8.31%     
==========================================
  Files          13       13              
  Lines         754      750       -4     
==========================================
+ Hits          634      693      +59     
+ Misses        120       57      -63     
Flag Coverage Δ
unittests 92.40% <98.94%> (+8.31%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/eth1spec/rlp.py 99.02% <98.94%> (+58.84%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 632e395...e9b675f. Read the comment docs.

Copy link

@SamWilsn SamWilsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty happy with this, but I'd wait for @lightclient's review before merging.

Copy link

@lightclient lightclient left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry for being so nitpicky - I just think it's really important to use hex values as much we can when dealing with RLP since RLP is almost always viewed in that form. To most devs, numbers like 183, 192, etc. mean nothing to them. But things like 0xb7 and 0xc0 have meaning.

src/eth1spec/rlp.py Outdated Show resolved Hide resolved
src/eth1spec/rlp.py Outdated Show resolved Hide resolved
src/eth1spec/rlp.py Outdated Show resolved Hide resolved
src/eth1spec/rlp.py Outdated Show resolved Hide resolved
src/eth1spec/rlp.py Outdated Show resolved Hide resolved
src/eth1spec/rlp.py Show resolved Hide resolved
src/eth1spec/rlp.py Outdated Show resolved Hide resolved
src/eth1spec/rlp.py Show resolved Hide resolved
src/eth1spec/rlp.py Outdated Show resolved Hide resolved
tests/test_rlp.py Outdated Show resolved Hide resolved
@lightclient lightclient merged commit 0b9534a into quilt:pyspec Jun 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants