Skip to content

Commit 5c4f4ac

Browse files
authored
docs: Add initial doc for system tests (#22002)
1 parent 0ea2445 commit 5c4f4ac

File tree

2 files changed

+67
-21
lines changed

2 files changed

+67
-21
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
sidebar_position: 1
3+
---
4+
5+
# System Tests
6+
7+
System tests provide a framework to write and execute black box tests against a running chain. This adds another level
8+
of confidence on top of unit, integration, and simulations tests, ensuring that business-critical scenarios
9+
(like double signing prevention) or scenarios that can't be tested otherwise (like a chain upgrade) are covered.
10+
11+
## Vanilla Go for Flow Control
12+
13+
System tests are vanilla Go tests that interact with the compiled chain binary. The `test runner` component starts a
14+
local testnet of 4 nodes (by default) and provides convenient helper methods for accessing the
15+
`system under test (SUT)`.
16+
A `CLI wrapper` makes it easy to access keys, submit transactions, or execute operations. Together, these components
17+
enable the replication and validation of complex business scenarios.
18+
19+
Here's an example of a double signing test, where a new node is added with the same key as the first validator:
20+
[double signing test example](https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/tests/systemtests/fraud_test.go)
21+
22+
The [getting started tutorial](https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/tests/systemtests/getting_started.md)
23+
contains a step-by-step guide to building and running your first system test. It covers setting chain state via genesis
24+
or
25+
transactions and validation via transaction response or queries.
26+
27+
## Design Principles and Guidelines
28+
29+
System tests are slower compared to unit or integration tests as they interact with a running chain. Therefore, certain
30+
principles can guide their usage:
31+
32+
- **Perspective:** Tests should mimic a human interacting with the chain from the outside. Initial states can be set via
33+
genesis or transactions to support a test scenario.
34+
- **Roles:** The user can have multiple roles such as validator, delegator, granter, or group admin.
35+
- **Focus:** Tests should concentrate on happy paths or business-critical workflows. Unit and integration tests are
36+
better suited for more fine-grained testing.
37+
- **Workflows:** Test workflows and scenarios, not individual units. Given the high setup costs, it is reasonable to
38+
combine multiple steps and assertions in a single test method.
39+
- **Genesis Mods:** Genesis modifications can incur additional time costs for resetting dirty states. Reuse existing
40+
accounts (node0..n) whenever possible.
41+
- **Framework:** Continuously improve the framework for better readability and reusability.
42+
43+
## Errors and Debugging
44+
45+
All output is logged to `systemtests/testnet/node{0..n}.out`. Usually, `node0.out` is very noisy as it receives the CLI
46+
connections. Prefer any other node's log to find stack traces or error messages.
47+
48+
Using system tests for state setup during debugging has become very handy:
49+
50+
- Start the test with one node only and verbose output:
51+
52+
```sh
53+
go test -v -tags=system_test ./ --run TestAccountCreation --verbose --nodes-count=1
54+
```
55+
56+
- Copy the CLI command for the transaction and modify the test to stop before the command
57+
- Start the node with `--home=<project-home>/tests/systemtests/testnet/node0/<binary-name>/` in debug mode
58+
- Execute CLI command from shell and enter breakpoints

docs/build/building-modules/16-testing.md

+9-21
Original file line numberDiff line numberDiff line change
@@ -86,38 +86,26 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/tests/integration/bank
8686

8787
## Simulations
8888

89-
Simulations uses as well a minimal application, built with [`depinject`](../packages/01-depinject.md):
89+
Simulations fuzz tests for deterministic message execution. They use a minimal application, built with [`depinject`](../packages/01-depinject.md):
9090

9191
:::note
92-
You can as well use the `AppConfig` `configurator` for creating an `AppConfig` [inline](https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/x/slashing/app_test.go#L54-L62). There is no difference between those two ways, use whichever you prefer.
92+
Simulations have been refactored to message factories
9393
:::
9494

95-
Following is an example for `x/gov/` simulations:
95+
An example for `x/bank/` simulations:
9696

9797
```go reference
98-
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/x/gov/simulation/operations_test.go#L406-L430
98+
https://github.com/cosmos/cosmos-sdk/blob/release/v0.52.x/x/bank/simulation/msg_factory.go#L13-L20
9999
```
100100

101-
```go reference
102-
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/x/gov/simulation/operations_test.go#L90-L132
103-
```
104-
105-
## End-to-end Tests
101+
## System Tests
106102

107-
End-to-end tests are at the top of the [test pyramid](https://martinfowler.com/articles/practical-test-pyramid.html).
108-
They must test the whole application flow, from the user perspective (for instance, CLI tests). They are located under [`/tests/e2e`](https://github.com/cosmos/cosmos-sdk/tree/main/tests/e2e).
103+
System tests are at the top of the [test pyramid](https://martinfowler.com/articles/practical-test-pyramid.html).
104+
They test the whole application flow as black box, from the user perspective. They are located under [`/tests/systemtests`](https://github.com/cosmos/cosmos-sdk/tree/main/tests/systemtests).
109105

110-
<!-- @julienrbrt: makes more sense to use an app wired app to have 0 simapp dependencies -->
111-
For that, the SDK is using `simapp` but you should use your own application (`appd`).
112-
Here are some examples:
106+
For that, the SDK is using the `simapp` binary, but you should use your own binary.
107+
More details about system test can be found in [building-apps](https://docs.cosmos.network/main/build/building-apps/06-system-tests.md)
113108

114-
* SDK E2E tests: <https://github.com/cosmos/cosmos-sdk/tree/main/tests/e2e>.
115-
* Cosmos Hub E2E tests: <https://github.com/cosmos/gaia/tree/main/tests/e2e>.
116-
* Osmosis E2E tests: <https://github.com/osmosis-labs/osmosis/tree/main/tests/e2e>.
117-
118-
:::note warning
119-
The SDK is in the process of creating its E2E tests, as defined in [ADR-59](https://docs.cosmos.network/main/build/architecture/adr-059-test-scopes). This page will eventually be updated with better examples.
120-
:::
121109

122110
## Learn More
123111

0 commit comments

Comments
 (0)