Skip to content

Commit

Permalink
update method names
Browse files Browse the repository at this point in the history
  • Loading branch information
rnbguy committed Apr 30, 2024
1 parent b0d3943 commit e092359
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 34 deletions.
41 changes: 21 additions & 20 deletions ibc-testkit/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!")

Check warning on line 128 in ibc-testkit/src/context.rs

View check run for this annotation

Codecov / codecov/patch

ibc-testkit/src/context.rs#L128

Added line #L128 was not covered by tests
Expand All @@ -131,21 +131,21 @@ 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
}

/// 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
Expand Down Expand Up @@ -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(),
)
Expand Down Expand Up @@ -478,7 +479,7 @@ where
self.dispatch(msg)
.map_err(RelayerError::TransactionFailed)?;
// Create a new block.
self.advance_block();
self.advance_height();
Ok(())
}

Expand Down Expand Up @@ -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 {:?}",
Expand Down
6 changes: 3 additions & 3 deletions ibc-testkit/src/fixtures/core/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@ 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)
.expect("no error"),
);

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!(
Expand Down
4 changes: 2 additions & 2 deletions ibc-testkit/src/hosts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>,
block_time: Duration,
Expand Down
2 changes: 1 addition & 1 deletion ibc-testkit/src/relayer/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ibc-testkit/src/relayer/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<A>, ctx_b: &TestContext<B>) {
while ctx_b.latest_timestamp() > ctx_a.latest_timestamp() {
ctx_a.advance_block();
ctx_a.advance_height();
}
}

Expand Down
2 changes: 1 addition & 1 deletion ibc-testkit/tests/core/ics02_client/recover_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions ibc-testkit/tests/core/ics02_client/update_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions ibc-testkit/tests/core/ics04_channel/recv_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit e092359

Please sign in to comment.