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 MockApi::addr_make #1887

Closed
webmaster128 opened this issue Sep 26, 2023 · 3 comments · Fixed by #1905
Closed

Add MockApi::addr_make #1887

webmaster128 opened this issue Sep 26, 2023 · 3 comments · Fixed by #1905
Assignees
Milestone

Comments

@webmaster128
Copy link
Member

webmaster128 commented Sep 26, 2023

Create a function that allows creating test addresses from arbitrary strings. As discussed in #1873.

E.g. in test code

let manager: Addr = api.addr_make("manager");
let user1: Addr = api.addr_make("Alice");
let user2: Addr = api.addr_make("Bob");
@DariuszDepta
Copy link
Member

Just to confirm, because different name is in the title and in examples. Do we stick to the convention in Api and name it addr_make?

Additionally, in cosmwasm-vm::testing there is also MockApi defined. Do we need to add the same function also there?

@chipshort
Copy link
Collaborator

I talked about this with @webmaster128 a few minutes ago.
Ideally we would only add it on the MockApi, not the trait. That would prevent people from misusing it in contract code.
The only thing that might pose a problem is if e.g. multi-test passes the MockApi as &dyn Api somewhere to test code. Then you would not have access to the function.
If that's the case, we can add it to the trait with a default unimplemented!() impl and implement it for the MockApi.
If not, I prefer the first option.

@webmaster128
Copy link
Member Author

Thanks. I updated the example to use the same name as the title. My motivation for the name is:

  • Include addr as it creates an Addr
  • Use it as a prefix similar to addr_humanize and addr_validate but If it is not in the trait, I don't have a strong opinion here
  • Prefer "make" or "new" over "hash" because hashing is an implementation detail. We can also implement it as a lookup table. The user should not worry about how to get from their describer string to the actual address

But feel free to disagree with those points and wer find the best name.

Additionally, in cosmwasm-vm::testing there is also MockApi defined. Do we need to add the same function also there?

Good questions. This belongs to a related but different trait BackendApi. We can skip it for now and if we see the need, copy it over.

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 a pull request may close this issue.

3 participants