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

mock_env() contains invalid Address #2276

Closed
Buckram123 opened this issue Oct 7, 2024 · 5 comments
Closed

mock_env() contains invalid Address #2276

Buckram123 opened this issue Oct 7, 2024 · 5 comments

Comments

@Buckram123
Copy link
Contributor

MockApi after 2.0 expects valid bech32 address, so current implementation of mock_env() would fail address validation:

            address: Addr::unchecked("cosmos2contract"),

I would prefer to have valid address instead, for example

            address: MockApi::default().addr_make("cosmos2contract"),

Or more flexible with passing MockApi inside mock env function:

            address: mock_api.addr_make("cosmos2contract"),
@Buckram123
Copy link
Contributor Author

And is there a simpler way to get address prefix than from env.contract.address?

@chipshort
Copy link
Collaborator

            address: MockApi::default().addr_make("cosmos2contract"),

This will be fixed for mock_env in 2.2. See here: https://github.com/CosmWasm/cosmwasm/blob/v2.2.0-rc.1/CHANGELOG.md#L43-L45

The other part will be fixed in 3.0 by requiring an api parameter for mock_env: #2218

@chipshort chipshort closed this as not planned Won't fix, can't repro, duplicate, stale Oct 7, 2024
@chipshort
Copy link
Collaborator

And is there a simpler way to get address prefix than from env.contract.address?

The simplest way is to know what chain you deploy on and just use their prefix. Why do you need it at runtime?
Ideally, you would just write code that is agnostic of the underlying address scheme.

@Buckram123
Copy link
Contributor Author

Why do you need it at runtime?

To generate address from public key. Don't want to have different wasm for each chain I deploy

@chipshort
Copy link
Collaborator

Ah, I see. To avoid a different wasm per chain, you could also make it a parameter in the InstantiateMsg.

If you really really want it programmatically, you'd have to go through a Stargate / Grpc query. It has to be allowlisted by the chain, but most chains have pretty big allow lists. See neutron for example: https://docs.rs/neutron-std/latest/neutron_std/types/cosmos/auth/v1beta1/struct.AuthQuerier.html#method.bech32_prefix
But I don't think it's worth the hassle.

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