-
Notifications
You must be signed in to change notification settings - Fork 76
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
β¨ cli(make): Add test
command for interactively creating new tests
#950
base: main
Are you sure you want to change the base?
Conversation
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.
Love it, really fun to use. Few minor changes.
I'll get back to the fork options in a bit π
52896cb
to
1a877dd
Compare
@danceratopz I have patched in all your feedback. The
|
test
command to interactively new create test files
test
command to interactively new create test filestest
command for interactively creating 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.
Thanks, I really like the idea of a more generalized command structure!
As we discussed async, @spencer-tb proposed an eest
namespace in #461. Inspired by uv
I would personally propose a shorter top-level command et
and add make
as a sub-command of that. Then we'd have uv run et make test
. I'm not a fan of using "make
" without a top-level command (as GNU Make is a very popular command - GNU Make), but not if it's a sub-command. Should we add et
in the scope of this PR with the sole sub-command et
and then add other sub-commands in follow-up PRs?
I'm enjoying the flair ποΈ, I'm not sure I like it in the context of make test
, as I want to prominently see the module name I'm creating (and perhaps the command to fill it, including --until=<fork>
if <fork>
is a development fork). Could you remove the quotes from the make test
output for now and we see where we can add something like this later on? But, feel free to leave src/cli/make/commands/quotes.py
as part of the PR if you like.
There's a couple of comments below, I'm starting to have more ideas, but perhaps we should try and not get too carried away for now π
@@ -0,0 +1,23 @@ | |||
""" | |||
A blockchain test for [EIP-{{eip_number}} {{eip_name}}](https://eips.ethereum.org/EIPS/eip-{eip_number}}). |
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.
Ooh, I think that was my mistake.
A blockchain test for [EIP-{{eip_number}} {{eip_name}}](https://eips.ethereum.org/EIPS/eip-{eip_number}}). | |
A blockchain test for [EIP-{{eip_number}} {{eip_name}}](https://eips.ethereum.org/EIPS/eip-{{eip_number}}). |
@@ -0,0 +1,23 @@ | |||
""" | |||
A state test for [EIP-{{eip_number}} {{eip_name}}](https://eips.ethereum.org/EIPS/eip-{eip_number}}). |
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.
A state test for [EIP-{{eip_number}} {{eip_name}}](https://eips.ethereum.org/EIPS/eip-{eip_number}}). | |
A state test for [EIP-{{eip_number}} {{eip_name}}](https://eips.ethereum.org/EIPS/eip-{{eip_number}}). |
src/cli/make/commands/test.py
Outdated
is saved in the appropriate directory with a rendered template using Jinja2. | ||
""" | ||
|
||
import os |
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.
To exit the command with an error we'll use sys.exit(1)
import os | |
import os | |
import sys |
src/cli/make/commands/test.py
Outdated
file_name = f"test_{eip_name.lower().replace(' ', '_')}.py" | ||
|
||
directory_path = f"tests/{fork.lower()}/eip{eip_number}_{eip_name.lower().replace(' ', '_')}" | ||
file_path = f"{directory_path}/{file_name}" |
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.
We shouldn't clobber the file if it exists, please check this runs as expected:
file_path = f"{directory_path}/{file_name}" | |
file_path = f"{directory_path}/{file_name}" | |
if file_path.exists(): | |
click.echo(f"The target test module {file_path} already exists!", err=True) | |
sys.exit(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.
Ah sorry, this won't work as-is as file_path
is a str
, not a pathlib.Path
src/cli/make/commands/test.py
Outdated
fork=fork, | ||
eip_number=eip_number, | ||
eip_name=eip_name, | ||
test_name=eip_name.lower().replace(" ", "_"), |
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 we should prompt users for a test_module
and a test_name
. They might want to run this wizard multiple times for the same EIP.
This has implications for the UX though. If the folder (e.g. tests/prague/eip123_example_x/
) exists, it would be more user-friendly to provided the folder as the first argument and the corresponding prompts skipped? Feel free to keep it simple for now. Just ideas.
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 we should prompt users for a
test_module
and atest_name
. They might want to run this wizard multiple times for the same EIP.
But perhaps only if the "default" test module doesn't exits? E.g. if tests/prague/eip124_exhibit_x/test_exhibit_x.py
exits then prompt for a test_module
and test_name
, otherwise keep it simple.
re: command structureStrongly agree with re: quotesI wasn't too sure if this is the right place. We could either:
OR
For this CLI, we could show a message like so: π Success! Test file created at: {file_path}
π Get started with tests: https://ethereum.github.io/execution-spec-tests/v3.0.0/writing_tests
β½ To fill this test, run: `uv run fill {file_path} --until={fork}` |
This sounds good! I would prefer
This looks great. Please note that, since we fixed the the test module path in the reviews above,
For now we can populate these expected global variables with dummy values to make allow |
Done
Pending1. UX with test module nameI'm not too sure how this should be because I haven't had a lot of experience writing tests. 2. Ensure the new test file passes fill command.Unsure how to get the fill to pass. But I'm looking into it. |
Niiice! The fully populated fork selection menu is so nice.
We can leave this for now, gather feedback from the team & close collaborators and iterate in follow-up PR(s).
Had a quick look, sorry to gatecrash. It looks like the default env = Environment()
sender = pre.fund_eoa()
tx = Transaction(to=sender, sender=sender)
post: dict[str, dict] = {}
state_test(env=env, pre=pre, post=post, tx=tx) I don't understand why this triggers the exception it does ( I got this far quite quickly by running the generated test with the
More info here: |
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 a lot for adding et
up front here. @spencer-tb gonna love it!
Just a couple of quick comments after trying the CLI out.
src/config/docs.py
Outdated
DOCS_BASE_URL: str = f"https://ethereum.github.io/execution-spec-tests/v{AppConfig().version}" | ||
|
||
# Documentation URLs prefixed with `DOCS_URL__` to avoid conflicts with other URLs | ||
DOCS_URL__WRITING_TESTS: str = f"{DOCS_BASE_URL}/writing_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.
Great idea to use the config for this.
I think I'd prefer to point to main
(for now) as we're pushing improvements to the docs much faster than we are releasing.
|
||
from ethereum_test_tools import Alloc, Block, BlockchainTestFiller, Transaction | ||
|
||
REFERENCE_SPEC_GIT_PATH = "DUMMY/eip-DUMMY.md" |
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 could actually populate the correct information for REFERENCE_SPEC_GIT_PATH
, but as mentioned, don't waste too much time as I'd prefer to remove this feature from EEST entirely.
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.
Yes. I have created an issue to remove it #963.
Once we merge this, I will reference these lines in the issue.
dac9049
to
c93a9bf
Compare
Fill now passes for all forks. This PR is now ready. |
ποΈ Description
Scaffold tests using CLI.
π Related Issues
closes #926, closes #946
β Checklist
mkdocs serve
locally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.