Skip to content

Commit f2cc377

Browse files
authored
docs: Add otter state generation doc (#21798)
Signed-off-by: Kelly Greco <kelly@swirldslabs.com>
1 parent ec3fb55 commit f2cc377

File tree

3 files changed

+79
-8
lines changed

3 files changed

+79
-8
lines changed

platform-sdk/consensus-otter-tests/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ platform-sdk/consensus-otter-tests/
6565

6666
## 📚 Documentation
6767

68-
| Guide | Description |
69-
|-----------------------------------------------------------|---------------------------|
70-
| [🏁 Getting Started](docs/getting-started.md) | Setup and your first test |
71-
| [🏛️ Architecture](docs/architecture.md) | Framework design overview |
72-
| [✍️ Writing Tests](docs/writing-tests.md) | Test development guide |
73-
| [🐢 Turtle Environment](docs/turtle-environment.md) | Simulated testing guide |
74-
| [🐳 Container Environment](docs/container-environment.md) | Docker-based testing |
68+
| Guide | Description |
69+
|---------------------------------------------------------------|---------------------------------|
70+
| [🏁 Getting Started](docs/getting-started.md) | Setup and your first test |
71+
| [🏛️ Architecture](docs/architecture.md) | Framework design overview |
72+
| [✍️ Writing Tests](docs/writing-tests.md) | Test development guide |
73+
| [🐢 Turtle Environment](docs/turtle-environment.md) | Simulated testing guide |
74+
| [🐳 Container Environment](docs/container-environment.md) | Docker-based testing |
75+
| [💾 Generating Saved States](docs/generating-saved-states.md) | Creating initial network states |

platform-sdk/consensus-otter-tests/docs/container-environment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ docker inspect <container_name>
462462
### 4. Attaching a Debugger
463463

464464
To attach a debugger to a running container, first identify the node ID of the node you want to attach to. The debug
465-
port for the container running the consensus node is `5005` plus the node ID (`5005` for node 0, `5006` for node 1,
465+
port for the container running the consensus node is `6005` plus the node ID (`6005` for node 0, `6006` for node 1,
466466
etc.). These debug ports are automatically configured in the consensus node containers. Please note that you cannot
467467
attach the debugger until the node has been started. For repeatable tests, you can set the seed that determines the node
468468
IDs using the `OtterSpecs` annotation and setting the `randomNodeIds` field to `false`:
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Generating Saved States for Otter Tests
2+
3+
## Overview
4+
5+
Saved states allow tests to bootstrap from a previously generated network state rather than starting from genesis. This is useful for migration testing and scenarios where you want to start from a specific network configuration.
6+
7+
## Generating a State
8+
9+
Use the `GenerateStateTool` command-line tool to create a new saved state:
10+
11+
```bash
12+
./gradlew :consensus-otter-tests:run --args="org.hiero.otter.fixtures.tools.GenerateStateTool"
13+
```
14+
15+
This tool:
16+
1. Creates a 4-node network using a deterministic seed
17+
2. Runs the network for 10 seconds
18+
3. Freezes the network to create a consistent snapshot
19+
4. Cleans up unnecessary files (keeping only the latest round and PCES directory)
20+
5. Moves the state to `platform-sdk/consensus-otter-tests/saved-states/previous-version-state`
21+
22+
The generated state is a **freeze state**, making it safe for:
23+
- Migration tests that load a state from a previous software version
24+
- Tests that make roster changes (node additions/removals)
25+
- Any test requiring a known starting state with existing rounds
26+
27+
## Using a Saved State in Tests
28+
29+
Reference the saved state directory in your test:
30+
31+
```java
32+
@OtterTest
33+
@OtterSpecs(randomNodeIds = false)
34+
void myTest(@NonNull final TestEnvironment env) {
35+
final Network network = env.network();
36+
37+
network.addNodes(numberOfNodes);
38+
network.savedStateDirectory(Path.of("previous-version-state"));
39+
network.version(targetVersion);
40+
network.start();
41+
42+
// ... test assertions
43+
}
44+
```
45+
46+
The network automatically handles:
47+
- Loading the saved state from `saved-states/previous-version-state`
48+
- Synchronizing FakeTime to the state's WALL_CLOCK_TIME + 1 hour if running in the Turtle environment to ensure time does not go backwards
49+
- Managing roster changes if the test uses different node counts
50+
51+
## Git Management
52+
53+
The `.gitignore` at the repository root ignores all `.swh` files:
54+
55+
```
56+
*.swh
57+
```
58+
59+
After generating a new state, **manually `git add` the `.swh` file** to include it in version control:
60+
61+
```bash
62+
cd platform-sdk/consensus-otter-tests/saved-states/previous-version-state
63+
git add -f OtterApp/0/hiero/*/SignedState.swh
64+
```
65+
66+
The `-f` flag is required because the file matches the gitignore pattern.
67+
68+
## Migration Testing
69+
70+
> TODO: Document migration testing workflow when we have tests that load states generated from previous software versions. Include version handling and any specific considerations for testing state format compatibility.

0 commit comments

Comments
 (0)