Skip to content

Commit

Permalink
Extend ibc::mock::ClientState with more data fields (#188)
Browse files Browse the repository at this point in the history
* extend proto defs of mock types

* simpler structure

* nit: types + frozen = 3

* chore: build mock protos

* chore: add unclog

---------

Co-authored-by: Farhad Shabani <[email protected]>
  • Loading branch information
rnbguy and Farhad-Shabani authored Feb 1, 2024
1 parent bdbfd0e commit 7643fa3
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
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;
}

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.

0 comments on commit 7643fa3

Please sign in to comment.