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

Extend ibc::mock types with more data fields #188

Merged
merged 5 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Extend `ibc::mock::ClientState` with `trusting_period` and `frozen` data
fields to cover a wider range of client state testing scenarios
([\#186](https://github.com/cosmos/ibc-proto-rs/issues/186)).
4 changes: 3 additions & 1 deletion definitions/mock/ibc.mock.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import "ibc/core/client/v1/client.proto";

message Header {
ibc.core.client.v1.Height height = 1;
uint64 timestamp = 2;
uint64 timestamp = 2;
}

message ClientState {
Header header = 1;
uint64 trusting_period = 2;
bool frozen = 3;
}
Farhad-Shabani marked this conversation as resolved.
Show resolved Hide resolved

message ConsensusState {
Expand Down
4 changes: 4 additions & 0 deletions src/prost/ibc.mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ impl ::prost::Name for Header {
pub struct ClientState {
#[prost(message, optional, tag = "1")]
pub header: ::core::option::Option<Header>,
#[prost(uint64, tag = "2")]
pub trusting_period: u64,
#[prost(bool, tag = "3")]
pub frozen: bool,
}
impl ::prost::Name for ClientState {
const NAME: &'static str = "ClientState";
Expand Down
38 changes: 38 additions & 0 deletions src/prost/ibc.mock.serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,23 @@ impl serde::Serialize for ClientState {
if true {
len += 1;
}
if true {
len += 1;
}
if true {
len += 1;
}
let mut struct_ser = serializer.serialize_struct("ibc.mock.ClientState", len)?;
if let Some(v) = self.header.as_ref() {
struct_ser.serialize_field("header", v)?;
}
if true {
#[allow(clippy::needless_borrow)]
struct_ser.serialize_field("trustingPeriod", ::alloc::string::ToString::to_string(&self.trusting_period).as_str())?;
}
if true {
struct_ser.serialize_field("frozen", &self.frozen)?;
}
struct_ser.end()
}
}
Expand All @@ -24,11 +37,16 @@ impl<'de> serde::Deserialize<'de> for ClientState {
{
const FIELDS: &[&str] = &[
"header",
"trusting_period",
"trustingPeriod",
"frozen",
];

#[allow(clippy::enum_variant_names)]
enum GeneratedField {
Header,
TrustingPeriod,
Frozen,
}
impl<'de> serde::Deserialize<'de> for GeneratedField {
fn deserialize<D>(deserializer: D) -> core::result::Result<GeneratedField, D::Error>
Expand All @@ -51,6 +69,8 @@ impl<'de> serde::Deserialize<'de> for ClientState {
{
match value {
"header" => Ok(GeneratedField::Header),
"trustingPeriod" | "trusting_period" => Ok(GeneratedField::TrustingPeriod),
"frozen" => Ok(GeneratedField::Frozen),
_ => Err(serde::de::Error::unknown_field(value, FIELDS)),
}
}
Expand All @@ -71,6 +91,8 @@ impl<'de> serde::Deserialize<'de> for ClientState {
V: serde::de::MapAccess<'de>,
{
let mut header__ = None;
let mut trusting_period__ = None;
let mut frozen__ = None;
while let Some(k) = map_.next_key()? {
match k {
GeneratedField::Header => {
Expand All @@ -79,10 +101,26 @@ impl<'de> serde::Deserialize<'de> for ClientState {
}
header__ = map_.next_value()?;
}
GeneratedField::TrustingPeriod => {
if trusting_period__.is_some() {
return Err(serde::de::Error::duplicate_field("trustingPeriod"));
}
trusting_period__ =
Some(map_.next_value::<::pbjson::private::NumberDeserialize<_>>()?.0)
;
}
GeneratedField::Frozen => {
if frozen__.is_some() {
return Err(serde::de::Error::duplicate_field("frozen"));
}
frozen__ = Some(map_.next_value()?);
}
}
}
Ok(ClientState {
header: header__,
trusting_period: trusting_period__.unwrap_or_default(),
frozen: frozen__.unwrap_or_default(),
})
}
}
Expand Down
Binary file modified src/prost/proto_descriptor.bin
Binary file not shown.
Loading