From 0516251be83951e5c94db26d9ac79d058b414cf1 Mon Sep 17 00:00:00 2001 From: ibrizsabin Date: Wed, 20 Dec 2023 12:17:37 +0545 Subject: [PATCH 1/3] fix: add mock query --- contracts/cosmwasm-vm/cw-mock-ibc-core/src/contract.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/contracts/cosmwasm-vm/cw-mock-ibc-core/src/contract.rs b/contracts/cosmwasm-vm/cw-mock-ibc-core/src/contract.rs index 3fa2919a5..0cf7f9a07 100644 --- a/contracts/cosmwasm-vm/cw-mock-ibc-core/src/contract.rs +++ b/contracts/cosmwasm-vm/cw-mock-ibc-core/src/contract.rs @@ -167,6 +167,9 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { let state = STATE.load(deps.storage).unwrap(); Ok(to_binary(&state.sequence).unwrap()) + }, + QueryMsg::GetLatestHeight { client_id }=>{ + Ok(to_binary(&100000_u64).unwrap()) } _ => Err(cosmwasm_std::StdError::NotFound { kind: "Query Not Found".to_string(), From 3ab51610d017cb338ac55b55a8b01332133b5b62 Mon Sep 17 00:00:00 2001 From: ibrizsabin Date: Thu, 21 Dec 2023 11:34:04 +0545 Subject: [PATCH 2/3] fix: add writeacknowledgement --- .../cosmwasm-vm/cw-common/src/xcall_connection_msg.rs | 2 ++ .../cosmwasm-vm/cw-mock-ibc-core/src/contract.rs | 11 ++++++++++- contracts/cosmwasm-vm/cw-mock-ibc-core/src/msg.rs | 6 +++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/contracts/cosmwasm-vm/cw-common/src/xcall_connection_msg.rs b/contracts/cosmwasm-vm/cw-common/src/xcall_connection_msg.rs index d55496d72..3e66be3cf 100644 --- a/contracts/cosmwasm-vm/cw-common/src/xcall_connection_msg.rs +++ b/contracts/cosmwasm-vm/cw-common/src/xcall_connection_msg.rs @@ -91,3 +91,5 @@ pub enum QueryMsg { #[returns(ConfigResponse)] GetIbcConfig { nid: NetId }, } + + diff --git a/contracts/cosmwasm-vm/cw-mock-ibc-core/src/contract.rs b/contracts/cosmwasm-vm/cw-mock-ibc-core/src/contract.rs index 0cf7f9a07..b8cb9f227 100644 --- a/contracts/cosmwasm-vm/cw-mock-ibc-core/src/contract.rs +++ b/contracts/cosmwasm-vm/cw-mock-ibc-core/src/contract.rs @@ -4,9 +4,10 @@ use cosmwasm_std::entry_point; use cosmwasm_std::{ to_binary, Addr, Binary, CosmosMsg, Deps, DepsMut, Empty, Env, IbcEndpoint, IbcPacket, IbcPacketReceiveMsg, IbcTimeout, IbcTimeoutBlock, MessageInfo, Reply, Response, StdResult, - SubMsg, Timestamp, WasmMsg, + SubMsg, Timestamp, WasmMsg, Event, }; use cw2::set_contract_version; +use cw_common::hex_string::HexString; use cw_common::ibc_types::IbcHeight; use cw_common::raw_types::channel::RawPacket; use cw_common::ProstMessage; @@ -153,10 +154,18 @@ pub fn execute( .add_submessage(sub_message.clone()) .add_attribute("method", "ibc_config") .add_attribute("data", to_binary(&sub_message).unwrap().to_base64())) + }, + ExecuteMsg::WriteAcknowledgement { packet, acknowledgement }=>{ + + Ok(Response::new().add_event(event_ack(acknowledgement))) } } } +pub fn event_ack(ack:HexString)->Event{ + return Event::new("write_acknowledgement").add_attribute("data", hex::encode(ack.to_bytes().unwrap())); +} + #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { diff --git a/contracts/cosmwasm-vm/cw-mock-ibc-core/src/msg.rs b/contracts/cosmwasm-vm/cw-mock-ibc-core/src/msg.rs index 9eb8d789e..f05119012 100644 --- a/contracts/cosmwasm-vm/cw-mock-ibc-core/src/msg.rs +++ b/contracts/cosmwasm-vm/cw-mock-ibc-core/src/msg.rs @@ -1,5 +1,5 @@ use cosmwasm_schema::cw_serde; -use cosmwasm_std::Addr; +use cosmwasm_std::{Addr, IbcPacket}; use cw_common::cw_types::CwChannelConnectMsg; use cw_common::hex_string::HexString; @@ -12,4 +12,8 @@ pub enum ExecuteMsg { ReceivePacket { message: String }, RegisterXcall { address: Addr }, IbcConfig { msg: CwChannelConnectMsg }, + WriteAcknowledgement { + packet: IbcPacket, + acknowledgement: HexString, + }, } From 72393a844637becf291732d59d334e6f3ea40287 Mon Sep 17 00:00:00 2001 From: ibrizsabin Date: Tue, 26 Dec 2023 10:48:28 +0545 Subject: [PATCH 3/3] chore: pass build --- .../cw-common/src/xcall_connection_msg.rs | 2 -- .../src/send_message.rs | 4 ++-- .../cw-mock-ibc-core/src/contract.rs | 20 +++++++++---------- .../cosmwasm-vm/cw-mock-ibc-core/src/msg.rs | 16 +++++++++++---- .../cw-xcall-ibc-connection/src/contract.rs | 2 +- .../tests/test_owner.rs | 1 - 6 files changed, 24 insertions(+), 21 deletions(-) diff --git a/contracts/cosmwasm-vm/cw-common/src/xcall_connection_msg.rs b/contracts/cosmwasm-vm/cw-common/src/xcall_connection_msg.rs index 3e66be3cf..d55496d72 100644 --- a/contracts/cosmwasm-vm/cw-common/src/xcall_connection_msg.rs +++ b/contracts/cosmwasm-vm/cw-common/src/xcall_connection_msg.rs @@ -91,5 +91,3 @@ pub enum QueryMsg { #[returns(ConfigResponse)] GetIbcConfig { nid: NetId }, } - - diff --git a/contracts/cosmwasm-vm/cw-mock-ibc-connection/src/send_message.rs b/contracts/cosmwasm-vm/cw-mock-ibc-connection/src/send_message.rs index d7d3bffe7..84fff8bac 100644 --- a/contracts/cosmwasm-vm/cw-mock-ibc-connection/src/send_message.rs +++ b/contracts/cosmwasm-vm/cw-mock-ibc-connection/src/send_message.rs @@ -16,11 +16,11 @@ impl<'a> CwIbcConnection<'a> { self.ensure_xcall_handler(deps.as_ref().storage, info.sender.clone())?; println!("{LOG_PREFIX} Packet Validated"); - let network_fee = self.get_network_fees(deps.as_ref().storage, nid.clone()); + let network_fee = self.get_network_fees(deps.as_ref().storage, nid); let mut total_fee = network_fee.send_packet_fee; if sn > 0 { - total_fee = total_fee + network_fee.ack_fee; + total_fee += network_fee.ack_fee; } let config = self.get_config(deps.storage)?; diff --git a/contracts/cosmwasm-vm/cw-mock-ibc-core/src/contract.rs b/contracts/cosmwasm-vm/cw-mock-ibc-core/src/contract.rs index b8cb9f227..fb43cc5fd 100644 --- a/contracts/cosmwasm-vm/cw-mock-ibc-core/src/contract.rs +++ b/contracts/cosmwasm-vm/cw-mock-ibc-core/src/contract.rs @@ -2,9 +2,9 @@ use common::ibc::core::ics04_channel::timeout::TimeoutHeight; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - to_binary, Addr, Binary, CosmosMsg, Deps, DepsMut, Empty, Env, IbcEndpoint, IbcPacket, + to_binary, Addr, Binary, CosmosMsg, Deps, DepsMut, Empty, Env, Event, IbcEndpoint, IbcPacket, IbcPacketReceiveMsg, IbcTimeout, IbcTimeoutBlock, MessageInfo, Reply, Response, StdResult, - SubMsg, Timestamp, WasmMsg, Event, + SubMsg, Timestamp, WasmMsg, }; use cw2::set_contract_version; use cw_common::hex_string::HexString; @@ -154,16 +154,16 @@ pub fn execute( .add_submessage(sub_message.clone()) .add_attribute("method", "ibc_config") .add_attribute("data", to_binary(&sub_message).unwrap().to_base64())) - }, - ExecuteMsg::WriteAcknowledgement { packet, acknowledgement }=>{ - - Ok(Response::new().add_event(event_ack(acknowledgement))) } + ExecuteMsg::WriteAcknowledgement { + packet: _, + acknowledgement, + } => Ok(Response::new().add_event(event_ack(acknowledgement))), } } -pub fn event_ack(ack:HexString)->Event{ - return Event::new("write_acknowledgement").add_attribute("data", hex::encode(ack.to_bytes().unwrap())); +pub fn event_ack(ack: HexString) -> Event { + Event::new("write_acknowledgement").add_attribute("data", hex::encode(ack.to_bytes().unwrap())) } #[cfg_attr(not(feature = "library"), entry_point)] @@ -176,10 +176,8 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { let state = STATE.load(deps.storage).unwrap(); Ok(to_binary(&state.sequence).unwrap()) - }, - QueryMsg::GetLatestHeight { client_id }=>{ - Ok(to_binary(&100000_u64).unwrap()) } + QueryMsg::GetLatestHeight { client_id: _ } => Ok(to_binary(&100000_u64).unwrap()), _ => Err(cosmwasm_std::StdError::NotFound { kind: "Query Not Found".to_string(), }), diff --git a/contracts/cosmwasm-vm/cw-mock-ibc-core/src/msg.rs b/contracts/cosmwasm-vm/cw-mock-ibc-core/src/msg.rs index f05119012..081b70d59 100644 --- a/contracts/cosmwasm-vm/cw-mock-ibc-core/src/msg.rs +++ b/contracts/cosmwasm-vm/cw-mock-ibc-core/src/msg.rs @@ -8,10 +8,18 @@ pub struct InstantiateMsg {} #[cw_serde] pub enum ExecuteMsg { - SendPacket { packet: HexString }, - ReceivePacket { message: String }, - RegisterXcall { address: Addr }, - IbcConfig { msg: CwChannelConnectMsg }, + SendPacket { + packet: HexString, + }, + ReceivePacket { + message: String, + }, + RegisterXcall { + address: Addr, + }, + IbcConfig { + msg: CwChannelConnectMsg, + }, WriteAcknowledgement { packet: IbcPacket, acknowledgement: HexString, diff --git a/contracts/cosmwasm-vm/cw-xcall-ibc-connection/src/contract.rs b/contracts/cosmwasm-vm/cw-xcall-ibc-connection/src/contract.rs index 5c20301c4..630f449cb 100644 --- a/contracts/cosmwasm-vm/cw-xcall-ibc-connection/src/contract.rs +++ b/contracts/cosmwasm-vm/cw-xcall-ibc-connection/src/contract.rs @@ -302,7 +302,7 @@ impl<'a> CwIbcConnection<'a> { info: MessageInfo, msg: InstantiateMsg, ) -> Result { - let owner = info.clone().sender; + let owner = info.sender; self.add_owner(store, owner.clone())?; self.update_admin(store, owner)?; diff --git a/contracts/cosmwasm-vm/cw-xcall-ibc-connection/tests/test_owner.rs b/contracts/cosmwasm-vm/cw-xcall-ibc-connection/tests/test_owner.rs index eb8f1b8de..2d4bb0257 100644 --- a/contracts/cosmwasm-vm/cw-xcall-ibc-connection/tests/test_owner.rs +++ b/contracts/cosmwasm-vm/cw-xcall-ibc-connection/tests/test_owner.rs @@ -2,7 +2,6 @@ mod account; mod setup; use account::*; -use cosmwasm_std::Addr; use cw_xcall_ibc_connection::state::CwIbcConnection; use setup::*; #[test]