From f94e6b2db138a501f0ce31b8e52a9694ea40afa2 Mon Sep 17 00:00:00 2001 From: AntonAndell Date: Wed, 8 Nov 2023 11:49:15 +0100 Subject: [PATCH] fix: Prevent networkId to be from native chain when receiving call messsages. (#166) --- .../cw-xcall/src/handle_call_message.rs | 2 +- .../cosmwasm-vm/cw-xcall/tests/test_request.rs | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/contracts/cosmwasm-vm/cw-xcall/src/handle_call_message.rs b/contracts/cosmwasm-vm/cw-xcall/src/handle_call_message.rs index 6d5b4603..ade3e6f3 100644 --- a/contracts/cosmwasm-vm/cw-xcall/src/handle_call_message.rs +++ b/contracts/cosmwasm-vm/cw-xcall/src/handle_call_message.rs @@ -11,12 +11,12 @@ impl<'a> CwCallService<'a> { from_nid: NetId, message: Vec, ) -> Result { - let call_service_message: CSMessage = CSMessage::try_from(message)?; let cfg = self.get_config(deps.storage).unwrap(); if cfg.network_id == from_nid.to_string() { return Err(ContractError::ProtocolsMismatch); } + let call_service_message: CSMessage = CSMessage::try_from(message)?; match call_service_message.message_type() { CallServiceMessageType::CallServiceRequest => { self.handle_request(deps, info, from_nid, call_service_message.payload()) diff --git a/contracts/cosmwasm-vm/cw-xcall/tests/test_request.rs b/contracts/cosmwasm-vm/cw-xcall/tests/test_request.rs index d0c237de..e135697f 100644 --- a/contracts/cosmwasm-vm/cw-xcall/tests/test_request.rs +++ b/contracts/cosmwasm-vm/cw-xcall/tests/test_request.rs @@ -4,7 +4,7 @@ mod setup; use std::str::FromStr; use cosmwasm_std::testing::mock_env; -use cw_xcall::state::CwCallService; +use cw_xcall::{error::ContractError, state::CwCallService}; use cw_xcall_lib::network_address::NetId; use setup::test::*; @@ -159,7 +159,6 @@ fn set_request_id_without_proper_initialisation() { .unwrap(); } - #[test] fn invalid_network_id() { let mut mock_deps = deps(); @@ -181,10 +180,17 @@ fn invalid_network_id() { ) .unwrap(); - - let response = contract - .handle_message(mock_deps.as_mut(), mock_info, NetId::from_str("nid").unwrap(), vec![]); + let response = contract.handle_message( + mock_deps.as_mut(), + mock_info, + NetId::from_str("nid").unwrap(), + vec![], + ); assert!(response.is_err()); + let error = response.err().unwrap(); + assert_eq!( + error.to_string(), + ContractError::ProtocolsMismatch.to_string() + ); } -