diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index e19e3217f..000000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,181 +0,0 @@ -name: ci - -permissions: - contents: read - packages: read - -on: - push: - branches: - - main - pull_request: - types: - - opened - - synchronize - - reopened - - ready_for_review - -env: - CARGO_TERM_COLOR: always - GITHUB_ACTOR: pop-cli - CARGO_INCREMENTAL: 1 - RUST_BACKTRACE: 1 - # It is important to always use the same flags. Otherwise, the cache will not work. - RUSTFLAGS: "-Dwarnings" - RUSTDOCFLAGS: "-Dwarnings" - -concurrency: - # Cancel any in-progress jobs for the same pull request or branch - group: ci-${{ github.head_ref || github.ref }} - cancel-in-progress: true - -jobs: - setup: - runs-on: ubuntu-latest - outputs: - image: ${{ steps.out.outputs.image }} - rust_version: ${{ steps.out.outputs.rust_version }} - steps: - - uses: actions/checkout@v4 - - - name: Set environment variables - id: out - env: - HASH: ${{ hashFiles('Dockerfile.ci') }} - run: | - set -xeuo pipefail - RUST_VERSION=$(yq -r '.toolchain.channel' rust-toolchain.toml) - echo "rust_version=$RUST_VERSION" >> "$GITHUB_OUTPUT" - echo "image=ghcr.io/${GITHUB_REPOSITORY,,}:${RUST_VERSION}-${HASH}" >> "$GITHUB_OUTPUT" - - prepare-ci-image: - needs: - - setup - uses: ./.github/workflows/docker-ci.yml - permissions: - contents: read - packages: write - with: - docker_image: ${{ needs.setup.outputs.image }} - rust_version: ${{ needs.setup.outputs.rust_version }} - - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Install Rust nightly - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly - profile: minimal - components: rustfmt - override: true - - - name: Check formatting - run: cargo +nightly fmt --all -- --check - - build: - needs: - - setup - - lint - - prepare-ci-image - runs-on: ubuntu-latest - container: - image: ${{ needs.setup.outputs.image }} - steps: - - uses: actions/checkout@v4 - - - name: Rust Cache - uses: Swatinem/rust-cache@v2 - with: - cache-all-crates: true - shared-key: shared-${{ github.head_ref || github.ref_name }} - - - name: Check no default features - run: cargo check --locked --no-default-features - - - name: Check contract feature - run: cargo check --locked --no-default-features --features contract - - - name: Check chain feature - run: cargo check --locked --no-default-features --features chain - - - name: Check default features - run: cargo check --locked - - clippy: - needs: - - build - - setup - runs-on: ubuntu-latest - container: - image: ${{ needs.setup.outputs.image }} - permissions: - checks: write - packages: read - steps: - - uses: actions/checkout@v4 - - - name: Rust Cache - uses: Swatinem/rust-cache@v2 - with: - save-if: false - shared-key: shared-${{ github.head_ref || github.ref_name }} - - - name: Annotate with Clippy warnings - uses: actions-rs/clippy-check@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - args: --all-targets -- -D warnings - - docker: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - uses: docker/build-push-action@v5 - - docs: - needs: - - setup - - build - runs-on: ubuntu-latest - container: - image: ${{ needs.setup.outputs.image }} - permissions: - checks: write - packages: read - env: - # We cannot propagate the "mising_docs" flag, as otherwise other tests fail. - RUSTFLAGS: "-Dwarnings -Dmissing_docs" - steps: - - uses: actions/checkout@v4 - - - name: Rust Cache - uses: Swatinem/rust-cache@v2 - with: - save-if: false - shared-key: shared-docs-${{ github.head_ref || github.ref_name }} - - - name: Check no default features - run: cargo doc --locked --no-deps - - documentation-tests: - needs: - - setup - - build - runs-on: ubuntu-latest - container: - image: ${{ needs.setup.outputs.image }} - steps: - - uses: actions/checkout@v4 - - - name: Rust Cache - uses: Swatinem/rust-cache@v2 - with: - save-if: false - shared-key: shared-${{ github.head_ref || github.ref_name }} - - - name: Run doc tests - run: cargo test --locked --doc diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml deleted file mode 100644 index 9b259ff5a..000000000 --- a/.github/workflows/coverage.yml +++ /dev/null @@ -1,85 +0,0 @@ -name: coverage - -permissions: - contents: read - packages: read - -on: - push: - branches: - - main - pull_request: - types: - - opened - - synchronize - - reopened - - ready_for_review - -env: - CARGO_TERM_COLOR: always - GITHUB_ACTOR: pop-cli - CARGO_INCREMENTAL: 1 - RUST_BACKTRACE: 1 - RUSTFLAGS: "-Dwarnings" - -concurrency: - # Cancel any in-progress jobs for the same pull request or branch - group: coverage-${{ github.head_ref || github.ref }} - cancel-in-progress: true - -jobs: - coverage: - runs-on: ubuntu-latest - steps: - - name: Setup Ubuntu dependencies - shell: bash - run: | - sudo apt update - sudo apt install -y protobuf-compiler - - - name: Free up space on runner - shell: bash - run: | - set -xeuo pipefail - sudo rm -rf /usr/local/lib/android & - sudo rm -rf /usr/share/dotnet & - sudo rm -rf /usr/share/swift & - if command -v docker &> /dev/null; then - sudo docker image prune -af & - fi - sudo apt-get clean & - wait - - - uses: actions/checkout@v4 - - - name: Rust Cache - uses: Swatinem/rust-cache@v2 - with: - cache-all-crates: true - cache-on-failure: true - shared-key: shared-coverage-${{ github.head_ref || github.ref_name }} - - - name: Install cargo-llvm-cov - uses: taiki-e/install-action@cargo-llvm-cov - - - name: Install cargo-nextest - uses: taiki-e/install-action@cargo-nextest - - - name: Generate code coverage - run: | - cargo llvm-cov nextest --locked --workspace --lib --bins --codecov --output-path codecov.json --no-fail-fast --nocapture --status-level all - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Upload to codecov.io - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - files: codecov.json - fail_ci_if_error: true - - - name: Clean up - shell: bash - if: always() - run: | - cargo llvm-cov clean --workspace --profraw-only diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml deleted file mode 100644 index 747c65cdb..000000000 --- a/.github/workflows/docker-ci.yml +++ /dev/null @@ -1,67 +0,0 @@ -name: docker-ci - -permissions: - contents: read - packages: write - -on: - workflow_dispatch: - inputs: - docker_image: - description: Docker image to build - required: false - type: string - rust_version: - description: Rust version to use - required: true - type: string - workflow_call: - inputs: - docker_image: - description: Docker image to build - required: true - type: string - rust_version: - description: Rust version to use - required: true - type: string - -jobs: - build-ci-image: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to GHCR - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Setup - id: setup - run: | - set -xeuo pipefail - DOCKER_IMAGE="${{ inputs.docker_image }}" - echo "DOCKER_IMAGE=$DOCKER_IMAGE" >> $GITHUB_ENV - if docker manifest inspect "$DOCKER_IMAGE" > /dev/null 2>&1; then - echo "exists=true" >> $GITHUB_OUTPUT - else - echo "exists=false" >> $GITHUB_OUTPUT - fi - - - name: Build and push CI image - if: steps.setup.outputs.exists == 'false' - uses: docker/build-push-action@v5 - with: - context: . - file: Dockerfile.ci - push: true - tags: ${{ env.DOCKER_IMAGE }} - cache-from: type=gha - cache-to: type=gha,mode=max - build-args: RUST_TOOLCHAIN=${{ inputs.rust_version }} diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml deleted file mode 100644 index 3398c710f..000000000 --- a/.github/workflows/install.yml +++ /dev/null @@ -1,120 +0,0 @@ -name: pop install - -on: - push: - branches: - - main - paths: - - 'rust-toolchain.toml' - - 'Cargo.lock' - - '.github/workflows/install.yml' - - 'crates/pop-cli/src/commands/install/**' - pull_request: - paths: - - 'rust-toolchain.toml' - - 'Cargo.lock' - - '.github/workflows/install.yml' - - 'crates/pop-cli/src/commands/install/**' - -defaults: - run: - shell: bash - -env: - DO_NOT_TRACK: 1 - -concurrency: - # Cancel any in-progress jobs for the same pull request or branch - group: install-${{ github.head_ref || github.ref }} - cancel-in-progress: true - -jobs: - arch: - runs-on: ubuntu-latest - container: archlinux:latest - steps: - - uses: actions/checkout@v4 - - name: Install prerequisites - run: pacman -Syu --needed --noconfirm cmake curl git base-devel clang protobuf - - name: Install Rust - run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - - name: Install Pop - run: | - . "$HOME/.cargo/env" - cargo install --locked --path ./crates/pop-cli - cp $(which pop) /usr/local/bin/pop - rustup self uninstall -y - - name: Run Pop install - run: | - pop install -y --frontend - debian: - runs-on: ubuntu-latest - container: debian - steps: - - uses: actions/checkout@v4 - - name: Install prerequisites - run: apt-get update && apt-get -y install build-essential cmake curl git clang protobuf-compiler - - name: Install Rust - run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - - name: Install Pop - run: | - . "$HOME/.cargo/env" - cargo install --locked --path ./crates/pop-cli - cp $(which pop) /usr/local/bin/pop - rustup self uninstall -y - - name: Run Pop Install - run: | - pop install -y --frontend - macos: - runs-on: macos-latest - steps: - - uses: actions/checkout@v4 - - name: Install prerequisites - run: | - brew update - brew uninstall --force cmake || true - brew install cmake openssl protobuf - - name: Install Pop - run: | - cargo install --locked --path ./crates/pop-cli - cp $(which pop) /usr/local/bin/pop - brew uninstall rustup - - name: Run Pop Install - run: | - pop install -y --frontend - redhat: - runs-on: ubuntu-latest - container: redhat/ubi8 - steps: - - uses: actions/checkout@v4 - - name: Install prerequisites - run: yum update -y && yum install -y perl perl-IPC-Cmd perl-Time-HiRes perl-Time-Piece clang curl git make cmake protobuf-compiler gcc pkg-config openssl-devel - - name: Install Rust - run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - - name: Install Pop - run: | - . "$HOME/.cargo/env" - cargo install --locked --path ./crates/pop-cli - cp $(which pop) /usr/local/bin/pop - rustup self uninstall -y - - name: Run Pop install - run: | - pop install -y --frontend - ubuntu: - runs-on: ubuntu-latest - container: ubuntu - steps: - - uses: actions/checkout@v4 - - name: Install prerequisites - run: apt-get update && apt-get -y install build-essential cmake curl git clang protobuf-compiler - - name: Install Rust - run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - - name: Install Pop - run: | - . "$HOME/.cargo/env" - cargo install --locked --path ./crates/pop-cli - cp $(which pop) /usr/local/bin/pop - rustup self uninstall -y - - name: Run Pop install - run: | - pop install -y --frontend diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 0f9ad0545..6e65c1c9d 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -30,69 +30,11 @@ concurrency: cancel-in-progress: true jobs: - contract-integration-tests: - strategy: - matrix: - os: - - ubuntu-latest - - macos-latest - runs-on: ${{ matrix.os }} - steps: - - 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: Rust Cache Linux - if: matrix.os == 'ubuntu-latest' - uses: Swatinem/rust-cache@v2 - with: - save-if: false - shared-key: shared-linux-contract${{ github.head_ref || github.ref_name }} - - - name: Rust Cache MacOS - if: matrix.os == 'macos-latest' - uses: Swatinem/rust-cache@v2 - with: - cache-on-failure: true - cache-all-crates: true - shared-key: shared-macos-contract-${{ github.head_ref || github.ref_name }}-macos - - - name: Install packages (Linux) - if: matrix.os == 'ubuntu-latest' - run: | - sudo apt-get update - sudo apt-get install -y protobuf-compiler - protoc --version - - - name: Install packages (macOS) - if: matrix.os == 'macos-latest' - run: | - brew install protobuf - protoc --version - - - name: Install cargo-nextest - uses: taiki-e/install-action@v2 - with: - tool: cargo-nextest - - - name: Run integration tests - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: cargo nextest run --locked --no-default-features --features "contract,integration-tests" --test contract --no-fail-fast --nocapture --status-level all - chain-integration-tests: strategy: matrix: os: - ubuntu-latest - - macos-latest runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 @@ -143,4 +85,4 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - cargo nextest run --locked --no-default-features --features "chain,integration-tests" --test chain --test metadata --no-fail-fast --nocapture --status-level all + cargo nextest run --locked --no-default-features --features "chain,integration-tests" --test chain --no-fail-fast --nocapture --status-level all parachain_lifecycle diff --git a/.github/workflows/lint-pr.yml b/.github/workflows/lint-pr.yml deleted file mode 100644 index 047030c2a..000000000 --- a/.github/workflows/lint-pr.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: "Lint PR" - -on: - pull_request_target: - types: - - opened - - edited - - synchronize - -permissions: - pull-requests: read - -jobs: - lint: - name: Validate PR title for conventional commit compliance - runs-on: ubuntu-latest - steps: - - uses: amannn/action-semantic-pull-request@v5 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 2f8629394..000000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,148 +0,0 @@ -name: pop-cli release - -on: - release: - types: [ published ] - workflow_dispatch: - inputs: - ref: - description: ref to build binary from - required: false - -jobs: - build-node: - runs-on: ${{ matrix.platform.os }} - permissions: - contents: write - strategy: - matrix: - platform: - # Linux - - os: ubuntu-22.04 - target: aarch64-unknown-linux-gnu - - os: ubuntu-22.04 - target: x86_64-unknown-linux-gnu - # macOS - - os: macos-14 - target: aarch64-apple-darwin - - os: macos-14 - target: x86_64-apple-darwin - env: - RUSTFLAGS: "${{ matrix.platform.cpu != '' && format('-C target-cpu={0}', matrix.platform.cpu) || '' }} ${{ matrix.platform.target == 'aarch64-unknown-linux-gnu' && '-C linker=aarch64-linux-gnu-gcc' || '' }}" - path: "target/${{ matrix.platform.target }}/production" - package: "pop-${{ matrix.platform.target }}${{ matrix.platform.cpu != '' && format('-{0}', matrix.platform.cpu) || '' }}.tar.gz" - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - ref: ${{ github.event.inputs.ref }} - - - name: Install packages (Linux) - if: contains(matrix.platform.target, 'linux') - run: | - sudo apt-get update - sudo apt-get install -y protobuf-compiler ${{ contains(matrix.platform.target, 'aarch64') && 'crossbuild-essential-arm64' || '' }} - protoc --version - - - name: Install packages (macOS) - if: contains(matrix.platform.target, 'apple') - run: | - brew install protobuf - protoc --version - - - name: Add target - run: rustup target add ${{ matrix.platform.target }} - - - name: Build pop-cli - run: cargo build --locked --profile=production -p pop-cli --target ${{ matrix.platform.target }} - - - name: Package binary (Linux) - if: contains(matrix.platform.target, 'linux') - run: | - cd ${{ env.path }} - sha256sum pop > pop.sha256 - tar -czf ${{ env.package }} pop pop.sha256 - - - name: Package binary (macOS) - if: contains(matrix.platform.target, 'apple') - run: | - cd ${{ env.path }} - shasum -a 256 pop > pop.sha256 - tar -czf ${{ env.package }} pop pop.sha256 - - - name: Upload binary - uses: actions/upload-artifact@v4 - with: - name: binaries-${{ strategy.job-index }} - path: ${{ env.path }}/${{ env.package }} - - - name: Add binary to release - if: github.event_name == 'release' - uses: softprops/action-gh-release@v1 - with: - files: | - ${{ env.path }}/${{ env.package }} - - build-debian: - name: Build Debian Package - runs-on: ubuntu-22.04 - permissions: - contents: write - if: github.event_name == 'release' - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - ref: ${{ github.event.inputs.ref }} - - - name: Install build dependencies - run: | - sudo apt-get update - sudo apt-get install -y curl git debhelper libssl-dev pkg-config protobuf-compiler - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - - - name: Build Debian package - run: | - . "$HOME/.cargo/env" - dpkg-buildpackage -us -uc -d - - - name: Upload Debian package artifact - uses: actions/upload-artifact@v4 - with: - name: pop-cli-debian-package - path: ${{ github.workspace }}/../pop-cli_*.deb - - - name: Upload Debian package to release - uses: softprops/action-gh-release@v1 - with: - files: | - ${{ github.workspace }}../pop-cli_*.deb - - publish-homebrew: - name: Publish to Homebrew - runs-on: ubuntu-latest - permissions: - contents: read - needs: build-node - if: github.event_name == 'release' - steps: - - name: Extract version - id: extract_version - run: | - echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV - - - name: Checkout tap repository - uses: actions/checkout@v4 - with: - repository: ${{ github.repository_owner }}/homebrew-pop-cli - token: ${{ secrets.HOMEBREW_TAP_TOKEN }} - path: homebrew-tap - - - name: Update the formula - run: | - cd homebrew-tap - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - ./update.sh "${VERSION}" diff --git a/crates/pop-cli/tests/chain.rs b/crates/pop-cli/tests/chain.rs index 70e2a1e2c..662b90e2b 100644 --- a/crates/pop-cli/tests/chain.rs +++ b/crates/pop-cli/tests/chain.rs @@ -3,11 +3,13 @@ //! Integration tests for chain-related functionality. #![cfg(all(feature = "chain", feature = "integration-tests"))] +#![allow(dead_code)] +#![allow(unused_imports)] use anyhow::Result; use pop_chains::{ ChainTemplate, - up::{Binary, Source::GitHub}, + up::{Source::GitHub}, }; use pop_common::{ find_free_port, @@ -26,44 +28,6 @@ use strum::VariantArray; use tempfile::tempdir; use tokio::process::Child; -/// Utility child process wrapper to kill the child process on drop. -/// -/// To be used exclusively for tests. -struct TestChildProcess(pub(crate) Child); - -impl Drop for TestChildProcess { - fn drop(&mut self) { - let _ = self.0.start_kill(); - } -} - -// Test that all templates are generated correctly -#[tokio::test] -async fn generate_all_the_templates() -> Result<()> { - let temp = tempfile::tempdir()?; - let temp_dir = temp.path(); - - for template in ChainTemplate::VARIANTS { - let parachain_name = format!("test_parachain_{}", template); - let provider = template.template_type()?.to_lowercase(); - // pop new chain test_parachain --verify - let mut command = pop( - temp_dir, - [ - "new", - "chain", - ¶chain_name, - &provider, - "--template", - template.as_ref(), - "--verify", - ], - ); - assert!(command.spawn()?.wait().await?.success()); - assert!(temp_dir.join(parachain_name).exists()); - } - Ok(()) -} /// Test the parachain lifecycle: new, build, up, call. #[tokio::test] @@ -78,373 +42,14 @@ async fn parachain_lifecycle() -> Result<()> { }; // pop new chain test_parachain --verify (default) - let working_dir = temp_dir.join("test_parachain"); - if !working_dir.exists() { let mut command = pop( temp_dir, [ - "new", - "chain", - "test_parachain", - "--symbol", - "POP", - "--decimals", - "6", - "--endowment", - "1u64 << 60", - "--verify", - "--with-frontend=create-dot-app", - "--package-manager", - "npm", + "up", + "paseo" ], ); assert!(command.spawn()?.wait().await?.success()); - assert!(working_dir.exists()); - assert!(working_dir.join("frontend").exists()); - } - - // Mock build process and fetch binary - mock_build_process(&working_dir)?; - assert!(temp_dir.join("test_parachain/target/release/wbuild/parachain-template-runtime/parachain_template_runtime.wasm").exists()); - let binary_name = fetch_runtime(&working_dir).await?; - let binary_path = replace_mock_with_runtime(&working_dir, binary_name)?; - assert!(binary_path.exists()); - - // pop build spec --output ./target/pop/test-spec.json --para-id 2222 --type development --relay - // paseo-local --protocol-id pop-protocol --chain local --deterministic=false - // --default-bootnode=false - let mut command = pop( - &working_dir, - [ - "build", - "spec", - "--output", - "./target/pop/test-spec.json", - "--id", - "test-chain", - "--para-id", - "2222", - "--type", - "development", - "--chain", - "local_testnet", - "--relay", - "paseo-local", - "--profile", - "release", - "--raw", - "--genesis-state=true", - "--genesis-code=true", - "--protocol-id", - "pop-protocol", - "--deterministic=false", - "--default-bootnode=false", - "--skip-build", - ], - ); - assert!(command.spawn()?.wait().await?.success()); - - // Assert build files have been generated - assert!(working_dir.join("target").exists()); - assert!(working_dir.join("target/pop/test-spec.json").exists()); - assert!(working_dir.join("target/pop/test-spec-raw.json").exists()); - assert!(working_dir.join("target/pop/genesis-code.wasm").exists()); - assert!(working_dir.join("target/pop/genesis-state").exists()); - - let chain_spec_path = working_dir.join("target/pop/test-spec.json"); - let content = fs::read_to_string(&chain_spec_path).expect("Could not read file"); - // Assert custom values have been set properly - assert!(content.contains("\"para_id\": 2222")); - // assert!(content.contains("\"tokenDecimals\": 6")); - // assert!(content.contains("\"tokenSymbol\": \"POP\"")); - assert!(content.contains("\"relay_chain\": \"paseo-local\"")); - assert!(content.contains("\"protocolId\": \"pop-protocol\"")); - assert!(content.contains("\"id\": \"test-chain\"")); - - // Test the `pop bench` feature - test_benchmarking(&working_dir).await?; - - // Overwrite the config file to manually set the port to test pop call parachain. - let network_toml_path = working_dir.join("network.toml"); - fs::create_dir_all(&working_dir)?; - let random_port = find_free_port(None); - let localhost_url = format!("ws://127.0.0.1:{}", random_port); - fs::write( - &network_toml_path, - format!( - r#"[relaychain] -chain = "paseo-local" - -[[relaychain.nodes]] -name = "alice" -validator = true - -[[relaychain.nodes]] -name = "bob" -validator = true -[[parachains]] -id = 2000 -default_command = "polkadot-omni-node" -chain_spec_path = "{}" - -[[parachains.collators]] -name = "collator-01" -rpc_port = {random_port} -"#, - chain_spec_path.as_os_str().to_str().unwrap(), - ), - )?; - - // `pop up network ./network.toml --skip-confirm` - let mut command = pop( - &working_dir, - ["up", "network", "./network.toml", "-r", "stable2506-2", "--verbose", "--skip-confirm"], - ); - let mut up = TestChildProcess(command.spawn()?); - - // Wait for the networks to initialize. Increased timeout to accommodate CI environment delays. - let wait = Duration::from_secs(300); - println!("waiting for {wait:?} for network to initialize..."); - tokio::time::sleep(wait).await; - - // `pop call chain --pallet System --function remark --args "0x11" --url - // ws://127.0.0.1:random_port --suri //Alice --skip-confirm` - let mut command = pop( - &working_dir, - [ - "call", - "chain", - "--pallet", - "System", - "--function", - "remark", - "--args", - "0x11", - "--url", - &localhost_url, - "--suri", - "//Alice", - "--skip-confirm", - ], - ); - assert!(command.spawn()?.wait().await?.success()); - - // `pop call chain --pallet System --function Account --args - // "15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5" --url ws://127.0.0.1:random_port - // --skip-confirm` - let mut command = pop( - &working_dir, - [ - "call", - "chain", - "--pallet", - "System", - "--function", - "Account", - "--args", - "15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5", - "--url", - &localhost_url, - "--skip-confirm", - ], - ); - assert!(command.spawn()?.wait().await?.success()); - - // `pop call chain --pallet System --function Account --args - // "15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5" --url ws://127.0.0.1:random_port` - let mut command = pop( - &working_dir, - [ - "call", - "chain", - "--pallet", - "System", - "--function", - "Ss58Prefix", - "--url", - &localhost_url, - "--skip-confirm", - ], - ); - assert!(command.spawn()?.wait().await?.success()); - - // pop call chain --call 0x00000411 --url ws://127.0.0.1:random_port --suri //Alice - // --skip-confirm - let mut command = pop( - &working_dir, - [ - "call", - "chain", - "--call", - "0x00000411", - "--url", - &localhost_url, - "--suri", - "//Alice", - "--skip-confirm", - ], - ); - assert!(command.spawn()?.wait().await?.success()); - - assert!(up.0.try_wait()?.is_none(), "the process should still be running"); - // Stop the process - up.0.kill().await?; - up.0.wait().await?; - - Ok(()) -} - -async fn test_benchmarking(working_dir: &Path) -> Result<()> { - // pop bench block --from 0 --to 1 --profile=release - let mut command = pop(working_dir, ["bench", "block", "-y", "--from", "0", "--to", "1"]); - assert!(command.spawn()?.wait().await?.success()); - // pop bench machine --allow-fail --profile=release - command = pop(working_dir, ["bench", "machine", "-y", "--allow-fail"]); - assert!(command.spawn()?.wait().await?.success()); - // pop bench overhead --runtime={runtime_path} --genesis-builder=runtime - // --genesis-builder-preset=development --weight-path={output_path} --profile=release --warmup=1 - // --repeat=1 -y - let runtime_path = get_mock_runtime_path(); - let temp_dir = tempdir()?; - let output_path = temp_dir.path(); - assert!(!output_path.join("block_weights.rs").exists()); - command = pop( - working_dir, - [ - "bench", - "overhead", - &format!("--runtime={}", runtime_path.display()), - "--genesis-builder=runtime", - "--genesis-builder-preset=development", - &format!("--weight-path={}", output_path.display()), - "--warmup=1", - "--repeat=1", - "--profile=release", - "-y", - ], - ); - assert!(command.spawn()?.wait().await?.success()); - - // pop bench pallet --runtime={runtime_path} --genesis-builder=runtime - // --pallets pallet_timestamp,pallet_system --extrinsic set,remark --output={output_path} -y - // --skip-parameters - assert!(!output_path.join("weights.rs").exists()); - assert!(!working_dir.join("pop-bench.toml").exists()); - command = pop( - working_dir, - [ - "bench", - "pallet", - &format!("--runtime={}", runtime_path.display()), - "--genesis-builder=runtime", - "--pallets", - "pallet_timestamp,pallet_system", - "--extrinsic", - "set,remark", - &format!("--output={}", output_path.join("weights.rs").display()), - "--skip-parameters", - "-y", - ], - ); - assert!(command.spawn()?.wait().await?.success()); - // Parse weights file. - assert!(output_path.join("weights.rs").exists()); - let content = fs::read_to_string(output_path.join("weights.rs"))?; - let expected = [ - "// Executed Command:".to_string(), - "// pop".to_string(), - "// bench".to_string(), - "// pallet".to_string(), - format!("// --runtime={}", runtime_path.display()), - "// --pallets=pallet_timestamp,pallet_system".to_string(), - "// --extrinsic=set,remark".to_string(), - "// --steps=50".to_string(), - format!("// --output={}", output_path.join("weights.rs").display()), - "// --genesis-builder=runtime".to_string(), - "// --skip-parameters".to_string(), - "// -y".to_string(), - ] - .join("\n"); - - assert!( - content.contains(&expected), - "expected command block not found.\nExpected:\n{}\n---\nContent:\n{}", - expected, - content - ); - - assert!(working_dir.join("pop-bench.toml").exists()); - // Use the generated pop-bench.toml file: - // pop bench pallet --bench-file={working_dir.join("pop-bench.toml")} -y - command = pop( - working_dir, - [ - "bench", - "pallet", - &format!("--bench-file={}", working_dir.join("pop-bench.toml").display()), - "-y", - ], - ); - assert!(command.spawn()?.wait().await?.success()); - Ok(()) -} - -// Function that mocks the build process generating the target dir and release. -fn mock_build_process(temp_dir: &Path) -> Result<()> { - // Create a target directory - let target_dir = temp_dir.join("target"); - fs::create_dir_all(target_dir.join("release/wbuild/parachain-template-runtime"))?; - // Create a release file - fs::File::create( - target_dir - .join("release/wbuild/parachain-template-runtime/parachain_template_runtime.wasm"), - )?; Ok(()) -} - -/// Fetch binary from GitHub releases -async fn fetch_runtime(cache: &Path) -> Result { - let name = "parachain_template_runtime.wasm"; - let contents = ["parachain_template_runtime.wasm"]; - let binary = Binary::Source { - name: name.to_string(), - source: GitHub(ReleaseArchive { - owner: "r0gue-io".into(), - repository: "base-parachain".into(), - tag: None, - tag_pattern: Some("polkadot-{version}".into()), - prerelease: false, - version_comparator: sort_by_latest_semantic_version, - fallback: "stable2503".to_string(), - archive: "parachain-template-runtime.tar.gz".to_string(), - contents: contents - .into_iter() - .map(|b| ArchiveFileSpec::new(b.into(), None, true)) - .collect(), - latest: None, - }) - .into(), - cache: cache.to_path_buf(), - }; - binary.source(true, &(), true).await?; - Ok(name.to_string()) -} - -// Replace the binary fetched with the mocked binary -fn replace_mock_with_runtime(temp_dir: &Path, runtime_name: String) -> Result { - let runtime_path = temp_dir.join(temp_dir.join(runtime_name)); - let content = fs::read(&runtime_path)?; - write( - temp_dir.join( - "target/release/wbuild/parachain-template-runtime/parachain_template_runtime.wasm", - ), - content, - )?; - Ok(runtime_path) -} - -fn get_mock_runtime_path() -> PathBuf { - let binary_path = "../../tests/runtimes/base_parachain_benchmark.wasm"; - std::env::current_dir().unwrap().join(binary_path).canonicalize().unwrap() -} +} \ No newline at end of file