Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imp(08-wasm): supersede Bytes with cosmwasm_std::Binary #1272

Merged
merged 9 commits into from
Jul 11, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [ibc-client-cw] Supersede `Bytes` with `cosmwasm::Binary`.
([\#1271](https://github.com/cosmos/ibc-rs/issues/1271))
Farhad-Shabani marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions ci/cw-check/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct Msg {
pub test: String,
}

#[cfg_attr(not(feature = "library"), cosmwasm_std::entry_point)]
#[cosmwasm_std::entry_point]
pub fn instantiate(
_deps: DepsMut,
_env: Env,
Expand Down Expand Up @@ -49,7 +49,7 @@ pub fn instantiate(
.add_attribute(msg.test.clone(), msg.test.clone()))
}

#[cfg_attr(not(feature = "library"), cosmwasm_std::entry_point)]
#[cosmwasm_std::entry_point]
pub fn execute(
_deps: DepsMut,
_env: Env,
Expand Down
18 changes: 9 additions & 9 deletions ibc-clients/cw-context/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use crate::types::{ContractError, GenesisMetadata, HeightTravel, MigrationPrefix};
use crate::utils::AnyCodec;

type Checksum = Vec<u8>;
type Checksum = cosmwasm_std::Binary;

/// - [`Height`] cannot be used directly as keys in the map,
/// as it doesn't implement some cw_storage specific traits.
Expand Down Expand Up @@ -241,13 +241,13 @@

let processed_height_key = self.client_update_height_key(&height);
metadata.push(GenesisMetadata {
key: processed_height_key.clone(),
value: self.retrieve(&processed_height_key)?,
key: processed_height_key.clone().into(),
value: self.retrieve(&processed_height_key)?.into(),

Check warning on line 245 in ibc-clients/cw-context/src/context/mod.rs

View check run for this annotation

Codecov / codecov/patch

ibc-clients/cw-context/src/context/mod.rs#L244-L245

Added lines #L244 - L245 were not covered by tests
});
let processed_time_key = self.client_update_time_key(&height);
metadata.push(GenesisMetadata {
key: processed_time_key.clone(),
value: self.retrieve(&processed_time_key)?,
key: processed_time_key.clone().into(),
value: self.retrieve(&processed_time_key)?.into(),

Check warning on line 250 in ibc-clients/cw-context/src/context/mod.rs

View check run for this annotation

Codecov / codecov/patch

ibc-clients/cw-context/src/context/mod.rs#L249-L250

Added lines #L249 - L250 were not covered by tests
});
}

Expand All @@ -265,8 +265,8 @@
let height = height_result?;

metadata.push(GenesisMetadata {
key: iteration_key(height.revision_number(), height.revision_height()),
value: height.encode_vec(),
key: iteration_key(height.revision_number(), height.revision_height()).into(),
value: height.encode_vec().into(),

Check warning on line 269 in ibc-clients/cw-context/src/context/mod.rs

View check run for this annotation

Codecov / codecov/patch

ibc-clients/cw-context/src/context/mod.rs#L268-L269

Added lines #L268 - L269 were not covered by tests
});
}

Expand All @@ -287,7 +287,7 @@
}
})?;

