diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 4a93ec41..c09b2ee0 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -605,6 +605,34 @@ jobs: run: | bash watchdog/e2e-tests/upgradability.sh + watchdog_canister_metadata: + runs-on: ubuntu-20.04 + needs: cargo-build + + steps: + - uses: actions/checkout@v4 + - uses: actions/cache@v4 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-1 + + - name: Install Rust + run: | + rustup update ${{ matrix.rust }} --no-self-update + rustup default ${{ matrix.rust }} + rustup target add wasm32-unknown-unknown + + - name: Install dfx + uses: dfinity/setup-dfx@main + with: + dfx-version: $DFX_VERSION + + - name: Run watchdog_canister_metadata test + run: bash watchdog/e2e-tests/watchdog-canister-metadata.sh + canister-build-reproducibility: runs-on: ubuntu-20.04 diff --git a/Cargo.lock b/Cargo.lock index 37588b61..fc764f50 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4392,6 +4392,7 @@ dependencies = [ "assert-json-diff", "async-trait", "candid 0.10.10", + "candid_parser", "futures", "hex", "ic-btc-interface", diff --git a/scripts/build-canister.sh b/scripts/build-canister.sh index 435baa36..14e38689 100755 --- a/scripts/build-canister.sh +++ b/scripts/build-canister.sh @@ -39,10 +39,17 @@ if [[ "$STATUS" -eq "0" ]]; then -o "./target/$TARGET/release/$CANISTER.wasm" shrink if [[ "$CANISTER" == "ic-btc-canister" ]]; then - ./target/bin/ic-wasm \ - "./target/$TARGET/release/$CANISTER.wasm" \ - -o "./target/$TARGET/release/$CANISTER.wasm" \ - metadata candid:service -f "$SCRIPT_DIR/../canister/candid.did" -v public + ./target/bin/ic-wasm \ + "./target/$TARGET/release/$CANISTER.wasm" \ + -o "./target/$TARGET/release/$CANISTER.wasm" \ + metadata candid:service -f "$SCRIPT_DIR/../canister/candid.did" -v public + fi + + if [[ "$CANISTER" == "watchdog" ]]; then + ./target/bin/ic-wasm \ + "./target/$TARGET/release/$CANISTER.wasm" \ + -o "./target/$TARGET/release/$CANISTER.wasm" \ + metadata candid:service -f "$SCRIPT_DIR/../watchdog/candid.did" -v public fi true diff --git a/watchdog/Cargo.toml b/watchdog/Cargo.toml index 12734865..3437dfcf 100644 --- a/watchdog/Cargo.toml +++ b/watchdog/Cargo.toml @@ -27,4 +27,5 @@ serde_json = { workspace = true } [dev-dependencies] assert-json-diff = "2.0.2" +candid_parser = { workspace = true } tokio = { workspace = true } diff --git a/watchdog/e2e-tests/watchdog-canister-metadata.sh b/watchdog/e2e-tests/watchdog-canister-metadata.sh new file mode 100755 index 00000000..19d53a2c --- /dev/null +++ b/watchdog/e2e-tests/watchdog-canister-metadata.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -Eexuo pipefail + +SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +source "${SCRIPT_DIR}/utils.sh" + +# Run dfx stop if we run into errors. +trap "dfx stop" EXIT SIGINT + +dfx start --background --clean + +# Deploy the watchdog canister. +deploy_watchdog_canister_mainnet + +# Check the canister's metadata section for the Candid interface. +METADATA=$(dfx canister metadata watchdog candid:service) + +# Metadata returned should match the canister's .did file. +DIFF_OUTPUT=$(diff "$SCRIPT_DIR/../candid.did" <(echo "$METADATA")) + +if [ "$DIFF_OUTPUT" != "" ]; then + echo "FAIL" + exit 1 +fi + +echo "SUCCESS" diff --git a/watchdog/src/lib.rs b/watchdog/src/lib.rs index 0d769e66..3188dd2f 100644 --- a/watchdog/src/lib.rs +++ b/watchdog/src/lib.rs @@ -198,4 +198,22 @@ mod test { init(BitcoinNetwork::Mainnet); assert_eq!(get_config(), Config::mainnet()); } + + #[test] + fn test_candid_interface_compatibility() { + use candid_parser::utils::{service_compatible, CandidSource}; + use std::path::PathBuf; + + candid::export_service!(); + let rust_interface = __export_service(); + + let candid_interface = + PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()).join("candid.did"); + + service_compatible( + CandidSource::Text(&rust_interface), + CandidSource::File(candid_interface.as_path()), + ) + .expect("The canister implementation is not compatible with the candid.did file"); + } }