Skip to content

Commit

Permalink
feat: add CLI integration tests using assert_cmd (#353)
Browse files Browse the repository at this point in the history
* feat: add CLI integration tests using assert_cmd

* feat: add test

* fix: address clippy issues

* test: extend import test to execute transactions

* feat: return result from main instead of just printing errors

* test: add extra test for import export notes and fix previous tests

* test: add extra test for import export notes and fix previous tests

* fix: use assert_cmd way of changing directory

* fix: fix for changes in CLI

* add debug info for CI

* fix: stop using constant account IDs

Since we run the miden node with `--concurrent` flag, genesis accounts generation becomes non-deterministic as the concurrent algorithm to generate the account IDs based on the seed can end up using the result of any thread depending on which finishes first.

* refactor: make assert_cmd an integration test dependency only

* address review comments

* test: add check for notes show command on CLI

* fix: do correct check when should_fail is true

* fix: fix mmr indices traversal

* test: add sleep in between sync attempts for cli

* test: ignore genesis test by default and enable it on integration-test-full target
  • Loading branch information
mFragaBA authored Jun 6, 2024
1 parent 82d7d15 commit 637a8d4
Show file tree
Hide file tree
Showing 10 changed files with 502 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
- run: cargo make reset
- run: cargo make node
- run: cargo make start-node > /dev/null &
- run: cargo make ci-integration-test
- run: cargo make integration-test-full
- name: Kill miden-node
if: always()
run: cargo make kill-node
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ required-features = ["integration"]
[features]
concurrent = ["miden-lib/concurrent", "miden-objects/concurrent", "miden-tx/concurrent"]
default = ["std"]
integration = ["testing", "concurrent", "uuid"]
integration = ["testing", "concurrent", "uuid", "assert_cmd"]
std = ["miden-objects/std"]
testing = ["miden-objects/testing", "miden-lib/testing"]
test_utils = ["miden-objects/testing"]
Expand All @@ -50,6 +50,7 @@ toml = { version = "0.8" }
tracing = { version = "0.1" }
tracing-subscriber = { version = "0.3" }
uuid = { version = "1.6.1", features = ["serde", "v4"], optional = true }
assert_cmd = { version = "2.0", optional = true }

[dev-dependencies]
# needed for tests to run always with the test utils feature
Expand Down
11 changes: 7 additions & 4 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ description = "Run the client testing suite"
command = "cargo"
args = ["nextest", "run", "--profile", "ci-default", "--release", "--workspace"]

[tasks.ci-integration-test]
description = "Run the integration test binary. Requires a node to connect to."
command = "cargo"
args = ["nextest", "run", "--profile", "ci-default", "--release", "--test=integration", "--features", "${FEATURES_INTEGRATION_TESTING}"]
[tasks.integration-test-full]
description = "Run the integration test binary with ignored tests included"
script_runner = "bash"
script = [
'cargo nextest run --profile ci-default --release --test=integration --features $FEATURES_INTEGRATION_TESTING',
'cargo nextest run --profile ci-default --release --test=integration --features $FEATURES_INTEGRATION_TESTING --run-ignored ignored-only -- test_import_genesis_accounts_can_be_used_for_transactions'
]

[tasks.lint]
dependencies = [
Expand Down
2 changes: 1 addition & 1 deletion src/cli/new_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub struct MintCmd {
#[clap(short, long, value_enum)]
note_type: NoteType,
/// Flag to submit the executed transaction without asking for confirmation
#[clap(short, long, default_value_t = false)]
#[clap(long, default_value_t = false)]
force: bool,
}

Expand Down
5 changes: 2 additions & 3 deletions src/client/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,10 +668,9 @@ impl<N: NodeRpcClient, R: FeltRng, S: Store, A: TransactionAuthenticator> Client
idx = idx.sibling();
// Rightmost index is always the biggest value, so if the path contains any node
// past it, we can discard it for our version of the forest
if idx > rightmost_index {
continue;
if idx <= rightmost_index {
path_nodes.push((idx, node));
}
path_nodes.push((idx, node));
idx = idx.parent();
}

Expand Down
6 changes: 2 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ mod cli;
use cli::Cli;

#[tokio::main]
async fn main() {
async fn main() -> Result<(), String> {
tracing_subscriber::fmt::init();
// read command-line args
let cli = Cli::parse();

// execute cli action
if let Err(error) = cli.execute().await {
println!("{}", error);
}
cli.execute().await
}
20 changes: 19 additions & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ cargo make node
# This command will run the node on background
cargo make start-node &
# This will run the integration test
cargo make integration-test
cargo make integration-test-full
```

## Integration Test Flow
Expand Down Expand Up @@ -42,6 +42,24 @@ To run the integration test you just need to run `cargo make integration-test`.
It'll run the integration tests as a cargo test using the `integration` feature
which is used to separate regular tests from integration tests.

### Ignored Tests

Currently, we have one ignored test because it requires having the genesis data
from the node it is running against which might not always be possible. You can
run it manually by doing:

```bash
cargo nextest run --profile ci-default --release --test=integration --features integration --run-ignored ignored-only -- test_import_genesis_accounts_can_be_used_for_transactions
```

Or run `cargo make integration-test-full` to run all integration tests with
that included. On the other hand, if you want to run integration tests without
that one you can just instead do:

```bash
cargo make integration-test
```

### Running tests against a remote node

You can run the integration tests against a remote node by overwriting the rpc
Expand Down
6 changes: 6 additions & 0 deletions tests/config/genesis.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ init_seed = "0xa123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
auth_scheme = "RpoFalcon512"
auth_seed = "0xb123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"

[[accounts]]
type = "BasicWallet"
init_seed = "0xa123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdea"
auth_scheme = "RpoFalcon512"
auth_seed = "0xb123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdea"

[[accounts]]
type = "BasicFungibleFaucet"
init_seed = "0xc123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
Expand Down
Loading

0 comments on commit 637a8d4

Please sign in to comment.