feat: rework test-harness for integration tests#896
feat: rework test-harness for integration tests#896lima-limon-inc wants to merge 4 commits into0xMiden:nextfrom
Conversation
|
@greenhat @bitwalker The PR is not yet finished, but what do you think about this approach? Any comments / recommendations are more than welcome. Thanks in advance! |
|
Good job!
The only problem with attribute macro DSLs I see is discoverability by the user. To this day I have to jump and search the docs when I'm using |
Thank you very much! 😊
Completely agree, The first thing that comes to mind is implementing a "help" command in the macro itself. Something like: #[miden_test(help)]
pub fn test_basic_wallet_p2id() {
(...)
}Which would display all of the supported attributes. Whilst I haven't seen this idea of a "help" command in macros, it's pretty standard in CLI tools; so maybe the it isn't too far out there. I'll tackle it and see how it goes. Do let me know if you have any thoughts! |
ed703ea to
6065281
Compare
I have just pushed the code that supports --> tests/integration-network/src/mockchain/basic_wallet.rs:20:1
|
| #[miden_test(help)]
| ^^^^^^^^^^^^^^^^^^^
|
= help: message:
<documentation string>Where A nifty detail is that it uses each struct's doc-comments to generate the help message. Which means that it remains consistent and up to date with the generated Additionally, I also added support for The actual displayed help message is still a bit rough around the edges, but all the "logic" to collect and generate the message is all there. I'll update the PR as soon as that is done. Just wanted to update the PR to show how things are shaping up 😊. Any comment/suggestion is more than welcome! Cheers! |
Nice! I have not thought about calling a macro to get help. |
a7eb5ca to
1ed5b54
Compare
2e7c626 to
30a9d0d
Compare
Signed-off-by: Tomas Fabrizio Orsi <tomas.orsi@lambdaclass.com>
Signed-off-by: Tomas Fabrizio Orsi <tomas.orsi@lambdaclass.com>
6c78c1b to
d2814c0
Compare
Signed-off-by: Tomas Fabrizio Orsi <tomas.orsi@lambdaclass.com>
d2814c0 to
8207c15
Compare
|
@bitwalker @greenhat I believe the PR is ready for review. Do note that it mainly focuses on refactoring the present test harness infrastructure itself to make it compatible with integration tests.
The actual expansion of the present tests could probably be done in a separate PR since this already is quite extensive. Would love to hear your thoughts! PS: The CI is currently running but it should pass, I've just pushed a commit updating the documentation. |
bitwalker
left a comment
There was a problem hiding this comment.
Definitely cleans up the boilerplate!
I do have some reservations about the level of magic involved, but the help attribute does mitigate that for the most part (of course, one has to know to use that in the first place, but it's still better than nothing). I definitely wish that attribute macros supported the same "helper" attributes mechanism that derive macros do, since that would help with discoverability, but 🤷.
I would suggest we provide a higher-level "user guide"-type document as well, maybe in test-harness/README.md, which goes into detail how the different options stack/interact, what the defaults are, and whether some options require others to be provided, and if so, under what conditions. That sort of guidance is the main thing missing IMO, as currently we largely are just relying just on a small set of examples, and the minimal help documentation produced by the help argument (which isn't very discoverable/accessible unless you look at the examples where it is featured).
I'm marking this approved though, and we can merge this once an initial version of that document is added here, just ping me!
8423887 to
e474bfc
Compare
Signed-off-by: Tomas Fabrizio Orsi <tomas.orsi@lambdaclass.com>
e474bfc to
b4f6844
Compare
I'm glad it helps 😊
@bitwalker |
|
Good job! Very thorough exploration of what's possible to achieve with macros. I think that the macro parameters approach in general cost/benefit is not looking good. Let's look at the following macro parameters: It is not much more concise than our current ad hoc and unoptimized API: let alice_account = builder
.add_account_from_builder(
Auth::BasicAuth,
build_existing_basic_wallet_account_builder(wallet_package.clone(), true, [5_u8; 32]),
AccountState::Exists,
);But it is significantly more expensive for the developers. I consider the following to be the extra price that the developers would pay for macros on top of Mockchain (which is not going anywhere):
With all that in mind I think that we should consider that macros might not be worth pursuing and we might need to change the direction. The alternatives I see:
|
Tackles #876
This PR aims to re work the testing harness merged here in order for it to work for integration tests.
A thing that was common in all the
integration-networktests was the presence of "repetitive" boilerplate code to set up a couple of basic wallet accounts inside aMockChain. See:With this in mind, this PR aims to aid in reducing the amount of boilerplate required to set up the context for a test. To achieve this, I went with a
clap-esque/operation-esque approach.Currently, it looks like so:
Which replaced the following lines:
The plan is to have something along these lines:
To replace the following:
This probably supersede the previous syntax where the "special"/"magic" recognized keywords were passed as function arguments. I believe this attribute interface is more idiomatic than the current interface.
Concretely, this means going from this:
to:
This PR is still in a WIP state and can of course include even more functionality (for instance, creating
ninstances of an Account`).Implementation wise, the attributes follow a "pipeline" in order to emit the code:
darlinginto aXBuilderstructXBuilderstructs are validated, via their ownvalidatefunction.XBuilderstruct gets turned into a plainXemits their corresponding code.This pipeline can be found here.