-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into tip/handlers_continuation
- Loading branch information
Showing
10 changed files
with
168 additions
and
43 deletions.
There are no files selected for viewing
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
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,50 @@ | ||
# CheckTx | ||
|
||
CheckTx is called by the `BaseApp` when comet receives a transaction from a client, over the p2p network or RPC. The CheckTx method is responsible for validating the transaction and returning an error if the transaction is invalid. | ||
|
||
```mermaid | ||
graph TD | ||
subgraph SDK[Cosmos SDK] | ||
B[Baseapp] | ||
A[AnteHandlers] | ||
B <-->|Validate TX| A | ||
end | ||
C[CometBFT] <-->|CheckTx|SDK | ||
U((User)) -->|Submit TX| C | ||
N[P2P] -->|Receive TX| C | ||
``` | ||
|
||
```go reference | ||
https://github.com/cosmos/cosmos-sdk/blob/31c604762a434c7b676b6a89897ecbd7c4653a23/baseapp/abci.go#L350-L390 | ||
``` | ||
|
||
## CheckTx Handler | ||
|
||
`CheckTxHandler` allows users to extend the logic of `CheckTx`. `CheckTxHandler` is called by pasding context and the transaction bytes received through ABCI. It is required that the handler returns deterministic results given the same transaction bytes. | ||
|
||
:::note | ||
we return the raw decoded transaction here to avoid decoding it twice. | ||
::: | ||
|
||
```go | ||
type CheckTxHandler func(ctx sdk.Context, tx []byte) (Tx, error) | ||
``` | ||
|
||
Setting a custom `CheckTxHandler` is optional. It can be done from your app.go file: | ||
|
||
```go | ||
func NewSimApp( | ||
logger log.Logger, | ||
db corestore.KVStoreWithBatch, | ||
traceStore io.Writer, | ||
loadLatest bool, | ||
appOpts servertypes.AppOptions, | ||
baseAppOptions ...func(*baseapp.BaseApp), | ||
) *SimApp { | ||
... | ||
// Create ChecktxHandler | ||
checktxHandler := abci.NewCustomCheckTxHandler(...) | ||
app.SetCheckTxHandler(checktxHandler) | ||
... | ||
} | ||
``` |
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,58 @@ | ||
--- | ||
sidebar_position: 1 | ||
--- | ||
|
||
# System Tests | ||
|
||
System tests provide a framework to write and execute black box tests against a running chain. This adds another level | ||
of confidence on top of unit, integration, and simulations tests, ensuring that business-critical scenarios | ||
(like double signing prevention) or scenarios that can't be tested otherwise (like a chain upgrade) are covered. | ||
|
||
## Vanilla Go for Flow Control | ||
|
||
System tests are vanilla Go tests that interact with the compiled chain binary. The `test runner` component starts a | ||
local testnet of 4 nodes (by default) and provides convenient helper methods for accessing the | ||
`system under test (SUT)`. | ||
A `CLI wrapper` makes it easy to access keys, submit transactions, or execute operations. Together, these components | ||
enable the replication and validation of complex business scenarios. | ||
|
||
Here's an example of a double signing test, where a new node is added with the same key as the first validator: | ||
[double signing test example](https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/tests/systemtests/fraud_test.go) | ||
|
||
The [getting started tutorial](https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/tests/systemtests/getting_started.md) | ||
contains a step-by-step guide to building and running your first system test. It covers setting chain state via genesis | ||
or | ||
transactions and validation via transaction response or queries. | ||
|
||
## Design Principles and Guidelines | ||
|
||
System tests are slower compared to unit or integration tests as they interact with a running chain. Therefore, certain | ||
principles can guide their usage: | ||
|
||
- **Perspective:** Tests should mimic a human interacting with the chain from the outside. Initial states can be set via | ||
genesis or transactions to support a test scenario. | ||
- **Roles:** The user can have multiple roles such as validator, delegator, granter, or group admin. | ||
- **Focus:** Tests should concentrate on happy paths or business-critical workflows. Unit and integration tests are | ||
better suited for more fine-grained testing. | ||
- **Workflows:** Test workflows and scenarios, not individual units. Given the high setup costs, it is reasonable to | ||
combine multiple steps and assertions in a single test method. | ||
- **Genesis Mods:** Genesis modifications can incur additional time costs for resetting dirty states. Reuse existing | ||
accounts (node0..n) whenever possible. | ||
- **Framework:** Continuously improve the framework for better readability and reusability. | ||
|
||
## Errors and Debugging | ||
|
||
All output is logged to `systemtests/testnet/node{0..n}.out`. Usually, `node0.out` is very noisy as it receives the CLI | ||
connections. Prefer any other node's log to find stack traces or error messages. | ||
|
||
Using system tests for state setup during debugging has become very handy: | ||
|
||
- Start the test with one node only and verbose output: | ||
|
||
```sh | ||
go test -v -tags=system_test ./ --run TestAccountCreation --verbose --nodes-count=1 | ||
``` | ||
|
||
- Copy the CLI command for the transaction and modify the test to stop before the command | ||
- Start the node with `--home=<project-home>/tests/systemtests/testnet/node0/<binary-name>/` in debug mode | ||
- Execute CLI command from shell and enter breakpoints |
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