From e09235965713088ce92e2be11be33203dbab0039 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Tue, 30 Apr 2024 21:35:09 +0200 Subject: [PATCH] update method names --- ibc-testkit/src/context.rs | 41 ++++++++++--------- ibc-testkit/src/fixtures/core/context.rs | 6 +-- ibc-testkit/src/hosts/mod.rs | 4 +- ibc-testkit/src/relayer/integration.rs | 2 +- ibc-testkit/src/relayer/utils.rs | 2 +- .../tests/core/ics02_client/recover_client.rs | 2 +- .../tests/core/ics02_client/update_client.rs | 8 ++-- .../tests/core/ics04_channel/recv_packet.rs | 4 +- 8 files changed, 35 insertions(+), 34 deletions(-) diff --git a/ibc-testkit/src/context.rs b/ibc-testkit/src/context.rs index c81768b8a..846182e8c 100644 --- a/ibc-testkit/src/context.rs +++ b/ibc-testkit/src/context.rs @@ -122,7 +122,7 @@ where } /// Advances the host chain height to the given target height. - pub fn advance_block_up_to(mut self, target_height: Height) -> Self { + pub fn advance_block_up_to_height(mut self, target_height: Height) -> Self { let latest_height = self.host.latest_height(); if target_height.revision_number() != latest_height.revision_number() { panic!("Cannot advance history of the chain to a different revision number!") @@ -131,7 +131,7 @@ where } else { // Repeatedly advance the host chain height till we hit the desired height while self.host.latest_height().revision_height() < target_height.revision_height() { - self.advance_block() + self.advance_height() } } self @@ -139,13 +139,13 @@ where /// Advance the first height of the host chain by generating a genesis block. /// - /// This method is exactly the same as [`Self::advance_with_block_params`]. + /// This method is exactly the same as [`Self::advance_genesis_height`]. /// But it bootstraps the genesis block by height 1 and `genesis_time`. /// /// The method starts and ends with [`Self::end_block`] and [`Self::begin_block`], just - /// like the [`Self::advance_with_block_params`], so that it can advance to next height - /// i.e. height 2 - just by calling [`Self::advance_with_block_params`]. - pub fn advance_with_genesis_block(&mut self, genesis_time: Timestamp, params: &H::BlockParams) { + /// like the [`Self::advance_height_with_params`], so that it can advance to next height + /// i.e. height 2 - just by calling [`Self::advance_height_with_params`]. + pub fn advance_genesis_height(&mut self, genesis_time: Timestamp, params: &H::BlockParams) { self.end_block(); // commit multi store @@ -216,28 +216,29 @@ where .expect("no error"); } - /// Produces the next block for the host chain by first committing the state of - /// the host's multi store, and then generating a new block that is added to - /// the host's block history. - pub fn produce_block(&mut self, block_time: Duration, params: &H::BlockParams) { + /// Commit store state to the current block of the host chain by: + /// - Committing the state to the context's multi store. + /// - Generating a new block with the commitment. + /// - Adding the generated block to the host's block history. + pub fn commit_state_to_host(&mut self, block_time: Duration, params: &H::BlockParams) { // commit the multi store let multi_store_commitment = self.multi_store.commit().expect("no error"); - // generate a new block + // generate a new block and add it to the block history self.host - .advance_block(multi_store_commitment, block_time, params); + .commit_block(multi_store_commitment, block_time, params); } - /// Advances the host chain by ending the current block, producing a new block, and + /// Advances the host chain height by ending the current block, producing a new block, and /// beginning the next block. - pub fn advance_with_block_params(&mut self, block_time: Duration, params: &H::BlockParams) { + pub fn advance_height_with_params(&mut self, block_time: Duration, params: &H::BlockParams) { self.end_block(); - self.produce_block(block_time, params); + self.commit_state_to_host(block_time, params); self.begin_block(); } - /// Convenience method to advance the host chain using default parameters. - pub fn advance_block(&mut self) { - self.advance_with_block_params( + /// Convenience method to advance the host chain height using default parameters. + pub fn advance_height(&mut self) { + self.advance_height_with_params( Duration::from_secs(DEFAULT_BLOCK_TIME_SECS), &Default::default(), ) @@ -478,7 +479,7 @@ where self.dispatch(msg) .map_err(RelayerError::TransactionFailed)?; // Create a new block. - self.advance_block(); + self.advance_height(); Ok(()) } @@ -569,7 +570,7 @@ mod tests { let current_height = test.ctx.latest_height(); // After advancing the chain's height, the context should still be valid. - test.ctx.advance_block(); + test.ctx.advance_height(); assert!( test.ctx.host.validate().is_ok(), "failed in test [{}] {} while validating context {:?}", diff --git a/ibc-testkit/src/fixtures/core/context.rs b/ibc-testkit/src/fixtures/core/context.rs index d12fea7be..7810c6b77 100644 --- a/ibc-testkit/src/fixtures/core/context.rs +++ b/ibc-testkit/src/fixtures/core/context.rs @@ -68,11 +68,11 @@ where // store is at height 0; no block - context.advance_with_genesis_block(genesis_timestamp, &Default::default()); + context.advance_genesis_height(genesis_timestamp, &Default::default()); // store is at height 1; one block - context = context.advance_block_up_to( + context = context.advance_block_up_to_height( params .latest_height .sub(params.block_params_history.len() as u64) @@ -80,7 +80,7 @@ where ); for block_params in params.block_params_history { - context.advance_with_block_params(params.block_time, &block_params); + context.advance_height_with_params(params.block_time, &block_params); } assert_eq!( diff --git a/ibc-testkit/src/hosts/mod.rs b/ibc-testkit/src/hosts/mod.rs index 43b2e5ab1..3a4183401 100644 --- a/ibc-testkit/src/hosts/mod.rs +++ b/ibc-testkit/src/hosts/mod.rs @@ -64,8 +64,8 @@ pub trait TestHost: Default + Debug + Sized { /// Add a block to the host chain. fn push_block(&mut self, block: Self::Block); - /// Advance the host chain, by extending the history of blocks. - fn advance_block( + /// Commit a block with commitment root to the blockchain, by extending the history of blocks. + fn commit_block( &mut self, commitment_root: Vec, block_time: Duration, diff --git a/ibc-testkit/src/relayer/integration.rs b/ibc-testkit/src/relayer/integration.rs index 5d0a72b21..766a21f75 100644 --- a/ibc-testkit/src/relayer/integration.rs +++ b/ibc-testkit/src/relayer/integration.rs @@ -120,7 +120,7 @@ where .expect("successfully created send_packet"); // send_packet wasn't committed, hence produce a block - relayer.get_ctx_a_mut().advance_block(); + relayer.get_ctx_a_mut().advance_height(); // retrieve the send_packet event let Some(IbcEvent::SendPacket(send_packet_event)) = relayer diff --git a/ibc-testkit/src/relayer/utils.rs b/ibc-testkit/src/relayer/utils.rs index 02f0181d4..af93f6085 100644 --- a/ibc-testkit/src/relayer/utils.rs +++ b/ibc-testkit/src/relayer/utils.rs @@ -103,7 +103,7 @@ where /// Advances the block height on `A` until it catches up with the latest timestamp on `B`. pub fn sync_clock_on_a(ctx_a: &mut TestContext, ctx_b: &TestContext) { while ctx_b.latest_timestamp() > ctx_a.latest_timestamp() { - ctx_a.advance_block(); + ctx_a.advance_height(); } } diff --git a/ibc-testkit/tests/core/ics02_client/recover_client.rs b/ibc-testkit/tests/core/ics02_client/recover_client.rs index afed94eee..8f6f804b0 100644 --- a/ibc-testkit/tests/core/ics02_client/recover_client.rs +++ b/ibc-testkit/tests/core/ics02_client/recover_client.rs @@ -100,7 +100,7 @@ fn setup_client_recovery_fixture( // Let the subject client state expire. while ctx.latest_timestamp() <= subject_client_trusted_timestamp { - ctx.advance_block(); + ctx.advance_height(); } // at this point, the subject client should be expired. diff --git a/ibc-testkit/tests/core/ics02_client/update_client.rs b/ibc-testkit/tests/core/ics02_client/update_client.rs index aaca3b46f..88d511233 100644 --- a/ibc-testkit/tests/core/ics02_client/update_client.rs +++ b/ibc-testkit/tests/core/ics02_client/update_client.rs @@ -258,7 +258,7 @@ fn test_consensus_state_pruning() { let update_height = ctx.latest_height(); - ctx.advance_block(); + ctx.advance_height(); let block = ctx.host_block(&update_height).unwrap().clone(); let mut block = block.into_header(); @@ -1439,7 +1439,7 @@ fn test_expired_client() { while ctx.ibc_store.host_timestamp().expect("no error") < (timestamp + trusting_period).expect("no error") { - ctx.advance_block(); + ctx.advance_height(); } let client_state = ctx.ibc_store.client_state(&client_id).unwrap(); @@ -1494,11 +1494,11 @@ fn test_client_update_max_clock_drift() { while ctx_b.ibc_store.host_timestamp().expect("no error") < (ctx_a.ibc_store.host_timestamp().expect("no error") + max_clock_drift).expect("no error") { - ctx_b.advance_block(); + ctx_b.advance_height(); } // include current block - ctx_b.advance_block(); + ctx_b.advance_height(); let update_height = ctx_b.latest_height(); diff --git a/ibc-testkit/tests/core/ics04_channel/recv_packet.rs b/ibc-testkit/tests/core/ics04_channel/recv_packet.rs index f7c4deb13..df946f1e3 100644 --- a/ibc-testkit/tests/core/ics04_channel/recv_packet.rs +++ b/ibc-testkit/tests/core/ics04_channel/recv_packet.rs @@ -133,7 +133,7 @@ fn recv_packet_validate_happy_path(fixture: Fixture) { packet.chan_id_on_b.clone(), 1.into(), ) - .advance_block_up_to(host_height) + .advance_block_up_to_height(host_height) // This `with_recv_sequence` is required for ordered channels .with_recv_sequence( packet.port_id_on_b.clone(), @@ -192,7 +192,7 @@ fn recv_packet_timeout_expired(fixture: Fixture) { .with_connection(ConnectionId::zero(), conn_end_on_b) .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_b) .with_send_sequence(PortId::transfer(), ChannelId::zero(), 1.into()) - .advance_block_up_to(host_height); + .advance_block_up_to_height(host_height); let res = validate(&context.ibc_store, &router, msg_envelope);