From e2db33cc99e8b64b56fc74b167d47614518f345a Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Fri, 26 Jan 2024 14:46:12 +0100 Subject: [PATCH 1/5] extend proto defs of mock types --- definitions/mock/ibc.mock.proto | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/definitions/mock/ibc.mock.proto b/definitions/mock/ibc.mock.proto index d8a2fe59..2b0bd5f3 100644 --- a/definitions/mock/ibc.mock.proto +++ b/definitions/mock/ibc.mock.proto @@ -1,19 +1,25 @@ syntax = "proto3"; package ibc.mock; +import "google/protobuf/duration.proto"; +import "google/protobuf/timestamp.proto"; import "ibc/core/client/v1/client.proto"; message Header { ibc.core.client.v1.Height height = 1; - uint64 timestamp = 2; + google.protobuf.Timestamp timestamp = 2; } message ClientState { Header header = 1; + google.protobuf.Duration trusing_period = 2; + google.protobuf.Duration max_clock_drift = 3; + bool frozen = 4; } message ConsensusState { Header header = 1; + bytes bytes = 2; } message Misbehaviour { From 574f0bf13fbab7a3485c86cf27e542778df3d039 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Thu, 1 Feb 2024 18:25:07 +0100 Subject: [PATCH 2/5] simpler structure --- definitions/mock/ibc.mock.proto | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/definitions/mock/ibc.mock.proto b/definitions/mock/ibc.mock.proto index 2b0bd5f3..1d490976 100644 --- a/definitions/mock/ibc.mock.proto +++ b/definitions/mock/ibc.mock.proto @@ -1,25 +1,21 @@ syntax = "proto3"; package ibc.mock; -import "google/protobuf/duration.proto"; -import "google/protobuf/timestamp.proto"; import "ibc/core/client/v1/client.proto"; message Header { ibc.core.client.v1.Height height = 1; - google.protobuf.Timestamp timestamp = 2; + uint64 timestamp = 2; } message ClientState { Header header = 1; - google.protobuf.Duration trusing_period = 2; - google.protobuf.Duration max_clock_drift = 3; + uint64 trusing_period = 2; bool frozen = 4; } message ConsensusState { Header header = 1; - bytes bytes = 2; } message Misbehaviour { From 10befa4ed3904ebcd3e5a5c5c794e73e250f91e2 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Thu, 1 Feb 2024 10:00:53 -0800 Subject: [PATCH 3/5] nit: types + frozen = 3 --- definitions/mock/ibc.mock.proto | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/definitions/mock/ibc.mock.proto b/definitions/mock/ibc.mock.proto index 1d490976..3b57cb2b 100644 --- a/definitions/mock/ibc.mock.proto +++ b/definitions/mock/ibc.mock.proto @@ -10,8 +10,8 @@ message Header { message ClientState { Header header = 1; - uint64 trusing_period = 2; - bool frozen = 4; + uint64 trusting_period = 2; + bool frozen = 3; } message ConsensusState { From e77383234b47993cfc1b91aaca25cce2ed772cdc Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Thu, 1 Feb 2024 10:01:51 -0800 Subject: [PATCH 4/5] chore: build mock protos --- src/prost/ibc.mock.rs | 4 ++++ src/prost/ibc.mock.serde.rs | 38 +++++++++++++++++++++++++++++++++ src/prost/proto_descriptor.bin | Bin 740247 -> 740422 bytes 3 files changed, 42 insertions(+) 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 Date: Thu, 1 Feb 2024 10:05:36 -0800 Subject: [PATCH 5/5] chore: add unclog --- .../unreleased/improvements/186-extend-ibc-mock-fields.md | 3 +++ 1 file changed, 3 insertions(+) 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)).