Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add watchdog canister metadata #329

Merged
merged 9 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

15 changes: 11 additions & 4 deletions scripts/build-canister.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here tabs were changed to spaces.

"./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/../canister/candid.did" -v public
fi

true
Expand Down
19 changes: 10 additions & 9 deletions watchdog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@ name = "watchdog"
path = "src/main.rs"

[dependencies]
async-trait = "0.1.67"
maksymar marked this conversation as resolved.
Show resolved Hide resolved
candid = { workspace = true }
futures = { workspace = true }
hex = { workspace = true }
ic-btc-interface = { workspace = true }
ic-cdk = { workspace = true }
ic-cdk-macros = { workspace = true }
ic-metrics-encoder = { workspace = true }
ic-cdk-timers = "0.1"
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
hex = { workspace = true }
async-trait = "0.1.67"
regex = "1.7.0"
futures = { workspace = true }
ic-http = { workspace = true }
ic-metrics-encoder = { workspace = true }
regex = "1.7.0"
serde = { workspace = true, features = ["derive"] }
serde_bytes = { workspace = true }
ic-btc-interface = { workspace = true }
serde_json = { workspace = true }

[dev-dependencies]
tokio = { workspace = true }
assert-json-diff = "2.0.2"
candid_parser = { workspace = true }
tokio = { workspace = true }
26 changes: 26 additions & 0 deletions watchdog/e2e-tests/watchdog-canister-metadata.sh
Original file line number Diff line number Diff line change
@@ -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"
18 changes: 18 additions & 0 deletions watchdog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Loading