Skip to content

Create diff tests for minor hardforks #635

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

Closed
wants to merge 3 commits into from

Conversation

gurukamath
Copy link
Collaborator

@gurukamath gurukamath commented Oct 29, 2022

(closes #605 )

What was wrong?

The minor hard forks do not currently have any tests.

Related to Issue #605

How was it fixed?

Create diff tests control for diffs in the hard fork source code, with the previous fork as the reference.

Cute Animal Picture

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

@codecov-commenter
Copy link

Codecov Report

Base: 68.75% // Head: 68.76% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (f80448d) compared to base (c8fbb41).
Patch has no changes to coverable lines.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #635   +/-   ##
=======================================
  Coverage   68.75%   68.76%           
=======================================
  Files         481      481           
  Lines       26836    26836           
=======================================
+ Hits        18451    18453    +2     
+ Misses       8385     8383    -2     
Flag Coverage Δ
unittests 68.76% <ø> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
src/ethereum/gray_glacier/__init__.py 100.00% <0.00%> (+100.00%) ⬆️
src/ethereum/arrow_glacier/__init__.py 100.00% <0.00%> (+100.00%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@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 wonder if these checks would be better suited to ethereum-spec-lint? I believe the Lint base class already gives you the previous hard fork, and the walk_sources function will be useful.

Could filter for forks ending with _glacier and make sure the only changed node is the fork block. Wouldn't work for the DAO fork, but maybe that could be its own special lint.

Comment on lines +56 to +58
code = re.sub(re.compile('""".*?"""', re.DOTALL), "", code)
code = re.sub(re.compile("#.*?\n"), "\n", code)
code = re.sub(re.compile("\n\s*\n"), "\n", code)
Copy link
Contributor

Choose a reason for hiding this comment

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

Haven't tested, but I think you can replace the compile with just a plain string:

Suggested change
code = re.sub(re.compile('""".*?"""', re.DOTALL), "", code)
code = re.sub(re.compile("#.*?\n"), "\n", code)
code = re.sub(re.compile("\n\s*\n"), "\n", code)
code = re.sub('""".*?"""', "", code, flags=re.DOTALL)
code = re.sub("#.*?\n", "\n", code)
code = re.sub("\n\s*\n", "\n", code)

Comment on lines +102 to +109
process_source_code(old_source_path, old_processed_path)
process_source_code(new_source_path, new_processed_path)

diffs = subprocess.run(
["diff", old_processed_path, new_processed_path],
capture_output=True,
text=True,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm... do you think it would be possible to implement a solution using Python's ast? You could walk the tree and remove docstrings and comments, plus whitespace would already be taken care of. Wouldn't need to shell out to diff that way either, or write files.

Apparently there's no built-in comparison function but there's a post with some ideas on how to do it.

I guess the hardest part of this approach is specifying what changes are allowed. Could just hard code the test for *_glacier forks for now I guess.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure. I will look into it.

@gurukamath
Copy link
Collaborator Author

Closing this in favour of the linting approach #639

@gurukamath gurukamath closed this Nov 5, 2022
@gurukamath gurukamath deleted the create_diff_tests branch November 26, 2022 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create diff tests for glacier hardforks
3 participants