-
Notifications
You must be signed in to change notification settings - Fork 356
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
Use builder pattern for App init #388
Comments
Why not to just build
I possibly made some unreasonable things with Api right here as I didn't work with code, but basically demonstrated the idea. |
I think this is much more complex than needed. As they don't own the storage. But let's talk more later. |
What I don't like is exposing internals, or being able to call configuration function after setup is complete. But maybe just using actual idea about passing arguments to closure is not this bad:
|
Yeah, nice idea. How about that let mut app = Router::new()
.with_staking(stakingKeeper)
.setup(|router: &Router, storage: &mut dyn Storage| {
router.bank.init_balance(storage, &owner, coins(1000, "etc"));
router.bank.init_balance(storage, &trader, coins(10, "btc"));
router.staking.set_validator_weight(storage, val1, 1000);
}); |
So, we can call all the generic helpers only at the initial phase. |
I basically spend too much time on this without reasonable proposal. It turns out, that with current multitest design this approach is in my opinion pointless - it is up to test developer to properly structure test and just not intersperse test logic with setup. The problem is that, in one hand, we don't want to create So instead of overcomplicating setup I propose just add mocks for all components, and probably default App constructor so all those mocks doesn't need to be passed by hand. |
I'm now reviewing this. Looks good (the builder pattern for I would say, let's wait for @ethanfrey 's take on this. |
In terms of mockall - as I told in call - I like generality and configurability of generated mocks. I don't think adding additional dependency for testing is an issue. However I understand that it might be an issue that using it forces one to get familiar with aditional crate, but actually any way of mocking introduces an API. Anyway - I understand concerns. |
Extending #387
With the generic modules, we no longer have generic initialisation functions (like setting the balance).
I propose the following builder pattern.
Router::new()
// this will set with BankKeeper, WasmKeeper, and the rest unimplemented.with_staking(stakingKeeper)
// so we can extend these later.build_app()
// this will create an app with MockApi and MockStorageThe main question I have is how to call the setup/init methods on custom keepers that go beyond the default module types (eg. init_balance). Here are some examples:
We can either just set these on the router when building (and then pass the storage into the build_app constructor:
Or we can expose these with some closure in the app.
In either case, we must make the different keepers public on the router interface. I lean towards the second one.
The text was updated successfully, but these errors were encountered: