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 DistributionQuery::DelegatorWithdrawAddress #442

Merged
merged 1 commit into from
Jul 3, 2023

Conversation

chipshort
Copy link
Collaborator

closes #436

Implements the query types for CosmWasm/cosmwasm#1593

Copy link
Member

@webmaster128 webmaster128 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

}

type DelegatorWithdrawAddressResponse struct {
WithdrawAddress string `json:"withdraw_address"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realize in cosmwasm (Rust) this should be Addr instead of String because we get a checked value from wasmd here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case we cannot have the Default derive for the DelegatorWithdrawAddressResponse and therefore also not the QueryResponseType impl. Is that alright? I think we need to add a constructor function then, if we want to mock it in multi-test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uff, yeah, this problem again. We hit the exact same case with ContractInfoResponse. In essence: in normale cases a contract never constructs this and just consumes it. Just for testing frameworks we need a constructor outside of cosmwasm-std which means we need to either have Default or give up #[non_exhaustive]. Having Default allows constructing invalid instances. I don't like this situation but don't have a solution.

Happy for any solution suggestion to this general problem but let's not block the release on it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose in this case we could just drop the non_exhaustive, as I do not think another field will be added to this response in particular.
I have some ideas on how to solve this in general:

  • keep separate Response structs in multi-test (as they only need to deserialize to the same), but then we have two separate ones, which is very annoying.
  • add a public function to create the response, but with #[doc(hidden)]. This has similar drawbacks as the Default impl, except that we can demand parameters and clearly mark it as not for "normal" usage.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second option means a non-stable constructor which I guess is fine. The other option between the two is a stable constructor which sets the newly added fields to some default value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, a non-stable constructor or default values if the added fields allow for one, but realistically non-stable constructor should be fine if we hide it and clearly document it to be non-stable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add those constructors for all query responses? Then we can remove Default here and make it Addr. I think we should favour the production use case over test framework convenience. And having a validated Addr save a call into the chain.

@webmaster128 webmaster128 merged commit 724041f into main Jul 3, 2023
1 check passed
@webmaster128 webmaster128 deleted the distribution-query branch July 3, 2023 19:47
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 this pull request may close these issues.

Add DistributionQuery::DelegatorWithdrawAddress types
2 participants