Skip to content
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 generics for consensus test specs testing to reduce code duplication #1621

Merged
merged 5 commits into from
Jan 13, 2025

Conversation

KolbyML
Copy link
Member

@KolbyML KolbyML commented Jan 7, 2025

What was wrong?

Currently every fork we must add thousands of lines of test data from ethereum/consensus-spec-tests and copy pastes tons of tests

This bloats our repo with large files, but also creates a bunch of almost duplicate tests.

This method also makes our test coverage limited as adding tests taking a lot of work to add and maintain so we often avoided adding additional test cases

This makes it very annoying and tedious to write tests for future forks

How was it fixed?

Creating a ef-testing crate which runs tests on data mostly generically, but manually for some cases.

  • we add a Makefile to download the data from ethereum/consensus-spec-tests
  • use generics to reduce code duplication and makes it easier to test future forks

These tests will also run in the CI which is good

Lighthouse and Reth use similar strategies for dealing with EF test data

In short

  • test coverage and maintainability is now highly improved
  • adding future tests and supporting new forks is easier

Future work

This is a big improvement, but of course we can always still improve. Anyways I want to move ethportal-peertest to the testing folder, and probably the test folder into it as well. What do you guys think?

I also want to move utp-testing into the testing folder

@KolbyML KolbyML force-pushed the improve-consensus-testing branch 2 times, most recently from 2f5e6a1 to b521e77 Compare January 7, 2025 17:47
@KolbyML KolbyML marked this pull request as ready for review January 7, 2025 17:49
@KolbyML KolbyML self-assigned this Jan 7, 2025
## Run [ethereum/consensus-spec-tests](https://github.com/ethereum/consensus-spec-tests)


Run Tests this will automatically download test data
Copy link
Collaborator

Choose a reason for hiding this comment

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

IIUC, this will also run the tests? This kind of sounds like it will only download the test data...

Clean test files
```bash
make clean
```
Copy link
Collaborator

Choose a reason for hiding this comment

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

In general, I think this README could use a fair amount more useful information....

  • outline of the crate structure
  • what kinds of datatypes are being tested?
  • how to add tests in future forks & make sure that they're tested
  • any other info you think would be useful to someone who just looks at this crate, and doesn't want to go digging through the code to understand what's going on

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for the feedback I will update the readme 🫡

@KolbyML
Copy link
Member Author

KolbyML commented Jan 9, 2025

@njgheorghita ready for another look, I tried to address the feedback, let me know if there is anything else you think would need improvement

@KolbyML KolbyML requested a review from njgheorghita January 9, 2025 15:49
Copy link
Member

@ogenev ogenev left a comment

Choose a reason for hiding this comment

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

I think it will be better if we have a root Makefile, instead of always going inside testing/ef-test if we want to download the test data.


In the future we may also test `ethereum/execution-test-specs`

## how to add tests in future forks & make sure that they're tested
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
## how to add tests in future forks & make sure that they're tested
## How to add tests in future forks & make sure that they're tested

@@ -0,0 +1,46 @@
## Run [ethereum/consensus-spec-tests](https://github.com/ethereum/consensus-spec-tests)

`ethereum/consensus-spec-tests` test data is important for testing our types, but the test data is very large which makes it not feasible to host it in our repository, this has lead to us under testing new types when new forks ship, and adding thousands of lines of test data and copy pasting almost identical tests with a few variables renamed.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
`ethereum/consensus-spec-tests` test data is important for testing our types, but the test data is very large which makes it not feasible to host it in our repository, this has lead to us under testing new types when new forks ship, and adding thousands of lines of test data and copy pasting almost identical tests with a few variables renamed.
`ethereum/consensus-spec-tests` test data is important for testing our types, but the test data is very large which makes it not feasible to host it in our repository, this has led to us under testing new types when new forks ship, and adding thousands of lines of test data and copy pasting almost identical tests with a few variables renamed.

### tests
All the tests the `ef-tests` crates run will be located in the `tests` folder

## what kinds of data types are being tested?
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
## what kinds of data types are being tested?
## What kinds of data types are being tested?

Copy link
Member

Choose a reason for hiding this comment

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

I'm more in favor of having a Makefile in the root dir. I would like, for example, to run a make test from the root to do all data downloads and all testing for me locally. We can have different commands for more granular testing, something similar to what reth are doing here and here.

@KolbyML
Copy link
Member Author

KolbyML commented Jan 10, 2025

@ogenev ready for another review, I believe I addressed all your concerns, let me know if I missed something or anything

@morph-dev
Copy link
Collaborator

I didn't take a closer look, but I wanted to ask why use Makefile and downloading test files instead of using submodule (like we do for portal-spec-tests)? Am I missing something?

In general, I'm in favor of this PR.

@KolbyML
Copy link
Member Author

KolbyML commented Jan 11, 2025

I didn't take a closer look, but I wanted to ask why use Makefile and downloading test files instead of using submodule (like we do for portal-spec-tests)? Am I missing something?

In general, I'm in favor of this PR.

Both lighthouse and reth download the test files using makefiles.

The test data is over 500MB's and uses git lfs, so I think using a submodule would make it less friendly to clone our project or run tests.

Doing it this way git cloning is still fast, and the annoying thing of git submodules changing branches is avoided.

Makefile Outdated
##@ Other

.PHONY: clean
clean: ## Perform a `cargo` clean and remove the binary and test vectors directories.
cargo clean
rm -rf $(BIN_DIR)
rm -rf $(EF_TESTS_DIR)
rm -rf $(EF_TESTS_DIR)
Copy link
Member

@ogenev ogenev Jan 13, 2025

Choose a reason for hiding this comment

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

nit: missed new line in EOF

@echo "Tests complete."

.PHONY: test
test: ## Runs workspace tests.
Copy link
Member

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 having a make command like test-workspace (or test-trin?), where we will run cargo test --workspace -- --nocapture and then having make test to run all tests (ef-tests + test-workspace)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wouldn't want make test to run ef-tests as it downloads files

neither lighthouse or reth uses make test to run ef-tests

Lighthouse puts ef-tests behind make test-full, I will do that as then it is more intentional you want to run the expanded test suite, which would involve downloading files.

Both lighthouse and reth use make test for testing the workspace

Copy link
Member

Choose a reason for hiding this comment

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

ok fair enough 👍 .

Copy link
Member

@ogenev ogenev left a comment

Choose a reason for hiding this comment

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

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.

4 participants