diff --git a/contracts/icp/context-config/build.sh b/contracts/icp/context-config/build.sh index 8e9f2f742..e3cd26f5d 100755 --- a/contracts/icp/context-config/build.sh +++ b/contracts/icp/context-config/build.sh @@ -1,22 +1,18 @@ -#!/bin/bash - -# Exit on error +#!/bin/sh set -e -# Ensure we have the wasm32 target -rustup target add wasm32-unknown-unknown +cd "$(dirname $0)" -# Build the contract -cargo build --target wasm32-unknown-unknown --release +TARGET="${CARGO_TARGET_DIR:-./target}" + +rustup target add wasm32-unknown-unknown -# Generate the candid interface -candid-extractor target/wasm32-unknown-unknown/release/context_contract.wasm > context_contract.did +cargo build --target wasm32-unknown-unknown --profile app-release -# Stop the replica -dfx stop +mkdir -p res -# Start the replica -dfx start --background +cp $TARGET/wasm32-unknown-unknown/app-release/context_contract.wasm ./res/context_contract.wasm -# Deploy the contract -dfx deploy \ No newline at end of file +if command -v wasm-opt > /dev/null; then + wasm-opt -Oz ./res/context_contract.wasm -o ./res/context_contract.wasm +fi diff --git a/contracts/icp/context-config/deploy_devnet.sh b/contracts/icp/context-config/deploy_devnet.sh new file mode 100644 index 000000000..4174ccade --- /dev/null +++ b/contracts/icp/context-config/deploy_devnet.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Build the contract +bash ./build.sh + +# Generate the candid interface +candid-extractor res/context_contract.wasm > context_contract.did + +# Stop the replica +dfx stop + +# Start the replica +dfx start --background + +# Deploy the contract +dfx deploy \ No newline at end of file diff --git a/contracts/icp/context-config/src/types.rs b/contracts/icp/context-config/src/types.rs index da3c2adff..7c60d49a9 100644 --- a/contracts/icp/context-config/src/types.rs +++ b/contracts/icp/context-config/src/types.rs @@ -97,10 +97,6 @@ impl ICContextId { pub fn new(bytes: [u8; 32]) -> Self { Self(Identity(bytes)) } - - pub fn as_bytes(&self) -> [u8; 32] { - self.0.as_bytes() - } } impl ReprBytes for ICContextId { diff --git a/contracts/icp/context-config/tests/integration.rs b/contracts/icp/context-config/tests/integration.rs index 99bd68262..07090e510 100644 --- a/contracts/icp/context-config/tests/integration.rs +++ b/contracts/icp/context-config/tests/integration.rs @@ -1,5 +1,6 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH}; +use calimero_context_config::repr::ReprBytes; use candid::Principal; use context_contract::types::{ ContextRequest, ContextRequestKind, ICApplication, ICApplicationId, ICBlobId, ICCapability, @@ -11,8 +12,7 @@ use rand::Rng; fn setup() -> (PocketIc, Principal) { let pic = PocketIc::new(); - let wasm = std::fs::read("target/wasm32-unknown-unknown/release/context_contract.wasm") - .expect("failed to read wasm"); + let wasm = std::fs::read("res/context_contract.wasm").expect("failed to read wasm"); let canister = pic.create_canister(); pic.add_cycles(canister, 2_000_000_000_000); pic.install_canister( diff --git a/scripts/test.sh b/scripts/test.sh index 35438717e..7da681894 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -12,6 +12,7 @@ cd "$(dirname $0)" ../contracts/registry/build.sh ../contracts/context-config/build.sh ../contracts/proxy-lib/build-test-deps.sh +../contracts/icp/context-config/build.sh # Run cargo test cargo test