Skip to content

Commit

Permalink
chore: update test coverage for ibc client (#846)
Browse files Browse the repository at this point in the history
  • Loading branch information
bishalbikram authored Mar 15, 2024
1 parent 9497615 commit 9a7876b
Show file tree
Hide file tree
Showing 2 changed files with 349 additions and 669 deletions.
75 changes: 73 additions & 2 deletions contracts/cosmwasm-vm/cw-ibc-core/tests/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ use cosmwasm_std::{
mock_dependencies, mock_env, mock_info, MockApi, MockQuerier, MockStorage,
MOCK_CONTRACT_ADDR,
},
to_binary, Addr, Binary, BlockInfo, ContractInfo, ContractResult, Empty, Env, IbcEndpoint,
MessageInfo, OwnedDeps, SystemResult, Timestamp, TransactionInfo, WasmQuery,
to_binary, Addr, Binary, BlockInfo, ContractInfo, ContractResult, DepsMut, Empty, Env,
IbcEndpoint, MessageInfo, OwnedDeps, SystemResult, Timestamp, TransactionInfo, WasmQuery,
};

use common::{
Expand Down Expand Up @@ -580,6 +580,7 @@ use cw_common::ibc_types::IbcClientId;
use cw_ibc_core::context::CwIbcCoreContext;
use cw_ibc_core::ics04_channel::Counterparty;
use cw_ibc_core::ics04_channel::State;
use cw_ibc_core::traits::IbcClient;
use cw_ibc_core::ConnectionEnd;
use cw_ibc_core::{compute_packet_commitment, ChannelEnd, Sequence};
use prost::Message;
Expand Down Expand Up @@ -631,6 +632,7 @@ pub struct TestContext {
pub module_address: Option<Addr>,
pub packet: Option<RawPacket>,
pub client_id: IbcClientId,
pub client_type: ClientType,
pub connection_id: ConnectionId,
pub env: Env,
pub height: Height,
Expand All @@ -653,6 +655,7 @@ impl TestContext {
port_id: PortId::default(),
channel_id: ChannelId::default(),
lightclient: Some(LightClient::new("lightclient".to_string())),
client_type: ClientType::new("iconclient".to_string()),
packet: None,
mock_queries: HashMap::<Binary, Binary>::new(),
module_address: Some(Addr::unchecked("moduleaddress")),
Expand Down Expand Up @@ -831,6 +834,13 @@ impl TestContext {
ctx
}

pub fn for_client_state(env: Env) -> Self {
let mut ctx = TestContext::default(env);
ctx.client_id = ClientId::from_str("iconclient-0").unwrap();

ctx
}

fn setup_channel_end(
mut ctx: TestContext,
state: State,
Expand Down Expand Up @@ -1029,6 +1039,31 @@ impl TestContext {
self.save_consensus_state(storage, self.client_state.clone().unwrap().latest_height);
}

pub fn init_connection_delay(
&mut self,
storage: &mut dyn Storage,
contract: &CwIbcCoreContext,
) {
contract
.store_last_processed_on(storage, &self.env, &self.client_id)
.unwrap();
}

pub fn init_client_state(&mut self, deps: DepsMut, contract: &CwIbcCoreContext) {
self.init_context(deps.storage, &contract);
self.save_consensus_state(
deps.storage,
self.client_state.clone().unwrap().latest_height,
);
contract.init_client_counter(deps.storage, 0).unwrap();
self.save_client_commitment(
deps.storage,
&contract,
&self.client_state.clone().unwrap().encode_to_vec(),
);
self.save_register_client(deps, &contract);
}

pub fn save_next_sequence_send(&self, storage: &mut dyn Storage, contract: &CwIbcCoreContext) {
if let Some(packet) = self.packet.clone() {
contract
Expand Down Expand Up @@ -1081,6 +1116,42 @@ impl TestContext {
}
}

pub fn save_connection_to_client(
&self,
storage: &mut dyn Storage,
contract: &CwIbcCoreContext,
) {
contract
.store_connection_to_client(storage, &self.client_id, &self.connection_id)
.unwrap();
}

pub fn save_client_commitment(
&self,
storage: &mut dyn Storage,
contract: &CwIbcCoreContext,
client_state_hash: &Vec<u8>,
) {
contract
.store_client_commitment(
storage,
&self.env,
&self.client_id,
client_state_hash.clone(),
)
.unwrap();
}

pub fn save_register_client(&self, deps: DepsMut, contract: &CwIbcCoreContext) {
if let Some(lightclient) = self.lightclient.clone() {
let addr = Addr::unchecked(lightclient.get_address());

contract
.register_client(deps, self.client_type.clone(), addr)
.unwrap();
}
}

pub fn save_channel_end(&self, storage: &mut dyn Storage, contract: &CwIbcCoreContext) {
if let Some(channel_end) = self.channel_end.clone() {
contract
Expand Down
Loading

0 comments on commit 9a7876b

Please sign in to comment.