Skip to content

Commit

Permalink
test: integration tests, doc tests and improve coverage (#242)
Browse files Browse the repository at this point in the history
* test: fix tests in docs

* chore: add docs tests in CI

* test: skip_confirm flag for pop up parachain integration testing

* test: remove useless tests

* test: integration_tests whole process parachains and contracts

* chore: add integration tests in CI for contract and parachains

* fix: kill process contracts-node after tests

* test: more unit tests in pop_contracts

* test: unit test for call contracts

* test: unit tests for call contract

* fix: ci for running cargo test --doc

* fix: doc tests
  • Loading branch information
AlexD10S authored Jul 11, 2024
1 parent 70d3869 commit c776588
Show file tree
Hide file tree
Showing 19 changed files with 674 additions and 382 deletions.
57 changes: 53 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
files: codecov.json
fail_ci_if_error: true

contract-integration-tests:
documentation-tests:
needs: lint
runs-on: ubuntu-latest
steps:
Expand All @@ -98,18 +98,67 @@ jobs:
with:
git-user: ${{ env.GITHUB_ACTOR }}

- name: Run doc tests
run: cargo test --doc

contract-integration-tests:
needs: lint
strategy:
matrix:
os: ["ubuntu-latest", "macos-latest"]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
default: true
target: wasm32-unknown-unknown
components: rust-src, clippy

- name: Cache
uses: Swatinem/rust-cache@v2

- name: Run integration tests
run: cargo test --no-default-features --features contract --test contract

parachain-integration-tests:
needs: lint
runs-on: ubuntu-latest
strategy:
matrix:
os: ["ubuntu-latest", "macos-latest"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4

- uses: "./.github/actions/init"
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
default: true
target: wasm32-unknown-unknown
components: rust-src, clippy

- name: Cache
uses: Swatinem/rust-cache@v2

- name: Install packages (Linux)
if: matrix.os == 'ubuntu-latest'
uses: "./.github/actions/init"
with:
git-user: ${{ env.GITHUB_ACTOR }}

- name: Install packages (macOS)
if: matrix.os == 'macos-latest'
run: |
brew install protobuf
protoc --version
- name: Run integration tests
run: cargo test --no-default-features --features parachain --test parachain
37 changes: 37 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ predicates = "3.1.0"
tar = "0.4.40"
tempfile = "3.10"
thiserror = "1.0.58"
tokio-test = "0.4.4"

# networking
reqwest = { version = "0.12", features = ["json"] }
Expand Down
13 changes: 10 additions & 3 deletions crates/pop-cli/src/commands/up/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ use pop_contracts::{
};
use sp_core::Bytes;
use sp_weights::Weight;
use std::path::{Path, PathBuf};
use std::process::Child;
use std::{
path::{Path, PathBuf},
process::Command,
};
use tempfile::NamedTempFile;
use url::Url;

Expand Down Expand Up @@ -259,14 +262,18 @@ impl UpContractCommand {
/// Handles the optional termination of a local running node.
fn terminate_node(process: Option<(Child, NamedTempFile)>) -> anyhow::Result<()> {
// Prompt to close any launched node
let Some((mut process, log)) = process else {
let Some((process, log)) = process else {
return Ok(());
};
if confirm("Would you like to terminate the local node?")
.initial_value(true)
.interact()?
{
process.kill()?
// Stop the process contracts-node
Command::new("kill")
.args(["-s", "TERM", &process.id().to_string()])
.spawn()?
.wait()?;
} else {
log.keep()?;
log::warning(format!("NOTE: The node is running in the background with process ID {}. Please terminate it manually when done.", process.id()))?;
Expand Down
37 changes: 23 additions & 14 deletions crates/pop-cli/src/commands/up/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ pub(crate) struct ZombienetCommand {
/// Whether the output should be verbose.
#[arg(short, long, action)]
verbose: bool,
/// Automatically source all needed binaries required without prompting for confirmation.
#[clap(short('y'), long)]
skip_confirm: bool,
}

impl ZombienetCommand {
Expand Down Expand Up @@ -83,7 +86,7 @@ impl ZombienetCommand {
};

// Source any missing/stale binaries
if Self::source_binaries(&mut zombienet, &cache, self.verbose).await? {
if Self::source_binaries(&mut zombienet, &cache, self.verbose, self.skip_confirm).await? {
return Ok(());
}

Expand Down Expand Up @@ -159,6 +162,7 @@ impl ZombienetCommand {
zombienet: &mut Zombienet,
cache: &PathBuf,
verbose: bool,
skip_confirm: bool,
) -> anyhow::Result<bool> {
// Check for any missing or stale binaries
let binaries: Vec<_> = zombienet.binaries().filter(|b| !b.exists() || b.stale()).collect();
Expand Down Expand Up @@ -197,15 +201,17 @@ impl ZombienetCommand {
))
.dim()
.to_string();
if !confirm(format!(
if !skip_confirm {
if !confirm(format!(
"📦 Would you like to source them automatically now? It may take some time...\n {list}"))
.initial_value(true)
.interact()?
{
outro_cancel(
.initial_value(true)
.interact()?
{
outro_cancel(
"🚫 Cannot launch the specified network until all required binaries are available.",
)?;
return Ok(true);
return Ok(true);
}
}
}

Expand Down Expand Up @@ -235,13 +241,16 @@ impl ZombienetCommand {
log::warning(format!(
"ℹ️ The following binaries have newer versions available:\n {list}"
))?;

latest = confirm(
"📦 Would you like to source them automatically now? It may take some time..."
.to_string(),
)
.initial_value(true)
.interact()?;
if !skip_confirm {
latest = confirm(
"📦 Would you like to source them automatically now? It may take some time..."
.to_string(),
)
.initial_value(true)
.interact()?;
} else {
latest = true;
}
}

let binaries: Vec<_> = binaries
Expand Down
Loading

0 comments on commit c776588

Please sign in to comment.