From e6cd59f026d524439a225bd4a84f5c5537e1dc90 Mon Sep 17 00:00:00 2001 From: Matej Vukosav Date: Thu, 21 Nov 2024 16:49:01 +0800 Subject: [PATCH 1/2] refactor: remove blockchain app example (#973) Merge with known context contract tests failing --- Cargo.lock | 8 --- Cargo.toml | 1 - apps/blockchain/Cargo.toml | 21 ------ apps/blockchain/build.sh | 18 ----- apps/blockchain/src/lib.rs | 132 ------------------------------------- 5 files changed, 180 deletions(-) delete mode 100644 apps/blockchain/Cargo.toml delete mode 100755 apps/blockchain/build.sh delete mode 100644 apps/blockchain/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index ec75344fb..ab7c0be65 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -682,14 +682,6 @@ dependencies = [ "generic-array 0.14.7", ] -[[package]] -name = "blockchain" -version = "0.1.0" -dependencies = [ - "calimero-sdk", - "calimero-storage", -] - [[package]] name = "blst" version = "0.3.13" diff --git a/Cargo.toml b/Cargo.toml index da0961a94..b99c36678 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,6 @@ members = [ "./apps/only-peers", "./apps/gen-ext", "./apps/visited", - "./apps/blockchain", "./contracts/context-config", "./contracts/registry", diff --git a/apps/blockchain/Cargo.toml b/apps/blockchain/Cargo.toml deleted file mode 100644 index 6022f2ae4..000000000 --- a/apps/blockchain/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "blockchain" -description = "Calimero increment/decrement application" -version = "0.1.0" -edition = "2021" - -[lib] -crate-type = ["cdylib"] - -[dependencies] -calimero-sdk = { path = "../../crates/sdk" } -calimero-storage = { path = "../../crates/storage" } - -[profile.app-release] -inherits = "release" -codegen-units = 1 -opt-level = "z" -lto = true -debug = false -panic = "abort" -overflow-checks = true diff --git a/apps/blockchain/build.sh b/apps/blockchain/build.sh deleted file mode 100755 index 0db2ceab3..000000000 --- a/apps/blockchain/build.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -set -e - -cd "$(dirname $0)" - -TARGET="${CARGO_TARGET_DIR:-../../target}" - -rustup target add wasm32-unknown-unknown - -cargo build --target wasm32-unknown-unknown --profile app-release - -mkdir -p res - -cp "$TARGET/wasm32-unknown-unknown/app-release/blockchain.wasm" ./res/ - -if command -v wasm-opt >/dev/null; then - wasm-opt -Oz ./res/blockchain.wasm -o ./res/blockchain.wasm -fi diff --git a/apps/blockchain/src/lib.rs b/apps/blockchain/src/lib.rs deleted file mode 100644 index fd9bf612d..000000000 --- a/apps/blockchain/src/lib.rs +++ /dev/null @@ -1,132 +0,0 @@ -use calimero_sdk::app; -use calimero_sdk::borsh::{BorshDeserialize, BorshSerialize}; -use calimero_sdk::env::ext::ProposalId; -use calimero_sdk::env::{self}; -use calimero_sdk::serde::{Deserialize, Serialize}; -use calimero_sdk::types::Error; -use calimero_storage::collections::UnorderedMap; -use calimero_storage::entities::Element; -use calimero_storage::AtomicUnit; - -#[derive(Clone, Debug, PartialEq, PartialOrd, Deserialize)] -#[serde(crate = "calimero_sdk::serde")] -pub struct CreateProposalRequest {} - -#[derive(Clone, Debug, PartialEq, PartialOrd, Deserialize)] -#[serde(crate = "calimero_sdk::serde", rename_all = "camelCase")] -pub struct GetProposalMessagesRequest { - proposal_id: String, -} - -#[derive(Clone, Debug, PartialEq, PartialOrd, Deserialize)] -#[serde(crate = "calimero_sdk::serde", rename_all = "camelCase")] -pub struct SendProposalMessageRequest { - proposal_id: String, - message: Message, -} - -#[app::event] -pub enum Event { - ProposalCreated(), -} - -#[app::state(emits = Event)] -#[derive(AtomicUnit, Clone, Debug, PartialEq, PartialOrd)] -#[root] -#[type_id(1)] -pub struct AppState { - count: u32, - #[storage] - storage: Element, - - messages: UnorderedMap>, -} - -#[derive( - Clone, Debug, PartialEq, PartialOrd, BorshSerialize, BorshDeserialize, Serialize, Deserialize, -)] -#[borsh(crate = "calimero_sdk::borsh")] -#[serde(crate = "calimero_sdk::serde")] -pub struct Message { - id: String, - proposal_id: String, - author: String, - text: String, - created_at: String, -} - -#[app::logic] -impl AppState { - #[app::init] - pub fn init() -> AppState { - AppState { - count: 0, - storage: Element::root(), - messages: UnorderedMap::new().unwrap(), - } - } - - pub fn create_new_proposal(receiver: String) -> Result { - env::log("env Call in wasm create new proposal"); - - println!("Call in wasm create new proposal {:?}", receiver); - let account_id = env::ext::AccountId("vuki.testnet".to_string()); - let amount = 1_000_000_000_000_000_000_000; - let proposal_id = Self::external() - .propose() - .transfer(account_id, amount) - .send(); - let log_message = format!("Proposal ID: {:?}", proposal_id); - env::log(&log_message); - println!("Create new proposal with id: {:?}", proposal_id); - - Ok(proposal_id) - } - - pub fn approve_proposal(proposal_id: ProposalId) -> Result { - println!("Approve proposal: {:?}", proposal_id); - let _ = Self::external().approve(proposal_id); - Ok(true) - } - - // Messages (discussion) - pub fn get_proposal_messages( - &self, - // request: GetProposalMessagesRequest, I cannot to this?? - proposal_id: ProposalId, - ) -> Result, Error> { - env::log(&format!("env Get messages for proposal: {:?}", proposal_id)); - let res = &self.messages.get(&proposal_id).unwrap(); - env::log(&format!( - "Get messages for proposal from storage: {:?}", - res - )); - match res { - Some(messages) => Ok(messages.clone()), - None => Ok(vec![]), - } - } - - pub fn send_proposal_messages( - &mut self, - // request: SendProposalMessageRequest, I cannot to this?? How to use camelCase? - proposal_id: ProposalId, - message: Message, - ) -> Result { - env::log(&format!("env send_proposal_messages: {:?}", proposal_id)); - env::log(&format!("env send_proposal_messages: {:?}", message)); - - let proposal_messages = self.messages.get(&proposal_id).unwrap(); - match proposal_messages { - Some(mut messages) => { - messages.push(message); - self.messages.insert(proposal_id, messages)?; - } - None => { - let messages = vec![message]; - self.messages.insert(proposal_id, messages)?; - } - } - Ok(true) - } -} From 8b26910ebb39d24c22e694ebed8847ba5c7923f3 Mon Sep 17 00:00:00 2001 From: Miraculous Owonubi Date: Fri, 22 Nov 2024 16:20:40 +0300 Subject: [PATCH 2/2] fix(CI): advance after transactions are fully finalized (#982) --- contracts/context-config/tests/sandbox.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/contracts/context-config/tests/sandbox.rs b/contracts/context-config/tests/sandbox.rs index 612f10890..8282be74e 100644 --- a/contracts/context-config/tests/sandbox.rs +++ b/contracts/context-config/tests/sandbox.rs @@ -1124,7 +1124,6 @@ async fn test_storage_usage_matches_code_size() -> eyre::Result<()> { let node1_balance = worker.view_account(&node1.id()).await?.balance; - // Deploy proxy contract let res = node1 .call(contract.id(), "mutate") .args_json(Signed::new( @@ -1155,11 +1154,15 @@ async fn test_storage_usage_matches_code_size() -> eyre::Result<()> { let expected_log = format!("Context `{}` added", context_id); assert!(res.logs().iter().any(|log| log == &expected_log)); + worker.fast_forward(1).await?; + let node1_balance_after = worker.view_account(&node1.id()).await?.balance; let diff = node1_balance.saturating_sub(node1_balance_after); let node1_balance = node1_balance_after; + println!("Node1 balance diff: {}", diff); + assert!( diff < NearToken::from_millinear(10), "Node1 balance should not be reduced by more than 10 milliNEAR, but was reduced by {}", @@ -1185,6 +1188,7 @@ async fn test_storage_usage_matches_code_size() -> eyre::Result<()> { println!("Initial storage usage: {}", initial_storage); println!("Initial WASM size: {}", initial_code_size); println!("Initial Balance: {}", initial_balance); + println!("Initial Node1 Balance: {}", node1_balance); let res = contract .call("set_proxy_code") @@ -1216,11 +1220,15 @@ async fn test_storage_usage_matches_code_size() -> eyre::Result<()> { assert!(res.failures().is_empty(), "{:#?}", res.failures()); + worker.fast_forward(1).await?; + let node1_balance_after = worker.view_account(&node1.id()).await?.balance; let diff = node1_balance.saturating_sub(node1_balance_after); let node1_balance = node1_balance_after; + println!("Node1 balance diff: {}", diff); + assert!( diff < NearToken::from_millinear(10), "Node1 balance should not be reduced by more than 10 milliNEAR, but was reduced by {}", @@ -1236,6 +1244,7 @@ async fn test_storage_usage_matches_code_size() -> eyre::Result<()> { println!("Intermediate storage usage: {}", intermediate_storage); println!("Intermediate WASM size: {}", intermediate_code_size); println!("Intermediate Balance: {}", intermediate_balance); + println!("Intermediate Node1 Balance: {}", node1_balance); // Calculate raw differences (can be negative) let storage_change = intermediate_storage as i64 - initial_storage as i64; @@ -1291,10 +1300,14 @@ async fn test_storage_usage_matches_code_size() -> eyre::Result<()> { assert!(res.failures().is_empty(), "{:#?}", res.failures()); + worker.fast_forward(1).await?; + let node1_balance_after = worker.view_account(&node1.id()).await?.balance; let diff = node1_balance.saturating_sub(node1_balance_after); + println!("Node1 balance diff: {}", diff); + assert!( diff < NearToken::from_millinear(10), "Node1 balance should not be reduced by more than 10 milliNEAR, but was reduced by {}", @@ -1310,6 +1323,7 @@ async fn test_storage_usage_matches_code_size() -> eyre::Result<()> { println!("Final storage usage: {}", final_storage); println!("Final WASM size: {}", final_code_size); println!("Final Balance: {}", final_balance); + println!("Final Node1 Balance: {}", node1_balance); // Calculate raw differences (can be negative) let storage_change = final_storage as i64 - intermediate_storage as i64;