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

Add support for configuring Wasm handling to MockQuerier #1137

Merged
merged 3 commits into from
Apr 4, 2022

Conversation

webmaster128
Copy link
Member

Closes #1050

Copy link
Contributor

@ueco-jb ueco-jb left a comment

Choose a reason for hiding this comment

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

I don't have experience in this part of code, but code itself looks solid and functionality is backed by tests.
My only "complain" is to a very long UT, which handles all the cases at once (so it's not a really UNIT test).
Otherwise, lgtm.

Comment on lines +1282 to +1284
#[test]
fn wasm_querier_works() {
let mut querier = WasmQuerier::default();
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a very long test for a UT. Consider splitting it.

Copy link
Member

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

This is a good first step to allowing some customizability.

In the issue we discuss ways to make this easier... standard implementations for handling RawQuery for example. But that can build on this original implementation as opt-in. Maybe even in cw-plus if we want. Just allowing an easy way to plug in a query handler is a great addition for extensibility and maybe all we need in the standard library.

/// always errors by default. Update it via `with_custom_handler`.
///
/// Use box to avoid the need of generic type.
handler: Box<dyn for<'a> Fn(&'a WasmQuery) -> QuerierResult>,
Copy link
Member

Choose a reason for hiding this comment

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

This would allow for a closure with some immutable data, but not mutable data, right?

I guess all mutability needs to happen before storing it in the WasmQuerier.

err => panic!("Unexpected error: {:?}", err),
}

querier.update_handler(|request| {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the problem with this approach is, this is still a lot of custom code to provide. Just to be able to set and find some values in the mock storage.

Isn't there a better / more generic way to do that for these mocks?

@ueco-jb
Copy link
Contributor

ueco-jb commented Apr 1, 2022

Is there any particular reason why this review is still up?

@webmaster128
Copy link
Member Author

Thank you

@webmaster128 webmaster128 merged commit 3740c07 into main Apr 4, 2022
@webmaster128 webmaster128 deleted the custom-wasmquerier branch April 4, 2022 06:32
- cosmwasm-std: `MockQuerier` now supports adding custom behaviour for handling
Wasm queries via `MockQuerier::update_wasm` ([#1050]).

[#1050]: https://github.com/CosmWasm/cosmwasm/pull/1050
Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, damn, this was added to the already released 1.0.0-beta7 section. Will fix on main branch.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh sorry, it's because it's under all other math related stuff I've been adding lately - didn't pay attention to the actual date.
Good catch, couple more things in changelog to shuffle

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.

Allow customising WasmQuerier in MockQuerier
4 participants