From 7643fa3f63d7da55daf8a3416a0addb9d62d3fcd Mon Sep 17 00:00:00 2001 From: Rano | Ranadeep Date: Thu, 1 Feb 2024 14:03:39 -0500 Subject: [PATCH] Extend `ibc::mock::ClientState` with more data fields (#188) * extend proto defs of mock types * simpler structure * nit: types + frozen = 3 * chore: build mock protos * chore: add unclog --------- Co-authored-by: Farhad Shabani --- .../186-extend-ibc-mock-fields.md | 3 ++ definitions/mock/ibc.mock.proto | 4 +- src/prost/ibc.mock.rs | 4 ++ src/prost/ibc.mock.serde.rs | 38 ++++++++++++++++++ src/prost/proto_descriptor.bin | Bin 740247 -> 740422 bytes 5 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 .changelog/unreleased/improvements/186-extend-ibc-mock-fields.md diff --git a/.changelog/unreleased/improvements/186-extend-ibc-mock-fields.md b/.changelog/unreleased/improvements/186-extend-ibc-mock-fields.md new file mode 100644 index 00000000..0f390b34 --- /dev/null +++ b/.changelog/unreleased/improvements/186-extend-ibc-mock-fields.md @@ -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)). diff --git a/definitions/mock/ibc.mock.proto b/definitions/mock/ibc.mock.proto index d8a2fe59..3b57cb2b 100644 --- a/definitions/mock/ibc.mock.proto +++ b/definitions/mock/ibc.mock.proto @@ -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 { diff --git a/src/prost/ibc.mock.rs b/src/prost/ibc.mock.rs index d47fadf7..e608e01d 100644 --- a/src/prost/ibc.mock.rs +++ b/src/prost/ibc.mock.rs @@ -18,6 +18,10 @@ impl ::prost::Name for Header { pub struct ClientState { #[prost(message, optional, tag = "1")] pub header: ::core::option::Option
, + #[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"; diff --git a/src/prost/ibc.mock.serde.rs b/src/prost/ibc.mock.serde.rs index 0e279efd..67700bbd 100644 --- a/src/prost/ibc.mock.serde.rs +++ b/src/prost/ibc.mock.serde.rs @@ -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() } } @@ -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(deserializer: D) -> core::result::Result @@ -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)), } } @@ -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 => { @@ -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(), }) } } diff --git a/src/prost/proto_descriptor.bin b/src/prost/proto_descriptor.bin index ae805c553896cdb51d5db0025c7069d1c406032c..e1e93ac386d6ecbc3b90d519fa4116c2f21aa8d8 100644 GIT binary patch delta 542 zcmX|-Jxjw-6oz}wy-Aa6(w6+MY zg5WQ37ypE_=O(!sUdVILecqfzsqWXJ`|t)oOZ;}!?-CYpucj+FK9vWeGs*96CxhY5 z#kijjMpqf`!y)gr&GC70DidK}=c8$Vm@%3=y^7R&1)uPzK2EG{_4Eoa&{julIGb$= z&H+KP7Ve3buryej97B5MW`-Ei&aNmml*~g}jgT}CZ9}AaP0tW%o*xJykfY>&LjpZB zjx)OEJ4w-p*pMv1sBj2uP30OybTM!{W=4I142wP{dDO_tK1R19Co1Zgu8T1(6arc= zuIh;BV(dyW)1OR8eQ{i_!SvrqFs?kHHImu`J#&3CBP|Kd>*#N!wT7gnwWcf6T0_#( eFuJtI`Qv;86r?Z;r&tu5(xf;P_kF$*@$)~b9ZF>Y delta 368 zcmX|+y-fo_5QTSU_Ws6}&)T0OpajdYE1({75|fz@)<`4-q&CP%6o5nlG=OM<9LaBO z?*-pUpJv|Mxv%XqrRDuQ{p|RqNxwVV(kk8U@%h`+XZK*WcGj37J^wc$eZSHZP1Efg z-KTYCsh^8&u2)!DR8`u2xo*bMtRoF%M7vL%X91`jxk0oj