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 dispatcher to test contracts calling contracts #90

Closed
ethanfrey opened this issue Dec 21, 2019 · 6 comments
Closed

Add dispatcher to test contracts calling contracts #90

ethanfrey opened this issue Dec 21, 2019 · 6 comments
Milestone

Comments

@ethanfrey
Copy link
Member

Minimal emulation of some of the sdk code, especially for the (non-wasm) unit tests.

Allow to register multiple modules with unique HumanAddr.
Launch a message on a Dispatcher and if it returns a message, attempt to route to other modules and so on.

Dispatcher exposes handle and query. query allows raw queries and smart queries to all the registered modules. Note that Dispatcher must handle multiple MockStorage for the contracts as well.

This is only designed for test code and should be optimized for ergonomics not performance.

@ethanfrey
Copy link
Member Author

@webmaster128 do you have any opinions here? The main use case in my mind is erc20 atomic swap contract testing (you need to have 2 contracts interact). Design ideas would be great. I just know this should work easily (whatever that means)

@ethanfrey
Copy link
Member Author

Short ideal is dispatcher takes api and storage as constructor.

Define a module as 3 function pointers, to init handle and query.

The dispatcher has the following methods

init(Module, Params, InitMsg) -> Result

handle(HumanAddr, Params, HandleMsg) -> Result<data? Log?>

query(HumanAddr, QueryMsg) -> Result

The human address is auto generated on init and a unique storage is set up for it.

@ethanfrey
Copy link
Member Author

ethanfrey commented Mar 17, 2020

I think to do this as a separate repo, like cw-storage to keep cosmwasm clean (and allow a faster iteration cycle to start). Unless a good reason to embed it in cosmwasm (next to cosmwasm-vm)

Also, it would need to pull in some sample contracts (like dummy bank implementation) and cw-storage and I would not like to throw all of that into the cosmwasm repo. (Or yes, we throw everything there, but not some in, some out).

@webmaster128
Copy link
Member

@webmaster128 do you have any opinions here?

Right now it is entirely unclear to me how composition is supposed to work. For this reason I'm lost with the rest of this ticket. E.g. I don't understand why this is about tests when we don't have a bunch of happy path runtime compositions to look at. Maybe let's build up a strategy for composition first and document it.

@ethanfrey
Copy link
Member Author

I will add a doc before the code. But the idea is expressed by returning messages now (adding queries later). I think this is more or less documented, mainly it needs concrete examples. And I think tests are the best documentation of how things work code-level, which is why I focus on that here.

@ethanfrey
Copy link
Member Author

Not going to build a dispatcher as part of this repo. Maybe in another repo. Closing it

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

No branches or pull requests

2 participants