Ok(wasm_client_state.checksum)
Ok(wasm_client_state.checksum.into())
}
}
}
Expand All @@ -298,7 +298,7 @@
client_state: C::ClientState,
) -> Result<Vec<u8>, ClientError> {
let wasm_client_state = WasmClientState {
checksum: self.obtain_checksum()?,
checksum: self.obtain_checksum()?.into(),
latest_height: client_state.latest_height(),
data: C::ClientState::encode_to_any_vec(client_state),
};
Expand Down
71 changes: 22 additions & 49 deletions ibc-clients/cw-context/src/types/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
use std::str::FromStr;

use cosmwasm_schema::{cw_serde, QueryResponses};
use ibc_client_wasm_types::serializer::Base64;
use ibc_client_wasm_types::Bytes;
use cosmwasm_std::Binary;
use ibc_core::client::types::proto::v1::Height as RawHeight;
use ibc_core::client::types::Height;
use ibc_core::commitment_types::commitment::{CommitmentPrefix, CommitmentProofBytes};
Expand All @@ -20,15 +19,9 @@

#[cw_serde]
pub struct InstantiateMsg {
#[schemars(with = "String")]
#[serde(with = "Base64", default)]
pub client_state: Bytes,
#[schemars(with = "String")]
#[serde(with = "Base64", default)]
pub consensus_state: Bytes,
#[schemars(with = "String")]
#[serde(with = "Base64", default)]
pub checksum: Bytes,
pub client_state: Binary,
pub consensus_state: Binary,
pub checksum: Binary,
}

// ------------------------------------------------------------
Expand All @@ -48,9 +41,7 @@

#[cw_serde]
pub struct UpdateStateOnMisbehaviourMsgRaw {
#[schemars(with = "String")]
#[serde(with = "Base64", default)]
pub client_message: Bytes,
pub client_message: Binary,
}

pub struct UpdateStateOnMisbehaviourMsg {
Expand All @@ -69,9 +60,7 @@

#[cw_serde]
pub struct UpdateStateMsgRaw {
#[schemars(with = "String")]
#[serde(with = "Base64", default)]
pub client_message: Bytes,
pub client_message: Binary,
}

pub struct UpdateStateMsg {
Expand All @@ -93,18 +82,10 @@

#[cw_serde]
pub struct VerifyUpgradeAndUpdateStateMsgRaw {
#[schemars(with = "String")]
#[serde(with = "Base64", default)]
pub upgrade_client_state: Bytes,
#[schemars(with = "String")]
#[serde(with = "Base64", default)]
pub upgrade_consensus_state: Bytes,
#[schemars(with = "String")]
#[serde(with = "Base64", default)]
pub proof_upgrade_client: Bytes,
#[schemars(with = "String")]
#[serde(with = "Base64", default)]
pub proof_upgrade_consensus_state: Bytes,
pub upgrade_client_state: Binary,
pub upgrade_consensus_state: Binary,
pub proof_upgrade_client: Binary,
pub proof_upgrade_consensus_state: Binary,
}

pub struct VerifyUpgradeAndUpdateStateMsg {
Expand All @@ -125,9 +106,11 @@
Ok(VerifyUpgradeAndUpdateStateMsg {
upgrade_client_state,
upgrade_consensus_state,
proof_upgrade_client: CommitmentProofBytes::try_from(raw.proof_upgrade_client)?,
proof_upgrade_client: CommitmentProofBytes::try_from(
raw.proof_upgrade_client.to_vec(),
)?,

Check warning on line 111 in ibc-clients/cw-context/src/types/msgs.rs

View check run for this annotation

Codecov / codecov/patch

ibc-clients/cw-context/src/types/msgs.rs#L109-L111

Added lines #L109 - L111 were not covered by tests
proof_upgrade_consensus_state: CommitmentProofBytes::try_from(
raw.proof_upgrade_consensus_state,
raw.proof_upgrade_consensus_state.to_vec(),

Check warning on line 113 in ibc-clients/cw-context/src/types/msgs.rs

View check run for this annotation

Codecov / codecov/patch

ibc-clients/cw-context/src/types/msgs.rs#L113

Added line #L113 was not covered by tests
)?,
})
}
Expand All @@ -140,13 +123,9 @@

#[cw_serde]
pub struct VerifyMembershipMsgRaw {
#[schemars(with = "String")]
#[serde(with = "Base64", default)]
pub proof: Bytes,
pub proof: Binary,
pub path: MerklePath,
#[schemars(with = "String")]
#[serde(with = "Base64", default)]
pub value: Bytes,
pub value: Binary,
pub height: RawHeight,
pub delay_block_period: u64,
pub delay_time_period: u64,
Expand All @@ -166,7 +145,7 @@
type Error = ContractError;

fn try_from(mut raw: VerifyMembershipMsgRaw) -> Result<Self, Self::Error> {
let proof = CommitmentProofBytes::try_from(raw.proof)?;
let proof = CommitmentProofBytes::try_from(raw.proof.to_vec())?;

Check warning on line 148 in ibc-clients/cw-context/src/types/msgs.rs

View check run for this annotation

Codecov / codecov/patch

ibc-clients/cw-context/src/types/msgs.rs#L148

Added line #L148 was not covered by tests
let prefix = raw.path.key_path.remove(0).into_bytes();
let path_str = raw.path.key_path.join("");
let path = Path::from_str(&path_str)?;
Expand All @@ -175,7 +154,7 @@
Ok(Self {
proof,
path,
value: raw.value,
value: raw.value.into(),

Check warning on line 157 in ibc-clients/cw-context/src/types/msgs.rs

View check run for this annotation

Codecov / codecov/patch

ibc-clients/cw-context/src/types/msgs.rs#L157

Added line #L157 was not covered by tests
height,
prefix: CommitmentPrefix::try_from(prefix)?,
delay_block_period: raw.delay_block_period,
Expand All @@ -186,9 +165,7 @@

#[cw_serde]
pub struct VerifyNonMembershipMsgRaw {
#[schemars(with = "String")]
#[serde(with = "Base64", default)]
pub proof: Bytes,
pub proof: Binary,
pub path: MerklePath,
pub height: RawHeight,
pub delay_block_period: u64,
Expand All @@ -208,7 +185,7 @@
type Error = ContractError;

fn try_from(mut raw: VerifyNonMembershipMsgRaw) -> Result<Self, Self::Error> {
let proof = CommitmentProofBytes::try_from(raw.proof)?;
let proof = CommitmentProofBytes::try_from(raw.proof.to_vec())?;

Check warning on line 188 in ibc-clients/cw-context/src/types/msgs.rs

View check run for this annotation

Codecov / codecov/patch

ibc-clients/cw-context/src/types/msgs.rs#L188

Added line #L188 was not covered by tests
let prefix = raw.path.key_path.remove(0).into_bytes();
let path_str = raw.path.key_path.join("");
let path = Path::from_str(&path_str)?;
Expand Down Expand Up @@ -259,9 +236,7 @@

#[cw_serde]
pub struct VerifyClientMessageRaw {
#[schemars(with = "String")]
#[serde(with = "Base64", default)]
pub client_message: Bytes,
pub client_message: Binary,
}

pub struct VerifyClientMessageMsg {
Expand All @@ -280,9 +255,7 @@

#[cw_serde]
pub struct CheckForMisbehaviourMsgRaw {
#[schemars(with = "String")]
#[serde(with = "Base64", default)]
pub client_message: Bytes,
pub client_message: Binary,
}

pub struct CheckForMisbehaviourMsg {
Expand Down
6 changes: 3 additions & 3 deletions ibc-clients/cw-context/src/types/response.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Contains the response types for the CosmWasm contract.
use cosmwasm_schema::cw_serde;
use ibc_client_wasm_types::Bytes;
rnbguy marked this conversation as resolved.
Show resolved Hide resolved
use cosmwasm_std::Binary;
use ibc_core::client::types::Height;

#[cw_serde]
pub struct GenesisMetadata {
pub key: Bytes,
pub value: Bytes,
pub key: Binary,
pub value: Binary,
}

#[cw_serde]
Expand Down
34 changes: 28 additions & 6 deletions tests-integration/tests/cosmwasm/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ impl Fixture {
let tm_consensus_state = dummy_sov_consensus_state(self.trusted_timestamp);

InstantiateMsg {
client_state: TmClientState::encode_to_any_vec(tm_client_state),
consensus_state: TmConsensusState::encode_to_any_vec(tm_consensus_state),
client_state: TmClientState::encode_to_any_vec(tm_client_state).into(),
consensus_state: TmConsensusState::encode_to_any_vec(tm_consensus_state).into(),
checksum: dummy_checksum(),
}
}
Expand Down Expand Up @@ -139,7 +139,13 @@ impl Fixture {

pub fn verify_client_message(&self, deps: Deps<'_>, client_message: Vec<u8>) {
let resp = self
.query(deps, VerifyClientMessageRaw { client_message }.into())
.query(
deps,
VerifyClientMessageRaw {
client_message: client_message.into(),
}
.into(),
)
.unwrap();

assert!(resp.is_valid);
Expand All @@ -149,7 +155,13 @@ impl Fixture {

pub fn check_for_misbehaviour(&self, deps: Deps<'_>, client_message: Vec<u8>) {
let resp = self
.query(deps, CheckForMisbehaviourMsgRaw { client_message }.into())
.query(
deps,
CheckForMisbehaviourMsgRaw {
client_message: client_message.into(),
}
.into(),
)
.unwrap();

assert!(resp.is_valid);
Expand Down Expand Up @@ -199,7 +211,12 @@ impl Fixture {

let mut ctx = self.ctx_mut(deps_mut);

let data = ctx.sudo(UpdateStateMsgRaw { client_message }.into())?;
let data = ctx.sudo(
UpdateStateMsgRaw {
client_message: client_message.into(),
}
.into(),
)?;

Ok(Response::default().set_data(data))
}
Expand All @@ -212,7 +229,12 @@ impl Fixture {
let mut ctx = self.ctx_mut(deps_mut);

let data = ctx
.sudo(UpdateStateOnMisbehaviourMsgRaw { client_message }.into())
.sudo(
UpdateStateOnMisbehaviourMsgRaw {
client_message: client_message.into(),
}
.into(),
)
.unwrap();

Response::default().set_data(data)
Expand Down
5 changes: 3 additions & 2 deletions tests-integration/tests/cosmwasm/helper.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::str::FromStr;

use cosmwasm_std::testing::{message_info, mock_dependencies, mock_env};
use cosmwasm_std::{coins, Env, MessageInfo, Timestamp as CwTimestamp};
use cosmwasm_std::{coins, Binary, Env, MessageInfo, Timestamp as CwTimestamp};
use ibc::clients::tendermint::types::ConsensusState;
use ibc::core::primitives::Timestamp as IbcTimestamp;
use tendermint::Hash;
Expand All @@ -13,9 +13,10 @@ pub fn dummy_msg_info() -> MessageInfo {
message_info(&creator, &coins(1000, "ibc"))
}

pub fn dummy_checksum() -> Vec<u8> {
pub fn dummy_checksum() -> Binary {
rnbguy marked this conversation as resolved.
Show resolved Hide resolved
hex::decode("2469f43c3ca20d476442bd3d98cbd97a180776ab37332aa7b02cae5a620acfc6")
.expect("Never fails")
.into()
}

pub fn dummy_sov_consensus_state(timestamp: IbcTimestamp) -> ConsensusState {
Expand Down
2 changes: 1 addition & 1 deletion tests-integration/tests/cosmwasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn test_cw_client_expiry() {
let resp = fxt.query(
deps.as_ref(),
VerifyClientMessageRaw {
client_message: client_message.clone(),
client_message: client_message.into(),
}
.into(),
);
Expand Down
Loading