Skip to content

Commit

Permalink
fix: Prevent networkId to be from native chain when receiving call me…
Browse files Browse the repository at this point in the history
…sssages. (#166)
  • Loading branch information
AntonAndell authored Nov 8, 2023
1 parent 99a582c commit f94e6b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion contracts/cosmwasm-vm/cw-xcall/src/handle_call_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ impl<'a> CwCallService<'a> {
from_nid: NetId,
message: Vec<u8>,
) -> Result<Response, ContractError> {
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);
}

Check warning on line 17 in contracts/cosmwasm-vm/cw-xcall/src/handle_call_message.rs

View check run for this annotation

Codecov / codecov/patch

contracts/cosmwasm-vm/cw-xcall/src/handle_call_message.rs#L17

Added line #L17 was not covered by tests

let call_service_message: CSMessage = CSMessage::try_from(message)?;

Check warning on line 19 in contracts/cosmwasm-vm/cw-xcall/src/handle_call_message.rs

View check run for this annotation

Codecov / codecov/patch

contracts/cosmwasm-vm/cw-xcall/src/handle_call_message.rs#L19

Added line #L19 was not covered by tests
match call_service_message.message_type() {
CallServiceMessageType::CallServiceRequest => {
self.handle_request(deps, info, from_nid, call_service_message.payload())
Expand Down
18 changes: 12 additions & 6 deletions contracts/cosmwasm-vm/cw-xcall/tests/test_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down Expand Up @@ -159,7 +159,6 @@ fn set_request_id_without_proper_initialisation() {
.unwrap();
}


#[test]
fn invalid_network_id() {
let mut mock_deps = deps();
Expand All @@ -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()
);
}

0 comments on commit f94e6b2

Please sign in to comment.