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

Improve wasm contract queries #22

Merged
merged 7 commits into from
Jan 15, 2020
Merged

Conversation

alpe
Copy link
Contributor

@alpe alpe commented Jan 13, 2020

Resolves #12

In this PR are the 3 different query types implemented as defined in #12. This includes server side and cli code.

Example:

wasmcli query wasm contract-state all "${CONTRACT}"
wasmcli query wasm contract-state raw  "${CONTRACT}" config --ascii
wasmcli query wasm contract-state smart "${CONTRACT}" '{"raw":{"key":"config"}}' --ascii

They all return:

[
  {
    "key": "config",
    "val": "{\"arbiter\":\"cosmos1s5k2p7nct27jzjrzvqgwy785wug0js9vdmdr5s\",\"recipient\":\"cosmos1p35xmxjl8ysxdp699ff4kmca8duwcve2jupxe3\",\"source\":\"cosmos1laapuw0u4vx3jjyq8vtf3pmzj24h3eqdfunyuk\",\"end_height\":0,\"end_time\":0}"
  }
]

For Admin Use:

  • Added appropriate labels to PR (ex. wip, ready-for-review, docs)
  • Reviewers Assigned
  • Squashed all commits, uses message "Merge PR #XYZ: [title]" (coding standards)

@codecov-io
Copy link

codecov-io commented Jan 13, 2020

Codecov Report

Merging #22 into master will increase coverage by 3.82%.
The diff coverage is 88.73%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #22      +/-   ##
==========================================
+ Coverage   56.48%   60.31%   +3.82%     
==========================================
  Files          11       11              
  Lines         979     1023      +44     
==========================================
+ Hits          553      617      +64     
+ Misses        375      351      -24     
- Partials       51       55       +4
Impacted Files Coverage Δ
x/wasm/internal/keeper/querier.go 26.96% <82.6%> (+26.96%) ⬆️
x/wasm/internal/keeper/keeper.go 62.65% <91.66%> (+9.54%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ce35d8d...6a76047. Read the comment docs.

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.

Quick comments on the draft to keep you on the right path

x/wasm/client/cli/query.go Outdated Show resolved Hide resolved
x/wasm/internal/keeper/querier.go Outdated Show resolved Hide resolved
@alpe alpe force-pushed the improve_contract_queries_12 branch from 249c7fe to 9156f29 Compare January 14, 2020 12:47
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.

Very nice.

I think a little more polish on the cli package, and it is good to merge.
Once you feel it is ready, please compile this and try out the last section of the tutorial with it, even using the standard escrow contract. To make sure at least raw and all state commands work in the cli (I don't think there are any automatic tests for that).

The smart queries, I will test via cli after merging in 0.6 support

x/wasm/client/cli/query.go Outdated Show resolved Hide resolved
x/wasm/client/cli/query.go Outdated Show resolved Hide resolved
x/wasm/internal/keeper/keeper.go Show resolved Hide resolved
x/wasm/internal/keeper/keeper.go Outdated Show resolved Hide resolved
x/wasm/internal/keeper/keeper.go Show resolved Hide resolved
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.

Nice update

@alpe alpe marked this pull request as ready for review January 14, 2020 16:20
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.

Very nice.

I have two comments on TestQueryContractState that I am unsure about the test cases. I would suggest adjusting them, and adjusting the code as needed to fit.

More "NotFound" errors, and no result on miss. But maybe you can explain why it is better how you coded it.

Rest of the code looks wonderful (this does to, I just think the logic is a bit off)

x/wasm/client/cli/query.go Show resolved Hide resolved
x/wasm/client/cli/query.go Show resolved Hide resolved
x/wasm/internal/keeper/keeper.go Show resolved Hide resolved
for iter := keeper.GetContractState(ctx, contractAddr); iter.Valid(); iter.Next() {
state = append(state, types.Model{
resultData = append(resultData, types.Model{
Copy link
Member

Choose a reason for hiding this comment

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

I like this

x/wasm/internal/keeper/querier_test.go Show resolved Hide resolved
x/wasm/internal/keeper/querier_test.go Show resolved Hide resolved
x/wasm/internal/keeper/querier_test.go Show resolved Hide resolved
srcPath: []string{QueryGetContractState, anyAddr.String(), QueryMethodContractStateAll},
expModelLen: 0,
},
"query smart with unknown 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 would assume all the "query with unknown address" would return the same types.ErrNotFound("contract") message

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree ErrNotFound would be nicer but the prefix.Store concatenates the prefix and key for the parent store so that it results in just another unknown key.
I would need to do a prefix scan on the parent to detect the issue. The previous implementation for all had the same "problem"

x/wasm/internal/keeper/querier_test.go Show resolved Hide resolved
expModelLen: 1,
//expModelContains: []model{}, // stopping here as contract internals are not stable
},
"query unknown raw key": {
Copy link
Member

Choose a reason for hiding this comment

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

Why doesn't this return an empty slice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was the simplest implementation but not necessarily the best. I was under the assumption that the KV store allows nil values so this result make sense but it does not.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe you are right, but I would rather let len(0) = deleted. Even if not strictly true, it gives contracts a way to mark things as deleted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a patch. And also returning non nil model slices.

@ethanfrey
Copy link
Member

Thanks for the cleanup. Looks great

@ethanfrey ethanfrey merged commit 09016ea into master Jan 15, 2020
@ethanfrey ethanfrey deleted the improve_contract_queries_12 branch January 15, 2020 10:53
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.

Improve query wasm contract-state CLI syntax
3 participants