From 3cd2b68cfbfa152bf5d3fc7bd04e21513f9585df Mon Sep 17 00:00:00 2001 From: gcranju Date: Tue, 10 Dec 2024 13:38:18 +0545 Subject: [PATCH] fix: removed xcall lib from connection --- .../cw-cluster-connection/Cargo.toml | 1 - .../cw-cluster-connection/src/contract.rs | 2 +- .../cw-cluster-connection/src/helper.rs | 14 +++++++++++--- .../cw-cluster-connection/tests/test.rs | 18 +++++++++--------- .../cosmwasm-vm/cw-xcall/src/types/request.rs | 2 +- 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/contracts/cosmwasm-vm/cw-cluster-connection/Cargo.toml b/contracts/cosmwasm-vm/cw-cluster-connection/Cargo.toml index f118f924..471972fc 100644 --- a/contracts/cosmwasm-vm/cw-cluster-connection/Cargo.toml +++ b/contracts/cosmwasm-vm/cw-cluster-connection/Cargo.toml @@ -36,7 +36,6 @@ serde = { workspace=true} thiserror = { workspace=true} common ={ workspace=true} cw-xcall-lib = { path="../cw-xcall-lib" } -cw-xcall = { path="../cw-xcall" } hex = "0.4.3" serde-json-wasm = {workspace=true} sha2 = { version = "0.10.6", default-features = false } diff --git a/contracts/cosmwasm-vm/cw-cluster-connection/src/contract.rs b/contracts/cosmwasm-vm/cw-cluster-connection/src/contract.rs index 89b18f08..ad98d34f 100644 --- a/contracts/cosmwasm-vm/cw-cluster-connection/src/contract.rs +++ b/contracts/cosmwasm-vm/cw-cluster-connection/src/contract.rs @@ -167,7 +167,7 @@ impl<'a> ClusterConnection<'a> { let signed_msg = SignableMsg { src_network: src_network.to_string(), - conn_sn: conn_sn, + conn_sn, data: msg_vec.clone(), dst_network: dst_network.to_string(), }; diff --git a/contracts/cosmwasm-vm/cw-cluster-connection/src/helper.rs b/contracts/cosmwasm-vm/cw-cluster-connection/src/helper.rs index a7d7b15d..79e777b9 100644 --- a/contracts/cosmwasm-vm/cw-cluster-connection/src/helper.rs +++ b/contracts/cosmwasm-vm/cw-cluster-connection/src/helper.rs @@ -1,5 +1,6 @@ use std::{collections::HashMap, str::FromStr}; +use cosmwasm_schema::QueryResponses; use cosmwasm_std::{ensure_eq, Addr, BalanceResponse, BankQuery, Coin, QueryRequest}; use cw_xcall_lib::network_address::{NetId, NetworkAddress}; use sha2::Digest; @@ -7,11 +8,18 @@ use sha3::Keccak256; use super::*; +#[cw_serde] +#[derive(QueryResponses)] +pub enum XcallQueryMsg { + #[returns(String)] + GetNetworkAddress {}, +} + pub fn keccak256(input: &[u8]) -> Keccak256 { use sha3::{Digest, Keccak256}; let mut hasher = Keccak256::new(); hasher.update(input); - return hasher; + hasher } pub fn to_truncated_le_bytes(n: u128) -> Vec { @@ -81,7 +89,7 @@ impl<'a> ClusterConnection<'a> { pub fn get_network_id(&self, deps: Deps) -> Result { let xcall_host = self.get_xcall(deps.storage)?; - let query_msg = cw_xcall::msg::QueryMsg::GetNetworkAddress {}; + let query_msg = XcallQueryMsg::GetNetworkAddress {}; let query_request = QueryRequest::Wasm(cosmwasm_std::WasmQuery::Smart { contract_addr: xcall_host.to_string(), @@ -139,7 +147,7 @@ impl<'a> ClusterConnection<'a> { } let mut recovery_code = signature[64]; if recovery_code >= 27 { - recovery_code = recovery_code - 27; + recovery_code -= 27; } match deps .api diff --git a/contracts/cosmwasm-vm/cw-cluster-connection/tests/test.rs b/contracts/cosmwasm-vm/cw-cluster-connection/tests/test.rs index 43980876..c18f9fde 100644 --- a/contracts/cosmwasm-vm/cw-cluster-connection/tests/test.rs +++ b/contracts/cosmwasm-vm/cw-cluster-connection/tests/test.rs @@ -126,8 +126,8 @@ pub fn test_set_validators() { let threshold = 2; let msg = ExecuteMsg::SetValidators { - validators: validators, - threshold: threshold, + validators, + threshold, }; let info = mock_info(ADMIN, &[]); @@ -135,7 +135,7 @@ pub fn test_set_validators() { assert!(res.is_ok()); let mut stored_validators = ctx.get_validators(deps.as_ref().storage).unwrap(); - let mut set_validators = vec![val1.to_string(), val2.to_string(), val3.to_string()]; + let mut set_validators = [val1.to_string(), val2.to_string(), val3.to_string()]; assert_eq!(stored_validators.sort(), set_validators.sort()); @@ -160,7 +160,7 @@ pub fn test_set_validators_unauthorized() { let msg = ExecuteMsg::SetValidators { validators: validators.clone(), - threshold: threshold, + threshold, }; let info = mock_info("UnauthorisedUser", &[]); @@ -208,7 +208,7 @@ pub fn test_set_validators_empty() { let mut stored_validators = ctx.get_validators(deps.as_ref().storage).unwrap(); let stored_threshold = ctx.get_signature_threshold(deps.as_ref().storage); - let mut set_validators = vec![val1.to_string(), val2.to_string(), val3.to_string()]; + let mut set_validators = [val1.to_string(), val2.to_string(), val3.to_string()]; assert_eq!(set_validators.sort(), stored_validators.sort()); assert_eq!(stored_threshold, 2); @@ -416,7 +416,7 @@ pub fn test_recv_message() { let signed_msg = SignableMsg { src_network: src_network.to_string(), - conn_sn: conn_sn, + conn_sn, data: hex::decode(msg.clone()).unwrap(), dst_network: dst_network.to_string(), }; @@ -461,7 +461,7 @@ pub fn test_recv_message() { let msg_with_signatures = ExecuteMsg::RecvMessage { src_network: src_network.clone(), conn_sn, - msg: msg, + msg, signatures: signatures.clone(), }; let res = execute( @@ -509,7 +509,7 @@ pub fn test_recv_message_signatures_insufficient() { let signed_msg = SignableMsg { src_network: src_network.to_string(), - conn_sn: conn_sn, + conn_sn, data: hex::decode(msg.clone()).unwrap(), dst_network: dst_network.to_string(), }; @@ -546,7 +546,7 @@ pub fn test_recv_message_signatures_insufficient() { let msg_with_signatures = ExecuteMsg::RecvMessage { src_network: src_network.clone(), conn_sn, - msg: msg, + msg, signatures: signatures.clone(), }; diff --git a/contracts/cosmwasm-vm/cw-xcall/src/types/request.rs b/contracts/cosmwasm-vm/cw-xcall/src/types/request.rs index 69997059..b6ceef96 100644 --- a/contracts/cosmwasm-vm/cw-xcall/src/types/request.rs +++ b/contracts/cosmwasm-vm/cw-xcall/src/types/request.rs @@ -168,7 +168,7 @@ mod tests { */ - use std::{io::Read, str::FromStr}; + use std::str::FromStr; use common::rlp::{self, RlpStream}; use cosmwasm_std::Addr;