Skip to content

Commit

Permalink
fix: cargo test takes too long to test (#90)
Browse files Browse the repository at this point in the history
* fix: ignore unit tests take so long

* chore: change ci to run only unit tests

* docs: add reason in ignored tests

* fix: e2e under feature test

* refactor: rename one test

* chore: run all tests in CI

* fix: pr feedback

* fix: remove ignore tests

* docs: update README

* chore: fmt
  • Loading branch information
AlexD10S authored Apr 4, 2024
1 parent 3bbe617 commit 60d7f80
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 12 deletions.
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:

```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
```

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(())
}

0 comments on commit 60d7f80

Please sign in to comment.