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): Deprecate MockContext::new* methods and their uses in favor of MockContextConfig #1042

Closed
rnbguy opened this issue Jan 18, 2024 · 0 comments · Fixed by #1047
Assignees
Milestone

Comments

@rnbguy
Copy link
Collaborator

rnbguy commented Jan 18, 2024

Bug Summary

Rust doesn't have default arguments in methods. So MockContext has two methods that allow initialization with default arguments in a hacky way.

We introduced MockContextConfig earlier to adopt the builder pattern.

But our tests are yet to be refactored to use MockContextConfig over MockContext::new.

Details

The following methods need to be deprecated

pub fn new(
host_id: ChainId,
host_type: HostType,
max_history_size: u64,
latest_height: Height,
) -> Self {

pub fn new_with_validator_history(
host_id: ChainId,
host_type: HostType,
validator_history: &[Vec<TestgenValidator>],
latest_height: Height,
) -> Self {

in favor of

/// Configuration of the `MockContext` type for generating dummy contexts.
#[derive(Debug, TypedBuilder)]
#[builder(build_method(into = MockContext))]
pub struct MockContextConfig {
#[builder(default = HostType::Mock)]
host_type: HostType,
host_id: ChainId,
#[builder(default = Duration::from_secs(DEFAULT_BLOCK_TIME_SECS))]
block_time: Duration,
// may panic if validator_set_history size is less than max_history_size + 1
#[builder(default = 5)]
max_history_size: u64,
#[builder(default, setter(strip_option))]
validator_set_history: Option<Vec<Vec<TestgenValidator>>>,
latest_height: Height,
#[builder(default = Timestamp::now())]
latest_timestamp: Timestamp,
}

Version

till v0.49.1

@rnbguy rnbguy self-assigned this Jan 18, 2024
@rnbguy rnbguy changed the title refactor(ibc-testkit): Deprecate MockContext::new* methods and their uses in favor of MockContextConfig imp(ibc-testkit): Deprecate MockContext::new* methods and their uses in favor of MockContextConfig Jan 18, 2024
@Farhad-Shabani Farhad-Shabani added this to the 0.50.0 milestone Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants