Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imp(ibc-testkit): generalize Host for MockContext #1107

Merged
merged 30 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1c8dcc6
fix semantic conflict
rnbguy Feb 25, 2024
fedf772
happy clippy
rnbguy Feb 25, 2024
bda48c2
fix next_consensus_state impl
rnbguy Feb 25, 2024
af49053
update prev_consensus_state impl
rnbguy Feb 26, 2024
0a66c3b
use self.block_time over const
rnbguy Feb 26, 2024
18e2005
use constant timestamp over dynamic now
rnbguy Feb 29, 2024
4a15b79
add new host impls
rnbguy Feb 29, 2024
dd4f6ef
changes to ibc-testkit
rnbguy Feb 29, 2024
f9be068
rm deprecated methods
rnbguy Feb 29, 2024
a2bf476
refactor tests
rnbguy Feb 29, 2024
ba5935a
public fields for tm block params
rnbguy Feb 29, 2024
af2b52a
forged client header update test
rnbguy Feb 29, 2024
3f92f17
add todo comment
rnbguy Feb 29, 2024
805f7f1
minor refactor
rnbguy Mar 1, 2024
3480c97
refactor tests
rnbguy Mar 1, 2024
25c7bb5
builder type for light client state
rnbguy Mar 5, 2024
720a714
minor refactor
rnbguy Mar 5, 2024
47db1bc
refactor tests
rnbguy Mar 5, 2024
29386bd
code opt
rnbguy Mar 5, 2024
efffab0
rename host structs
rnbguy Mar 6, 2024
9bf774f
renamings
rnbguy Mar 6, 2024
e7c1bb3
refactor tendermint host
rnbguy Mar 6, 2024
fbcb2a5
mv year_2023 to utils
rnbguy Mar 6, 2024
a678b6f
refactor the new tests
rnbguy Mar 6, 2024
79104a1
test malicious adjacent header update
rnbguy Mar 6, 2024
7b46404
fix tests
rnbguy Mar 6, 2024
4fda8a5
add changelog
rnbguy Mar 6, 2024
c1b03d9
rm unused chain_revision_number
rnbguy Mar 7, 2024
1561834
add doc string for year_2023
rnbguy Mar 7, 2024
531c3c9
rename to query_latest_block
rnbguy Mar 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [ibc-testkit] Refactor `HostBlock` enum to `Host` trait
([\#1044](https://github.com/cosmos/ibc-rs/issues/1044))
38 changes: 18 additions & 20 deletions ibc-testkit/src/fixtures/core/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ use ibc::core::client::types::Height;
use ibc::core::host::types::identifiers::ChainId;
use ibc::core::primitives::prelude::*;
use ibc::core::primitives::Timestamp;
use tendermint_testgen::Validator as TestgenValidator;
use typed_builder::TypedBuilder;

use crate::hosts::block::{HostBlock, HostType};
use crate::hosts::TestHost;
use crate::testapp::ibc::core::types::{MockGenericContext, MockIbcStore, DEFAULT_BLOCK_TIME_SECS};
use crate::utils::year_2023;

/// Configuration of the `MockContext` type for generating dummy contexts.
#[derive(Debug, TypedBuilder)]
#[builder(build_method(into))]
pub struct MockContextConfig {
#[builder(default = HostType::Mock)]
host_type: HostType,

pub struct MockContextConfig<H>
where
H: TestHost,
{
#[builder(default = ChainId::new("mockgaia-0").expect("Never fails"))]
host_id: ChainId,

Expand All @@ -32,20 +32,21 @@ pub struct MockContextConfig {
max_history_size: u64,

#[builder(default, setter(strip_option))]
validator_set_history: Option<Vec<Vec<TestgenValidator>>>,
block_params_history: Option<Vec<H::BlockParams>>,

#[builder(default = Height::new(0, 5).expect("Never fails"))]
latest_height: Height,

#[builder(default = Timestamp::now())]
#[builder(default = year_2023())]
latest_timestamp: Timestamp,
}

impl<S> From<MockContextConfig> for MockGenericContext<S>
impl<S, H> From<MockContextConfig<H>> for MockGenericContext<S, H>
where
S: ProvableStore + Debug + Default,
H: TestHost,
{
fn from(params: MockContextConfig) -> Self {
fn from(params: MockContextConfig<H>) -> Self {
assert_ne!(
params.max_history_size, 0,
"The chain must have a non-zero max_history_size"
Expand Down Expand Up @@ -74,15 +75,15 @@ where
.add(params.block_time)
.expect("Never fails");

let history = if let Some(validator_set_history) = params.validator_set_history {
let host = H::with_chain_id(params.host_id);

let history = if let Some(validator_set_history) = params.block_params_history {
(0..n)
.rev()
.map(|i| {
// generate blocks with timestamps -> N, N - BT, N - 2BT, ...
// where N = now(), BT = block_time
HostBlock::generate_block_with_validators(
params.host_id.clone(),
params.host_type,
host.generate_block(
params
.latest_height
.sub(i)
Expand All @@ -92,7 +93,6 @@ where
.sub(params.block_time * ((i + 1) as u32))
.expect("Never fails"),
&validator_set_history[(n - i) as usize - 1],
&validator_set_history[(n - i) as usize],
)
})
.collect()
Expand All @@ -102,9 +102,7 @@ where
.map(|i| {
// generate blocks with timestamps -> N, N - BT, N - 2BT, ...
// where N = now(), BT = block_time
HostBlock::generate_block(
params.host_id.clone(),
params.host_type,
host.generate_block(
params
.latest_height
.sub(i)
Expand All @@ -113,14 +111,14 @@ where
next_block_timestamp
.sub(params.block_time * ((i + 1) as u32))
.expect("Never fails"),
&H::BlockParams::default(),
)
})
.collect()
};

MockGenericContext {
host_chain_type: params.host_type,
host_chain_id: params.host_id.clone(),
host,
max_history_size: params.max_history_size,
history,
block_time: params.block_time,
Expand Down
3 changes: 2 additions & 1 deletion ibc-testkit/src/fixtures/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use alloc::fmt::Debug;
use ibc::core::handler::types::error::ContextError;
use ibc::core::primitives::prelude::*;

use crate::hosts::MockHost;
use crate::testapp::ibc::core::types::MockContext;
pub enum Expect {
Success,
Expand All @@ -14,7 +15,7 @@ pub enum Expect {

#[derive(Debug)]
pub struct Fixture<M: Debug> {
pub ctx: MockContext,
pub ctx: MockContext<MockHost>,
pub msg: M,
}

Expand Down
260 changes: 0 additions & 260 deletions ibc-testkit/src/hosts/block.rs

This file was deleted.

Loading
Loading