From c1ad5873beb3588ebd8954dfef65f45e2eefb911 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Mon, 1 Apr 2024 10:50:05 +0200 Subject: [PATCH 01/10] fix: ignore unit tests take so long --- src/engines/contract_engine.rs | 2 ++ src/engines/parachain_engine.rs | 1 + 2 files changed, 3 insertions(+) diff --git a/src/engines/contract_engine.rs b/src/engines/contract_engine.rs index 09721ec6..74fb7eaf 100644 --- a/src/engines/contract_engine.rs +++ b/src/engines/contract_engine.rs @@ -204,6 +204,7 @@ mod tests { } #[test] + #[ignore] // It takes long time to build fn test_contract_build() -> Result<(), Error> { let temp_contract_dir = setup_test_environment()?; @@ -230,6 +231,7 @@ mod tests { } #[test] + #[ignore] // It takes long time to build fn test_contract_test() -> Result<(), Error> { let temp_contract_dir = setup_test_environment()?; diff --git a/src/engines/parachain_engine.rs b/src/engines/parachain_engine.rs index cf55776d..1e487449 100644 --- a/src/engines/parachain_engine.rs +++ b/src/engines/parachain_engine.rs @@ -125,6 +125,7 @@ mod tests { } #[test] + #[ignore] // It takes long time to build fn test_parachain_build_after_instantiating_template() -> Result<()> { let temp_dir = setup_template_and_instantiate().expect("Failed to setup template and instantiate"); From 1c4724cfc381b639d6f2572d81d885de71e59930 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Mon, 1 Apr 2024 10:51:14 +0200 Subject: [PATCH 02/10] chore: change ci to run only unit tests --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b81c1943..0472bc32 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -64,5 +64,5 @@ jobs: - name: Build default features run: cargo build - - name: Run tests - run: cargo test --verbose \ No newline at end of file + - name: Run unit tests + run: cargo test --bins \ No newline at end of file From b35ea2d8afe69548b1ed38735d22823198f67147 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Mon, 1 Apr 2024 12:44:07 +0200 Subject: [PATCH 03/10] docs: add reason in ignored tests --- src/engines/contract_engine.rs | 4 ++-- src/engines/parachain_engine.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/engines/contract_engine.rs b/src/engines/contract_engine.rs index 74fb7eaf..c293cd2a 100644 --- a/src/engines/contract_engine.rs +++ b/src/engines/contract_engine.rs @@ -204,7 +204,7 @@ mod tests { } #[test] - #[ignore] // It takes long time to build + #[ignore = "Build a contract takes long time to build"] fn test_contract_build() -> Result<(), Error> { let temp_contract_dir = setup_test_environment()?; @@ -231,7 +231,7 @@ mod tests { } #[test] - #[ignore] // It takes long time to build + #[ignore = "Build a contract to test it takes long time to build"] fn test_contract_test() -> Result<(), Error> { let temp_contract_dir = setup_test_environment()?; diff --git a/src/engines/parachain_engine.rs b/src/engines/parachain_engine.rs index 1e487449..c68ee4e6 100644 --- a/src/engines/parachain_engine.rs +++ b/src/engines/parachain_engine.rs @@ -125,7 +125,7 @@ mod tests { } #[test] - #[ignore] // It takes long time to build + #[ignore = "Build parachain takes long time to build"] fn test_parachain_build_after_instantiating_template() -> Result<()> { let temp_dir = setup_template_and_instantiate().expect("Failed to setup template and instantiate"); From ed953a7142d01d733004ef6b0c2c4261f73f618d Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Mon, 1 Apr 2024 20:38:10 +0200 Subject: [PATCH 04/10] fix: e2e under feature test --- Cargo.toml | 3 +++ README.md | 29 +++++++++++++++++++++++++++++ tests/build_contract.rs | 3 +++ 3 files changed, 35 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 211269c4..7f5cf96c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,6 +63,7 @@ contract = [ "dep:sp-weights", "dep:url", ] +e2e_contract = [] parachain = [ "dep:dirs", "dep:indexmap", @@ -75,3 +76,5 @@ parachain = [ "dep:zombienet-sdk", "dep:zombienet-support" ] +e2e_parachain = [] + diff --git a/README.md b/README.md index 16cf809b..42978b0d 100644 --- a/README.md +++ b/README.md @@ -204,3 +204,32 @@ 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 the contracts e2e tests: + +```sh +cargo test --features e2e_contract +``` + +Run the parachain e2e tests: + +```sh +cargo test --features e2e_parachain +``` + +Run all tests, including the ignored ones: + +```sh +cargo test --all-features -- --include-ignored +``` \ No newline at end of file diff --git a/tests/build_contract.rs b/tests/build_contract.rs index 65a0bfe8..ad880b56 100644 --- a/tests/build_contract.rs +++ b/tests/build_contract.rs @@ -16,6 +16,7 @@ fn setup_test_environment() -> Result { } #[test] +#[cfg_attr(not(feature = "e2e_contract"), ignore)] fn test_contract_build() -> Result<(), Error> { let temp_contract_dir = setup_test_environment()?; @@ -47,6 +48,7 @@ fn test_contract_build() -> Result<(), Error> { } #[test] +#[cfg_attr(not(feature = "e2e_contract"), ignore)] fn test_contract_build_specify_path() -> Result<(), Error> { let temp_contract_dir = setup_test_environment()?; @@ -78,6 +80,7 @@ fn test_contract_build_specify_path() -> Result<(), Error> { } #[test] +#[cfg_attr(not(feature = "e2e_contract"), ignore)] fn test_contract_build_fails_if_no_contract_exists() -> Result<(), Error> { // pop build contract Command::cargo_bin("pop") From 30774bf5138924ad8774e203dbe2b016e7272ba7 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Mon, 1 Apr 2024 20:39:18 +0200 Subject: [PATCH 05/10] refactor: rename one test --- tests/build_contract.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/build_contract.rs b/tests/build_contract.rs index ad880b56..3c15de14 100644 --- a/tests/build_contract.rs +++ b/tests/build_contract.rs @@ -17,7 +17,7 @@ fn setup_test_environment() -> Result { #[test] #[cfg_attr(not(feature = "e2e_contract"), ignore)] -fn test_contract_build() -> Result<(), Error> { +fn test_contract_build_success() -> Result<(), Error> { let temp_contract_dir = setup_test_environment()?; // pop build contract From 028c89e0f9e5b69c0f65ddc4250812ec02d4f609 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Tue, 2 Apr 2024 10:25:15 +0200 Subject: [PATCH 06/10] chore: run all tests in CI --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0472bc32..88993649 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -65,4 +65,4 @@ jobs: run: cargo build - name: Run unit tests - run: cargo test --bins \ No newline at end of file + run: cargo test --all-features -- --include-ignored \ No newline at end of file From b0688462b4a09b6e48ba0881de2d2e9971921ff7 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Thu, 4 Apr 2024 09:23:47 +0200 Subject: [PATCH 07/10] fix: pr feedback --- .github/workflows/build.yml | 2 +- tests/build_contract.rs | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 88993649..38187f63 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -64,5 +64,5 @@ jobs: - name: Build default features run: cargo build - - name: Run unit tests + - name: Run tests run: cargo test --all-features -- --include-ignored \ No newline at end of file diff --git a/tests/build_contract.rs b/tests/build_contract.rs index 3c15de14..972192bc 100644 --- a/tests/build_contract.rs +++ b/tests/build_contract.rs @@ -1,3 +1,4 @@ +#![cfg(feature = "e2e_contract")] use anyhow::{Error, Result}; use assert_cmd::Command; use predicates::prelude::*; @@ -16,7 +17,6 @@ fn setup_test_environment() -> Result { } #[test] -#[cfg_attr(not(feature = "e2e_contract"), ignore)] fn test_contract_build_success() -> Result<(), Error> { let temp_contract_dir = setup_test_environment()?; @@ -48,7 +48,6 @@ fn test_contract_build_success() -> Result<(), Error> { } #[test] -#[cfg_attr(not(feature = "e2e_contract"), ignore)] fn test_contract_build_specify_path() -> Result<(), Error> { let temp_contract_dir = setup_test_environment()?; @@ -80,7 +79,6 @@ fn test_contract_build_specify_path() -> Result<(), Error> { } #[test] -#[cfg_attr(not(feature = "e2e_contract"), ignore)] fn test_contract_build_fails_if_no_contract_exists() -> Result<(), Error> { // pop build contract Command::cargo_bin("pop") From e56a50343345f2ce6686ee972098d6fbf2d5a29b Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Thu, 4 Apr 2024 10:35:38 +0200 Subject: [PATCH 08/10] fix: remove ignore tests --- .github/workflows/build.yml | 2 +- Cargo.toml | 1 + src/engines/contract_engine.rs | 6 +++--- src/engines/parachain_engine.rs | 10 ---------- tests/build_parachain.rs | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 tests/build_parachain.rs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 38187f63..682dd740 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -65,4 +65,4 @@ jobs: run: cargo build - name: Run tests - run: cargo test --all-features -- --include-ignored \ No newline at end of file + run: cargo test --all-features \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 7f5cf96c..90d3bdd9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,6 +64,7 @@ contract = [ "dep:url", ] e2e_contract = [] +unit_contract = [] parachain = [ "dep:dirs", "dep:indexmap", diff --git a/src/engines/contract_engine.rs b/src/engines/contract_engine.rs index c293cd2a..64de9650 100644 --- a/src/engines/contract_engine.rs +++ b/src/engines/contract_engine.rs @@ -203,8 +203,8 @@ mod tests { Ok(()) } + #[cfg(feature = "unit_contract")] #[test] - #[ignore = "Build a contract takes long time to build"] fn test_contract_build() -> Result<(), Error> { let temp_contract_dir = setup_test_environment()?; @@ -229,9 +229,9 @@ mod tests { Ok(()) } - + + #[cfg(feature = "unit_contract")] #[test] - #[ignore = "Build a contract to test it takes long time to build"] fn test_contract_test() -> Result<(), Error> { let temp_contract_dir = setup_test_environment()?; diff --git a/src/engines/parachain_engine.rs b/src/engines/parachain_engine.rs index c68ee4e6..3c27069b 100644 --- a/src/engines/parachain_engine.rs +++ b/src/engines/parachain_engine.rs @@ -123,14 +123,4 @@ mod tests { Ok(()) } - - #[test] - #[ignore = "Build parachain takes long time to build"] - 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(()) - } } diff --git a/tests/build_parachain.rs b/tests/build_parachain.rs new file mode 100644 index 00000000..47f7d9d4 --- /dev/null +++ b/tests/build_parachain.rs @@ -0,0 +1,32 @@ +#![cfg(feature = "e2e_parachain")] +use anyhow::{Error, Result}; +use assert_cmd::Command; + +fn setup_test_environment() -> Result { + 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(()) +} \ No newline at end of file From db947e1e7501c07d6c6cb07bfb480ca2ebe50f58 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Thu, 4 Apr 2024 10:38:27 +0200 Subject: [PATCH 09/10] docs: update README --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 42978b0d..9a2e4035 100644 --- a/README.md +++ b/README.md @@ -216,6 +216,12 @@ Run the unit tests: cargo test ``` +Run only contracts unit tests: + +```sh +cargo test --features unit_contract +``` + Run the contracts e2e tests: ```sh @@ -228,8 +234,8 @@ Run the parachain e2e tests: cargo test --features e2e_parachain ``` -Run all tests, including the ignored ones: +Run all tests: ```sh -cargo test --all-features -- --include-ignored +cargo test --all-features ``` \ No newline at end of file From 98868667c8dee34442f445cf039e9537c9f5e73e Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Thu, 4 Apr 2024 12:06:25 +0200 Subject: [PATCH 10/10] chore: fmt --- src/engines/contract_engine.rs | 2 +- tests/build_parachain.rs | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/engines/contract_engine.rs b/src/engines/contract_engine.rs index 1675f2b3..6d657c6d 100644 --- a/src/engines/contract_engine.rs +++ b/src/engines/contract_engine.rs @@ -230,7 +230,7 @@ mod tests { Ok(()) } - + #[cfg(feature = "unit_contract")] #[test] fn test_contract_test() -> Result<(), Error> { diff --git a/tests/build_parachain.rs b/tests/build_parachain.rs index 47f7d9d4..06b0824a 100644 --- a/tests/build_parachain.rs +++ b/tests/build_parachain.rs @@ -17,16 +17,16 @@ fn setup_test_environment() -> Result { #[test] fn test_parachain_build_after_instantiating_template() -> Result<()> { - let temp_dir = setup_test_environment()?; + let temp_dir = setup_test_environment()?; - // pop build contract -p "./test_parachain" + // pop build contract -p "./test_parachain" Command::cargo_bin("pop") - .unwrap() - .current_dir(&temp_dir) - .args(&["build", "parachain", "-p", "./test_parachain"]) - .assert() - .success(); + .unwrap() + .current_dir(&temp_dir) + .args(&["build", "parachain", "-p", "./test_parachain"]) + .assert() + .success(); - assert!(temp_dir.path().join("test_parachain/target").exists()); - Ok(()) -} \ No newline at end of file + assert!(temp_dir.path().join("test_parachain/target").exists()); + Ok(()) +}