Skip to content

Commit

Permalink
cosmwasm: proof of concept cw-multi-test ibc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kakucodes committed Oct 28, 2024
1 parent 6e601b4 commit 532190a
Show file tree
Hide file tree
Showing 15 changed files with 431 additions and 43 deletions.
124 changes: 110 additions & 14 deletions cosmwasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions cosmwasm/contracts/wormchain-ibc-receiver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ crate-type = ["cdylib", "rlib"]
[features]
backtraces = ["cosmwasm-std/backtraces"]
library = []
test-interface = []

[dependencies]
cosmwasm-std = { version = "1.0.0", features = ["ibc3"] }
cosmwasm-schema = "1"
cw-storage-plus = "0.13.2"
cosmwasm-std = { version = "1.5.8", features = ["ibc3"] }
cosmwasm-schema = "1.5.8"
cw-storage-plus = "1.2.0"
anyhow = "1"
semver = "1.0.16"
thiserror = "1.0.31"
Expand All @@ -23,7 +24,17 @@ wormhole-sdk = { workspace = true, features = ["schemars"] }
serde_wormhole.workspace = true

[dev-dependencies]
cw-multi-test = { version = "0.20" }
abstract-cw-multi-test = "1.0.1"
serde-json-wasm = "0.4"
wormhole-bindings = { version = "0.1.0", features = ["fake"] }
serde = { version = "1.0.137", default-features = false, features = ["derive"] }

hex = "0.4.3"
wormhole-ibc = { path = "../wormhole-ibc", features = ["test-interface"] }
wormhole-cosmwasm = { version = "0.1.0", default-features = false, features = [
"library",
"full",
] }
wormchain-ibc-receiver = { path = "../wormchain-ibc-receiver", features = [
"test-interface",
] }
6 changes: 3 additions & 3 deletions cosmwasm/contracts/wormchain-ibc-receiver/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::error::ContractError;
use crate::msg::{AllChannelChainsResponse, ChannelChainResponse, ExecuteMsg, QueryMsg};
use crate::state::{CHANNEL_CHAIN, VAA_ARCHIVE};
use anyhow::{bail, ensure, Context};
use cosmwasm_std::{entry_point, to_binary, Binary, Deps, Empty, Event, StdResult};
use cosmwasm_std::{entry_point, to_json_binary, Binary, Deps, Empty, Event, StdResult};
use cosmwasm_std::{DepsMut, Env, MessageInfo, Order, Response};
use serde_wormhole::RawMessage;
use std::str;
Expand Down Expand Up @@ -132,10 +132,10 @@ fn handle_vaa(deps: DepsMut<WormholeQuery>, vaa: Binary) -> anyhow::Result<Event
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::ChannelChain { channel_id } => {
query_channel_chain(deps, channel_id).and_then(|resp| to_binary(&resp))
query_channel_chain(deps, channel_id).and_then(|resp| to_json_binary(&resp))
}
QueryMsg::AllChannelChains {} => {
query_all_channel_chains(deps).and_then(|resp| to_binary(&resp))
query_all_channel_chains(deps).and_then(|resp| to_json_binary(&resp))
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions cosmwasm/contracts/wormchain-ibc-receiver/src/ibc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{bail, ensure};
use cosmwasm_std::{
entry_point, from_slice, to_binary, Attribute, Binary, ContractResult, DepsMut, Env,
entry_point, from_json, to_json_binary, Attribute, Binary, ContractResult, DepsMut, Env,
Ibc3ChannelOpenResponse, IbcBasicResponse, IbcChannelCloseMsg, IbcChannelConnectMsg,
IbcChannelOpenMsg, IbcChannelOpenResponse, IbcPacketAckMsg, IbcPacketReceiveMsg,
IbcPacketTimeoutMsg, IbcReceiveResponse, StdError, StdResult,
Expand Down Expand Up @@ -91,7 +91,7 @@ fn handle_packet_receive(msg: IbcPacketReceiveMsg) -> Result<IbcReceiveResponse,
let packet = msg.packet;
// which local channel did this packet come on
let channel_id = packet.dest.channel_id;
let wormhole_msg: WormholeIbcPacketMsg = from_slice(&packet.data)?;
let wormhole_msg: WormholeIbcPacketMsg = from_json(&packet.data)?;
match wormhole_msg {
WormholeIbcPacketMsg::Publish { msg: publish_attrs } => {
receive_publish(channel_id, publish_attrs)
Expand Down Expand Up @@ -135,7 +135,7 @@ fn receive_publish(
}

// send the ack and emit the message with the attributes from the wormhole message
let acknowledgement = to_binary(&ContractResult::<()>::Ok(()))?;
let acknowledgement = to_json_binary(&ContractResult::<()>::Ok(()))?;
Ok(IbcReceiveResponse::new()
.set_ack(acknowledgement)
.add_attribute("action", "receive_publish")
Expand All @@ -146,7 +146,7 @@ fn receive_publish(
// this encode an error or error message into a proper acknowledgement to the recevier
fn encode_ibc_error(msg: impl Into<String>) -> Binary {
// this cannot error, unwrap to keep the interface simple
to_binary(&ContractResult::<()>::Err(msg.into())).unwrap()
to_json_binary(&ContractResult::<()>::Err(msg.into())).unwrap()
}

/// 5. Acknowledging a packet. Called when the other chain successfully receives a packet from us.
Expand Down
Loading

0 comments on commit 532190a

Please sign in to comment.