-
Notifications
You must be signed in to change notification settings - Fork 355
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
multi-test: Pass in API access to BankKeeper #353
Comments
The borrow in bank approach would not work with safe Rust - it is typical example of self referential structure. It is possible to do with bunch of unsafe code, but I don't see how it is worth especially in tests. There are some crates hiding such unsafeness, but I didn't find clear winner here on the market and I am not sure about using some not well-known in community crate to thing like this. Also I suspect that at some time we would actually get Polonius, and if we are lucky it would allow for easier self references. The other idea you proposed is cloning whole API - not bad idea, as it is just single The third way is just to use Way I would take is to take
The downside is that @ethanfrey I need your opinion on those four (basically I am debating between 3rd and 4rd approach). |
3 and 4 both seem reasonable. This just needs to be usable by unit tests, so api outside app seems fine. let api = mock_api();
let app = mock_app(&api);
// ... use app in tests is only one more line in setup and quite easy to implement.
This would actually allow us to share lots of immutable references everywhere, and keep the same setup flow as now and expose it to many keepers. What do you not like about it? If you have a good reason not to, I am happy with (4) |
I just find |
Fair enough, let's go with case (4) and just pass in &api when creating the App |
See TODO: https://github.com/CosmWasm/cosmwasm-plus/blob/15685ab98ad7a6785357ea4341dcb2a3b7999e44/packages/multi-test/src/bank.rs#L143
The ability to validate addresses is in
Api
and bank should have that as well (and any future keeper as well).Find an easy way to pass this into BankKeeper as well. We either want to clone Api to provide multiple copies for each keeper (which is not implemented on the trait), or just pass in &dyn Api to each Keeper and hold
Box<dyn Api>
in the App. You only need&Api
as it exposes pure functions, but I am not sure how these references play with lifetimes.After getting Api into bank, then we can properly validate any input and reject sends to invalid addresses
The text was updated successfully, but these errors were encountered: