diff --git a/CHANGELOG.md b/CHANGELOG.md index f522363b6e..640b385808 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,8 @@ - [ibc] - Enable `pub` access to verification methods of ICS 03 & 04 ([#1198]) - Add `ics26_routing::handler::decode` function ([#1194]) - + - Add a pseudo root to `MockConsensusState` ([#1215]) + - [ibc-relayer-cli] - Added `upgrade-clients` CLI ([#763]) diff --git a/Cargo.lock b/Cargo.lock index 21bddae44f..b235a6630e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -787,9 +787,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.8.4" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" +checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" dependencies = [ "atty", "humantime", diff --git a/modules/src/ics02_client/handler/create_client.rs b/modules/src/ics02_client/handler/create_client.rs index 7d6f75fd74..3b2791aa69 100644 --- a/modules/src/ics02_client/handler/create_client.rs +++ b/modules/src/ics02_client/handler/create_client.rs @@ -88,7 +88,7 @@ mod tests { let msg = MsgCreateAnyClient::new( MockClientState(MockHeader::new(height)).into(), - MockConsensusState(MockHeader::new(height)).into(), + MockConsensusState::new(MockHeader::new(height)).into(), signer, ) .unwrap(); @@ -138,7 +138,7 @@ mod tests { ..height })) .into(), - MockConsensusState(MockHeader::new(Height { + MockConsensusState::new(MockHeader::new(Height { revision_height: 42, ..height })) @@ -152,7 +152,7 @@ mod tests { ..height })) .into(), - MockConsensusState(MockHeader::new(Height { + MockConsensusState::new(MockHeader::new(Height { revision_height: 42, ..height })) @@ -166,7 +166,7 @@ mod tests { ..height })) .into(), - MockConsensusState(MockHeader::new(Height { + MockConsensusState::new(MockHeader::new(Height { revision_height: 50, ..height })) diff --git a/modules/src/ics02_client/handler/upgrade_client.rs b/modules/src/ics02_client/handler/upgrade_client.rs index c420c3ffe1..b0b910c871 100644 --- a/modules/src/ics02_client/handler/upgrade_client.rs +++ b/modules/src/ics02_client/handler/upgrade_client.rs @@ -116,7 +116,7 @@ mod tests { let msg = MsgUpgradeAnyClient { client_id: client_id.clone(), client_state: MockClientState(MockHeader::new(Height::new(1, 26))).into(), - consensus_state: MockConsensusState(MockHeader::new(Height::new(1, 26))).into(), + consensus_state: MockConsensusState::new(MockHeader::new(Height::new(1, 26))).into(), proof_upgrade_client: MerkleProof::try_from(c_bytes).unwrap(), proof_upgrade_consensus_state: MerkleProof::try_from(cs_bytes).unwrap(), signer, @@ -167,7 +167,7 @@ mod tests { let msg = MsgUpgradeAnyClient { client_id: ClientId::from_str("nonexistingclient").unwrap(), client_state: MockClientState(MockHeader::new(Height::new(1, 26))).into(), - consensus_state: MockConsensusState(MockHeader::new(Height::new(1, 26))).into(), + consensus_state: MockConsensusState::new(MockHeader::new(Height::new(1, 26))).into(), proof_upgrade_client: MerkleProof::try_from(c_bytes).unwrap(), proof_upgrade_consensus_state: MerkleProof::try_from(cs_bytes).unwrap(), signer, @@ -201,7 +201,7 @@ mod tests { let msg = MsgUpgradeAnyClient { client_id, client_state: MockClientState(MockHeader::new(Height::new(0, 26))).into(), - consensus_state: MockConsensusState(MockHeader::new(Height::new(0, 26))).into(), + consensus_state: MockConsensusState::new(MockHeader::new(Height::new(0, 26))).into(), proof_upgrade_client: MerkleProof::try_from(c_bytes).unwrap(), proof_upgrade_consensus_state: MerkleProof::try_from(cs_bytes).unwrap(), signer, diff --git a/modules/src/ics02_client/msgs/upgrade_client.rs b/modules/src/ics02_client/msgs/upgrade_client.rs index 5a063a71fb..70a6e1cbb5 100644 --- a/modules/src/ics02_client/msgs/upgrade_client.rs +++ b/modules/src/ics02_client/msgs/upgrade_client.rs @@ -141,7 +141,7 @@ pub mod test_util { AnyClientState::Mock(MockClientState(MockHeader::new(height))).into(), ), consensus_state: Some( - AnyConsensusState::Mock(MockConsensusState(MockHeader::new(height))).into(), + AnyConsensusState::Mock(MockConsensusState::new(MockHeader::new(height))).into(), ), proof_upgrade_client: get_dummy_proof(), proof_upgrade_consensus_state: get_dummy_proof(), @@ -178,7 +178,8 @@ mod tests { let height = Height::new(1, 1); let client_state = AnyClientState::Mock(MockClientState(MockHeader::new(height))); - let consensus_state = AnyConsensusState::Mock(MockConsensusState(MockHeader::new(height))); + let consensus_state = + AnyConsensusState::Mock(MockConsensusState::new(MockHeader::new(height))); let proof = get_dummy_merkle_proof(); diff --git a/modules/src/ics26_routing/handler.rs b/modules/src/ics26_routing/handler.rs index 0e56371658..caea813c8b 100644 --- a/modules/src/ics26_routing/handler.rs +++ b/modules/src/ics26_routing/handler.rs @@ -204,7 +204,9 @@ mod tests { let create_client_msg = MsgCreateAnyClient::new( AnyClientState::from(MockClientState(MockHeader::new(start_client_height))), - AnyConsensusState::from(MockConsensusState(MockHeader::new(start_client_height))), + AnyConsensusState::Mock(MockConsensusState::new(MockHeader::new( + start_client_height, + ))), default_signer.clone(), ) .unwrap(); @@ -434,7 +436,7 @@ mod tests { msg: Ics26Envelope::Ics2Msg(ClientMsg::UpgradeClient(MsgUpgradeAnyClient::new( client_id.clone(), AnyClientState::Mock(MockClientState(MockHeader::new(upgrade_client_height))), - AnyConsensusState::Mock(MockConsensusState(MockHeader::new( + AnyConsensusState::Mock(MockConsensusState::new(MockHeader::new( upgrade_client_height, ))), get_dummy_merkle_proof(), @@ -450,7 +452,7 @@ mod tests { AnyClientState::Mock(MockClientState(MockHeader::new( upgrade_client_height_second, ))), - AnyConsensusState::Mock(MockConsensusState(MockHeader::new( + AnyConsensusState::Mock(MockConsensusState::new(MockHeader::new( upgrade_client_height_second, ))), get_dummy_merkle_proof(), diff --git a/modules/src/mock/client_def.rs b/modules/src/mock/client_def.rs index db33791946..4f4befa430 100644 --- a/modules/src/mock/client_def.rs +++ b/modules/src/mock/client_def.rs @@ -32,7 +32,7 @@ impl ClientDef for MockClient { "received header height is lower than (or equal to) client latest height".into(), ); } - Ok((MockClientState(header), MockConsensusState(header))) + Ok((MockClientState(header), MockConsensusState::new(header))) } fn verify_client_consensus_state( @@ -156,6 +156,6 @@ impl ClientDef for MockClient { _proof_upgrade_client: MerkleProof, _proof_upgrade_consensus_state: MerkleProof, ) -> Result<(Self::ClientState, Self::ConsensusState), Box> { - Ok((*client_state, *consensus_state)) + Ok((*client_state, consensus_state.clone())) } } diff --git a/modules/src/mock/client_state.rs b/modules/src/mock/client_state.rs index 2a15dc7ea1..5c86f9259a 100644 --- a/modules/src/mock/client_state.rs +++ b/modules/src/mock/client_state.rs @@ -104,16 +104,26 @@ impl ClientState for MockClientState { impl From for MockClientState { fn from(cs: MockConsensusState) -> Self { - Self(cs.0) + Self(cs.header) } } -#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize)] -pub struct MockConsensusState(pub MockHeader); +#[derive(Clone, Debug, PartialEq, Eq, Serialize)] +pub struct MockConsensusState { + pub header: MockHeader, + pub root: CommitmentRoot, +} impl MockConsensusState { + pub fn new(header: MockHeader) -> Self { + MockConsensusState { + header, + root: CommitmentRoot::from(vec![0]), + } + } + pub fn timestamp(&self) -> Timestamp { - (self.0).timestamp + self.header.timestamp } } @@ -127,7 +137,10 @@ impl TryFrom for MockConsensusState { .header .ok_or_else(|| ClientKind::InvalidRawConsensusState.context("missing header"))?; - Ok(Self(MockHeader::try_from(raw_header)?)) + Ok(Self { + header: MockHeader::try_from(raw_header)?, + root: CommitmentRoot::from(vec![0]), + }) } } @@ -135,8 +148,8 @@ impl From for RawMockConsensusState { fn from(value: MockConsensusState) -> Self { RawMockConsensusState { header: Some(ibc_proto::ibc::mock::Header { - height: Some(value.0.height().into()), - timestamp: (value.0).timestamp.as_nanoseconds(), + height: Some(value.header.height().into()), + timestamp: value.header.timestamp.as_nanoseconds(), }), } } @@ -154,11 +167,11 @@ impl ConsensusState for MockConsensusState { } fn root(&self) -> &CommitmentRoot { - todo!() + &self.root } fn validate_basic(&self) -> Result<(), Box> { - todo!() + Ok(()) } fn wrap_any(self) -> AnyConsensusState { diff --git a/modules/src/mock/context.rs b/modules/src/mock/context.rs index 5837fb832a..3713b86f6a 100644 --- a/modules/src/mock/context.rs +++ b/modules/src/mock/context.rs @@ -209,7 +209,7 @@ impl MockContext { // If it's a mock client, create the corresponding mock states. ClientType::Mock => ( Some(MockClientState(MockHeader::new(client_state_height)).into()), - MockConsensusState(MockHeader::new(cs_height)).into(), + MockConsensusState::new(MockHeader::new(cs_height)).into(), ), // If it's a Tendermint client, we need TM states. ClientType::Tendermint => { diff --git a/modules/src/mock/header.rs b/modules/src/mock/header.rs index bfa8386139..04269a2946 100644 --- a/modules/src/mock/header.rs +++ b/modules/src/mock/header.rs @@ -82,7 +82,7 @@ impl Header for MockHeader { impl From for AnyConsensusState { fn from(h: MockHeader) -> Self { - AnyConsensusState::Mock(MockConsensusState(h)) + AnyConsensusState::Mock(MockConsensusState::new(h)) } } diff --git a/modules/tests/runner/mod.rs b/modules/tests/runner/mod.rs index b1a7aaa5e1..4fbdc41f84 100644 --- a/modules/tests/runner/mod.rs +++ b/modules/tests/runner/mod.rs @@ -152,7 +152,7 @@ impl IbcTestRunner { } pub fn consensus_state(height: u64) -> AnyConsensusState { - AnyConsensusState::Mock(MockConsensusState(Self::mock_header(height))) + AnyConsensusState::Mock(MockConsensusState::new(Self::mock_header(height))) } fn signer() -> Signer {