forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: small improvements (cosmos#13672)
* ci: update buf * add recommended vscode extension * update gh username * follow-up cosmos#13613 * add more sugestions * remove atlas github action
- Loading branch information
1 parent
f73e426
commit c303d7f
Showing
8 changed files
with
36 additions
and
81 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"recommendations": [ | ||
"golang.go", | ||
"bufbuild.vscode-buf", | ||
"davidanson.vscode-markdownlint" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,27 +58,18 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.46.0/x/bank/keeper/grpc_query.go | |
### Calling queries from the State Machine | ||
|
||
The Cosmos SDK v0.47 introduces a new `cosmos.query.v1.module_query_safe` Protobuf annotation which is used to state that a query that is safe to be called from within the state machine, for example: | ||
- a Keeper's query function can be called from another module's Keeper, | ||
- ADR-033 intermodule query calls, | ||
- CosmWasm contracts can also directly interact with these queries. | ||
|
||
If the `module_query_safe` annotation set to `true`, it means: | ||
- The query is deterministic: given a block height it will return the same response upon multiple calls, and doesn't introduce any state-machine breaking changes across SDK patch versions. | ||
- Gas consumption never fluctuates across calls and across patch versions. | ||
* a Keeper's query function can be called from another module's Keeper, | ||
* ADR-033 intermodule query calls, | ||
* CosmWasm contracts can also directly interact with these queries. | ||
|
||
If you are a module developer and want to use `module_query_safe` annotation for your own query, you have to ensure the following things: | ||
- the query is deterministic and won't introduce state-machine-breaking changes without coordinated upgrades | ||
- it has its gas tracked, to avoid the attack vector where no gas is accounted for | ||
on potentially high-computation queries. | ||
|
||
#### Deterministic and Regression tests | ||
If the `module_query_safe` annotation set to `true`, it means: | ||
|
||
Tests are written for queries in the Cosmos SDK which have `module_query_safe`. Each query is tested using 2 methods: | ||
- we use property-based testing using the [`rapid`](https://pkg.go.dev/pgregory.net/[email protected]) library. The property that is tested is that the query response and gas consumption are the same upon 1000 query calls. | ||
- we write regression tests with hardcoded responses and gas, and make sure they don't change upon 1000 calls and between SDK patch versions. | ||
* The query is deterministic: given a block height it will return the same response upon multiple calls, and doesn't introduce any state-machine breaking changes across SDK patch versions. | ||
* Gas consumption never fluctuates across calls and across patch versions. | ||
|
||
Here's an example of regression tests: | ||
If you are a module developer and want to use `module_query_safe` annotation for your own query, you have to ensure the following things: | ||
|
||
```go reference | ||
https://github.com/cosmos/cosmos-sdk/blob/9f3575a10f1a6f1315b94a9be783df5156ce2292/tests/integration/bank/keeper/deterministic_test.go#L102-L115 | ||
``` | ||
* the query is deterministic and won't introduce state-machine-breaking changes without coordinated upgrades | ||
* it has its gas tracked, to avoid the attack vector where no gas is accounted for | ||
on potentially high-computation queries. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,21 @@ Now the types are injected and we can use them for our tests: | |
https://github.com/cosmos/cosmos-sdk/blob/e09516f4795c637ab12b30bf732ce5d86da78424/tests/integration/distribution/keeper/keeper_test.go#L21-L53 | ||
``` | ||
|
||
## Deterministic and Regression tests | ||
|
||
Tests are written for queries in the Cosmos SDK which have `module_query_safe` Protobuf annotation. | ||
|
||
Each query is tested using 2 methods: | ||
|
||
* Use property-based testing with the [`rapid`](https://pkg.go.dev/pgregory.net/[email protected]) library. The property that is tested is that the query response and gas consumption are the same upon 1000 query calls. | ||
* Regression tests are written with hardcoded responses and gas, and verify they don't change upon 1000 calls and between SDK patch versions. | ||
|
||
Here's an example of regression tests: | ||
|
||
```go reference | ||
https://github.com/cosmos/cosmos-sdk/blob/9f3575a10f1a6f1315b94a9be783df5156ce2292/tests/integration/bank/keeper/deterministic_test.go#L102-L115 | ||
``` | ||
|
||
## Simulations | ||
|
||
Simulations uses as well a minimal application, built with [`depinject`](../building-apps/01-depinject.md): | ||
|