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

Responses validation in multi-test #373

Merged
merged 1 commit into from
Aug 3, 2021
Merged

Conversation

hashedone
Copy link
Contributor

closes #341

I don't like checking the errors in test by comparing strings - I would really prefer to switch to proper error types (we have thiserror anyway), and if needed converting them to string at the end. If for simplicity we want to unify error types, then we could just go with handling them with anyhow so if needed, error types can be retrieved by downcasting.

@hashedone hashedone force-pushed the 341-returned-items-validity branch from b3c59f5 to c2fb2e5 Compare August 3, 2021 12:10
Copy link
Member

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

Looks good.

I would remove the events echo in reply and add some trim spaces to the length checks. Then good to merge

@@ -720,6 +724,43 @@ where
let storage = ReadonlyPrefixedStorage::multilevel(storage, &[NAMESPACE_WASM, &namespace]);
Box::new(storage)
}

fn verify_attributes(attributes: &[Attribute]) -> Result<(), String> {
Copy link
Member

Choose a reason for hiding this comment

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

Looks good

@@ -268,6 +268,10 @@ where
funds,
label,
} => {
if label.is_empty() {
Copy link
Member

Choose a reason for hiding this comment

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

👍

}),
..
} = msg
{
Ok(Response::new().set_data(data))
Ok(Response::new().set_data(data).add_events(events))
Copy link
Member

Choose a reason for hiding this comment

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

I would actually not add these to the reply call. These should be appended by the runtime when there is a SubMsg executed without the reply blob doing anything


fn verify_attributes(attributes: &[Attribute]) -> Result<(), String> {
for attr in attributes {
if attr.key.is_empty() {
Copy link
Member

Choose a reason for hiding this comment

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

Note in the real wasmd implementation, we trim off whitespace from the ends before checking empty, so " " is also invalid.

The relevant Go code changes are are https://github.com/CosmWasm/wasmd/pull/562/files maybe you can use them as reference

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missed it, corrected.


for event in &response.events {
Self::verify_attributes(&event.attributes)?;
if event.ty.len() < 2 {
Copy link
Member

Choose a reason for hiding this comment

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

Same thing, I think we trim whitespace before checking length

@hashedone hashedone force-pushed the 341-returned-items-validity branch from c2fb2e5 to 4fbb283 Compare August 3, 2021 14:52
Copy link
Member

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

lgtm

@ethanfrey ethanfrey merged commit 9c17aa9 into main Aug 3, 2021
@ethanfrey ethanfrey deleted the 341-returned-items-validity branch August 3, 2021 19:49
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.

multitest: Enforce validity checks for returned items
2 participants