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

Create Envs, a factory for making mock Envs #2442

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Create Envs, a factory for making mock Envs #2442

wants to merge 5 commits into from

Conversation

webmaster128
Copy link
Member

@webmaster128 webmaster128 commented Mar 26, 2025

A potential solution for #2218. Not necessarily ready yet but I wonder if this looks good.

Closes #2218

@webmaster128 webmaster128 requested a review from chipshort March 26, 2025 15:09
Copy link
Collaborator

@chipshort chipshort left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea! That way we could even extend it if we need more configurability in the future.


pub fn make(&mut self) -> Env {
let height = self.last_height + 1;
let time = self.last_time.plus_seconds(5);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to make the time increment configurable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of things are configurable now. See EnvsOptions

/// assert_eq!(env.block.time, Timestamp::from_nanos(1_571_797_419_879_305_533).plus_seconds((index*5) as u64));
/// }
/// ```
pub struct Envs {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a more specific name would be better? Envs sounds very generic and doesn't really indicate that this is for testing only.

Copy link
Member Author

@webmaster128 webmaster128 Apr 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy for suggestions. But I doubt this will be used in the majority of test code.

You have to import it through cosmwasm_std::testing::Envs, so testing is implied here

@webmaster128 webmaster128 marked this pull request as ready for review April 7, 2025 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create mock_env() alternative that supports non-default address generators (aka. other bech32 prefixes)
2 participants