-
Notifications
You must be signed in to change notification settings - Fork 71
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
feat: add CLI tests #216
base: main
Are you sure you want to change the base?
feat: add CLI tests #216
Conversation
test/cli-tests/tests/it/auth.rs
Outdated
|
||
const WASM: &Wasm = &Wasm::Release("soroban_auth_contract"); | ||
|
||
const ACC1: &str = "GA6S566FD3EQDUNQ4IGSLXKW3TGVSTQW3TPHPGS7NWMCEIPBOKTNCSRU"; |
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.
Please write out. No need to be so terse in an example test.
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.
done in d6bf4f8
test/cli-tests/Cargo.toml
Outdated
|
||
[dev-dependencies] | ||
predicates = "2.1.5" | ||
soroban-test = { git = "https://github.com/ahalabs/soroban-tools", rev = "bc1d008" } |
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.
This should probably be the stellar repo, right?
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, relevant PR is here:
We can wait to merge these examples tests until the soroban-tools PR is merged.
The tests themselves look fine. But they feel like cli tests, so it's odd they're in the examples repo. Feels like they should be in the |
I agree with @paulbellamy that these tests don't naturally fit in the examples repo. I think that in a perfect world they would be in the docs repo, as the docs are what is actually being tested. However, the docs don't currently have machinery to facilitate that. So for now having them here sounds like a reasonable compromise to me. I suggest the following:
Thoughts @willemneal @chadoh? |
I think doc-tests is a good name for now. Ideally we would make the examples a git submodule and then the docs repo could host the tests there. |
I do wonder if there's a more ergonomic way to write these tests. Constructing these commands in code is somewhat painful and will be painful to update. Is there a way to use the cli's parser to parse a single command string instead of constructing it by code? I think this will make writing and updating these tests easier - just copy&paste the cli command. |
@tomerweller Willem and I would rather have the ability to move somewhat in the other direction. ^ this would allow us to:
What do you think? |
All done. Looks like someone needs to approve running the workflow so tests actually run. |
I totally agree about writing tests in rust and not calling an external CLI process. My question/wonder was whether there's a way in code to construct the cli command, using the library, instead of "manually" constructing it. So instead of this TestEnv::with_default(|e| {
e.new_cmd("contract")
.arg("invoke")
.arg("--wasm")
.arg(&WASM.path())
.args(["--id", "1"])
.args(["--fn", "increment"])
.args(["--"])
.args(["--incr", "5"])
.assert()
.stderr("")
.stdout("5\n");
}); One could potentially write something more "similar" to this: TestEnv::with_default(|e| {
e.new_cmd_pasre("contract invoke --wasm {} --id 1 --fn increment -- --incr 5", &WASM.path())
.assert()
.stderr("")
.stdout("5\n");
}); This makes an assumption that there's an available parse function (or that one could be exposed) in the cli lib. Intuitively I think there should be one because the soroban-cli indeed parses commands from the cli that take that shape (but my intuition is often wrong). What's the feasibility of this? |
The idea would be to allow constructing an invoke, or any command, and then call a run function that returns the output. We have tests in the cli to handle testing cli parsing but we can skip that part and have proper types. |
ad807ac
to
3d5998e
Compare
version = "0.0.0" | ||
authors = ["Stellar Development Foundation <info@stellar.org>"] | ||
license = "Apache-2.0" | ||
edition = "2021" |
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.
not an expert, but shouldn't this be 2023 ?
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.
Is there a 2023 edition (yet)? I don't see it listed in the edition guide.
test/doc-tests/Cargo.toml
Outdated
|
||
[dev-dependencies] | ||
predicates = "2.1.5" | ||
soroban-test = { git = "https://github.com/ahalabs/soroban-tools", rev = "698479c" } |
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.
shouldn't this be pointed to an official release ?
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, see related discussion from last week
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.
This now points at an official release! Please mark this comment resolved.
39b8810
to
27cacd6
Compare
4976a35
to
e2b9d7b
Compare
@tomerweller @tsachiherman @paulbellamy this now uses the v0.7.1 versions of both soroban-cli and soroban-test. I'd love another round of review.
However, even without this, we believe that these tests are a great start. I think it's time to merge this PR; we can open new ones to update these tests as the testing library and CLI evolve. |
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.
LGTM. It would be nice to have these run as part of CI
9a3b573
to
e3f9532
Compare
This makes use of the newly-published [soroban-test](https://docs.rs/soroban-test/latest/soroban_test/) crate and the newly-reorganized [soroban-cli](https://docs.rs/soroban-cli) library to test all commands shown in the docs. This gives us confidence that all of these commands work, though it does come with some downsides: - these tests live far from the thing they are meant to test - could we generate the docs from this repository, rather than keeping them in sync with each other? - maybe, but it's a little unclear how that would work - this is a good starting point Another shortcoming of the approach here: it still makes use of `assert_cmd` in some tests, which runs the version of `soroban-cli` installed on the host system, making it quite brittle. This is necessary because some commands (`Cmd`s) from `soroban-cli` do not currently operate in a test-friendly way. This can be seen in a secondary way, too: not all `Cmd`s can be run the same way. Some use `run`, some use `run_in_sandbox`, some take arguments, some do not. These concerns can all be addressed together by refactoring `soroban-cli` to make all `Cmd`s implement an asynchronous `run` method with the same signature, and which will return a struct containing both `stdout` and `stderr`. However, even with these shortcomings and downsides, it is still worth merging these tests as-is, since it will give us higher confidence that everything works as expected with the current code. We can refactor these tests later, and potentially move them to a different repo. Co-authored-by: Chad Ostrowski <221614+chadoh@users.noreply.github.com>
@paulbellamy can you approve the workflow to run? |
Nope, I don't have write access to this repo. Maybe @leighmcculloch can? |
Just did. Could you address the conflicts ? |
* main: Add a very simple account contract example. (stellar#227)
@chadoh Seems like the test runner is failing to launch the Edit: Seems like the |
Aaaaaaand the top-level Cargo.toml was removed, so there's no more |
Currently the docs have example cli commands for the examples and this provides tests to ensure that the docs are accurate.