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

fix: cargo test takes too long to test #90

Merged
merged 11 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ jobs:
run: cargo build

- name: Run tests
run: cargo test --verbose
run: cargo test --all-features
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ contract = [
"dep:sp-weights",
"dep:url",
]
e2e_contract = []
unit_contract = []
parachain = [
"dep:dirs",
"dep:indexmap",
Expand All @@ -76,3 +78,5 @@ parachain = [
"dep:zombienet-sdk",
"dep:zombienet-support"
]
e2e_parachain = []

36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,43 @@ pop up parachain -f ./tests/zombienet.toml -p https://github.com/r0gue-io/pop-no
> :information_source: Pop CLI will automatically source the necessary polkadot binaries. Currently, these will be built
> if on a non-linux system.

## Testing Pop CLI

To test the tool locally.

Run the unit tests:

```sh
cargo test
```

Run only contracts unit tests:
AlexD10S marked this conversation as resolved.
Show resolved Hide resolved

```sh
cargo test --features unit_contract
```

Run the contracts e2e tests:

```sh
cargo test --features e2e_contract
```

Run the parachain e2e tests:

```sh
cargo test --features e2e_parachain
AlexD10S marked this conversation as resolved.
Show resolved Hide resolved
```

Run all tests:

```sh
cargo test --all-features
```
## Acknowledgements

Pop CLI would not be possible without these awesome crates!

- Local network deployment powered by [zombienet-sdk](https://github.com/paritytech/zombienet-sdk)
- [cargo contract](https://github.com/paritytech/cargo-contract) a setup and deployment tool for developing Wasm based smart contracts via ink!
- [cargo contract](https://github.com/paritytech/cargo-contract) a setup and deployment tool for developing Wasm based smart contracts via ink!
2 changes: 2 additions & 0 deletions src/engines/contract_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ mod tests {
Ok(())
}

#[cfg(feature = "unit_contract")]
#[test]
fn test_contract_build() -> Result<(), Error> {
let temp_contract_dir = setup_test_environment()?;
Expand All @@ -230,6 +231,7 @@ mod tests {
Ok(())
}

#[cfg(feature = "unit_contract")]
#[test]
fn test_contract_test() -> Result<(), Error> {
let temp_contract_dir = setup_test_environment()?;
Expand Down
9 changes: 0 additions & 9 deletions src/engines/parachain_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,4 @@ mod tests {

Ok(())
}

#[test]
fn test_parachain_build_after_instantiating_template() -> Result<()> {
let temp_dir =
setup_template_and_instantiate().expect("Failed to setup template and instantiate");
let build = build_parachain(&Some(temp_dir.path().to_path_buf()));
assert!(build.is_ok(), "Result should be Ok");
Ok(())
}
}
3 changes: 2 additions & 1 deletion tests/build_contract.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(feature = "e2e_contract")]
use anyhow::{Error, Result};
use assert_cmd::Command;
use predicates::prelude::*;
Expand All @@ -16,7 +17,7 @@ fn setup_test_environment() -> Result<tempfile::TempDir, Error> {
}

#[test]
fn test_contract_build() -> Result<(), Error> {
fn test_contract_build_success() -> Result<(), Error> {
let temp_contract_dir = setup_test_environment()?;

// pop build contract
Expand Down
32 changes: 32 additions & 0 deletions tests/build_parachain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#![cfg(feature = "e2e_parachain")]
use anyhow::{Error, Result};
use assert_cmd::Command;

fn setup_test_environment() -> Result<tempfile::TempDir, Error> {
let temp_dir = tempfile::tempdir().unwrap();
// pop new parachain test_parachain
Command::cargo_bin("pop")
.unwrap()
.current_dir(&temp_dir)
.args(&["new", "parachain", "test_parachain"])
.assert()
.success();

Ok(temp_dir)
}

#[test]
fn test_parachain_build_after_instantiating_template() -> Result<()> {
let temp_dir = setup_test_environment()?;

// pop build contract -p "./test_parachain"
Command::cargo_bin("pop")
.unwrap()
.current_dir(&temp_dir)
.args(&["build", "parachain", "-p", "./test_parachain"])
.assert()
.success();

assert!(temp_dir.path().join("test_parachain/target").exists());
Ok(())
}
Loading