diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b81c1943..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 --verbose \ 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 0344ae21..80ea5018 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,6 +64,8 @@ contract = [ "dep:sp-weights", "dep:url", ] +e2e_contract = [] +unit_contract = [] parachain = [ "dep:dirs", "dep:indexmap", @@ -76,3 +78,5 @@ parachain = [ "dep:zombienet-sdk", "dep:zombienet-support" ] +e2e_parachain = [] + diff --git a/README.md b/README.md index 5bea5a2f..1151783e 100644 --- a/README.md +++ b/README.md @@ -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! \ No newline at end of file +- [cargo contract](https://github.com/paritytech/cargo-contract) a setup and deployment tool for developing Wasm based smart contracts via ink! diff --git a/src/engines/contract_engine.rs b/src/engines/contract_engine.rs index d524aa43..6d657c6d 100644 --- a/src/engines/contract_engine.rs +++ b/src/engines/contract_engine.rs @@ -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()?; @@ -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()?; diff --git a/src/engines/parachain_engine.rs b/src/engines/parachain_engine.rs index e00c2b5e..f3329093 100644 --- a/src/engines/parachain_engine.rs +++ b/src/engines/parachain_engine.rs @@ -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(()) - } } diff --git a/tests/build_contract.rs b/tests/build_contract.rs index 65a0bfe8..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,7 @@ fn setup_test_environment() -> Result { } #[test] -fn test_contract_build() -> Result<(), Error> { +fn test_contract_build_success() -> Result<(), Error> { let temp_contract_dir = setup_test_environment()?; // pop build contract diff --git a/tests/build_parachain.rs b/tests/build_parachain.rs new file mode 100644 index 00000000..06b0824a --- /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(()) +}