From 3321e6add796ee481252a1d43a48ea728a6f2e6d Mon Sep 17 00:00:00 2001 From: alenmestrov Date: Sun, 1 Dec 2024 18:37:31 +0100 Subject: [PATCH 1/4] fix: removed wrong as_bytes --- contracts/icp/context-config/src/types.rs | 4 ---- contracts/icp/context-config/tests/integration.rs | 1 + 2 files changed, 1 insertion(+), 4 deletions(-) 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..00fb0d91c 100644 --- a/contracts/icp/context-config/tests/integration.rs +++ b/contracts/icp/context-config/tests/integration.rs @@ -5,6 +5,7 @@ use context_contract::types::{ ContextRequest, ContextRequestKind, ICApplication, ICApplicationId, ICBlobId, ICCapability, ICContextId, ICContextIdentity, ICPSigned, ICSignerId, Request, RequestKind, }; +use calimero_context_config::repr::ReprBytes; use ed25519_dalek::{Signer, SigningKey}; use pocket_ic::{PocketIc, WasmResult}; use rand::Rng; From bd54748b8340387b95884287c1df5f6a24fd0ec5 Mon Sep 17 00:00:00 2001 From: alenmestrov Date: Sun, 1 Dec 2024 18:38:56 +0100 Subject: [PATCH 2/4] fix: lint --- contracts/icp/context-config/tests/integration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/icp/context-config/tests/integration.rs b/contracts/icp/context-config/tests/integration.rs index 00fb0d91c..d85fb79bb 100644 --- a/contracts/icp/context-config/tests/integration.rs +++ b/contracts/icp/context-config/tests/integration.rs @@ -1,11 +1,11 @@ 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, ICContextId, ICContextIdentity, ICPSigned, ICSignerId, Request, RequestKind, }; -use calimero_context_config::repr::ReprBytes; use ed25519_dalek::{Signer, SigningKey}; use pocket_ic::{PocketIc, WasmResult}; use rand::Rng; From ba788ca5eac57da7161fd974349d3da880eac1b9 Mon Sep 17 00:00:00 2001 From: alenmestrov Date: Mon, 2 Dec 2024 12:51:47 +0100 Subject: [PATCH 3/4] fix: resolved building of contract for CI --- contracts/icp/context-config/build.sh | 26 ++++++++----------- contracts/icp/context-config/deploy_devnet.sh | 16 ++++++++++++ .../icp/context-config/tests/integration.rs | 2 +- scripts/test.sh | 1 + 4 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 contracts/icp/context-config/deploy_devnet.sh 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/tests/integration.rs b/contracts/icp/context-config/tests/integration.rs index d85fb79bb..d90740236 100644 --- a/contracts/icp/context-config/tests/integration.rs +++ b/contracts/icp/context-config/tests/integration.rs @@ -12,7 +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") + 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); 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 From f1213c011646df76b07eab8aac94f250f0ff1495 Mon Sep 17 00:00:00 2001 From: alenmestrov Date: Mon, 2 Dec 2024 12:52:03 +0100 Subject: [PATCH 4/4] fix: lint --- contracts/icp/context-config/tests/integration.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/contracts/icp/context-config/tests/integration.rs b/contracts/icp/context-config/tests/integration.rs index d90740236..07090e510 100644 --- a/contracts/icp/context-config/tests/integration.rs +++ b/contracts/icp/context-config/tests/integration.rs @@ -12,8 +12,7 @@ use rand::Rng; fn setup() -> (PocketIc, Principal) { let pic = PocketIc::new(); - let wasm = std::fs::read("res/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(