Skip to content

Commit

Permalink
fix: removed xcall lib from connection
Browse files Browse the repository at this point in the history
  • Loading branch information
gcranju committed Dec 10, 2024
1 parent e0c8c69 commit 3cd2b68
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
1 change: 0 additions & 1 deletion contracts/cosmwasm-vm/cw-cluster-connection/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
Expand Down
14 changes: 11 additions & 3 deletions contracts/cosmwasm-vm/cw-cluster-connection/src/helper.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
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;
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<u8> {
Expand Down Expand Up @@ -81,7 +89,7 @@ impl<'a> ClusterConnection<'a> {
pub fn get_network_id(&self, deps: Deps) -> Result<String, ContractError> {
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(),
Expand Down Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions contracts/cosmwasm-vm/cw-cluster-connection/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,16 @@ pub fn test_set_validators() {
let threshold = 2;

let msg = ExecuteMsg::SetValidators {
validators: validators,
threshold: threshold,
validators,
threshold,
};

let info = mock_info(ADMIN, &[]);
let res = execute(deps.as_mut(), env.clone(), info, msg.clone());
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());

Expand All @@ -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", &[]);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(),
};
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(),
};
Expand Down Expand Up @@ -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(),
};

Expand Down
2 changes: 1 addition & 1 deletion contracts/cosmwasm-vm/cw-xcall/src/types/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3cd2b68

Please sign in to comment.