Skip to content

Commit e291955

Browse files
Integration tests ergonomics (#7836)
Fixes #7785 - [x] Update all integration tests with >1 files to follow the `main` pattern. - [x] `crypto/eth2_key_derivation/tests` - [x] `crypto/eth2_keystore/tests` - [x] `crypto/eth2_wallet/tests` - [x] `slasher/tests` - [x] `common/eth2_interop_keypairs/tests` - [x] `beacon_node/lighthouse_network/tests` - [x] Set `debug_assertions` to false on `.vscode/settings.json`. - [x] Document how to make rust analyzer work on integration tests files. In `book/src/contributing_setup.md` --- Tracking a `rust-analyzer.toml` with settings like the one provided in `.vscode/settings.json` would be nicer. But this is not possible yet. For now, that config should be a good enough indicator for devs using editors different to VSCode. Co-Authored-By: Daniel Ramirez-Chiquillo <hi@danielrachi.com> Co-Authored-By: Michael Sproul <michael@sigmaprime.io>
1 parent 070e395 commit e291955

File tree

16 files changed

+98
-3
lines changed

16 files changed

+98
-3
lines changed

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"rust-analyzer.cargo.cfgs": [
3+
"!debug_assertions"
4+
]
5+
}

beacon_node/lighthouse_network/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "lighthouse_network"
33
version = "0.2.0"
44
authors = ["Sigma Prime <contact@sigmaprime.io>"]
55
edition = { workspace = true }
6+
autotests = false
67

78
[features]
89
libp2p-websocket = []
@@ -74,3 +75,7 @@ async-channel = { workspace = true }
7475
logging = { workspace = true }
7576
proptest = { workspace = true }
7677
tempfile = { workspace = true }
78+
79+
[[test]]
80+
name = "lighthouse_network_tests"
81+
path = "tests/main.rs"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mod common;
2+
mod rpc_tests;

beacon_node/lighthouse_network/tests/rpc_tests.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#![cfg(test)]
22

3-
mod common;
4-
3+
use crate::common;
54
use crate::common::spec_with_all_forks_enabled;
6-
use common::{Protocol, build_tracing_subscriber};
5+
use crate::common::{Protocol, build_tracing_subscriber};
76
use lighthouse_network::rpc::{RequestType, methods::*};
87
use lighthouse_network::service::api_types::AppRequestId;
98
use lighthouse_network::{NetworkEvent, ReportSource, Response};

book/src/contributing_setup.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,47 @@ $ cargo nextest run -p safe_arith
7171
Summary [ 0.012s] 8 tests run: 8 passed, 0 skipped
7272
```
7373

74+
### Integration tests
75+
76+
Due to the size and complexity of the test suite, Lighthouse uses a pattern that differs from how
77+
[integration tests are usually defined](https://doc.rust-lang.org/rust-by-example/testing/integration_testing.html).
78+
This pattern helps manage large test suites more effectively and ensures tests only run in release
79+
mode to avoid stack overflow issues.
80+
81+
#### The "main pattern"
82+
83+
For packages with integration tests that require more than one file, Lighthouse uses the following
84+
structure:
85+
86+
- A `main.rs` file is defined at `package/tests/main.rs` that declares other test files as modules
87+
- In `package/Cargo.toml`, integration tests are explicitly configured:
88+
89+
```toml
90+
[package]
91+
autotests = false
92+
93+
[[test]]
94+
name = "package_tests"
95+
path = "tests/main.rs"
96+
```
97+
98+
#### Rust Analyzer configuration
99+
100+
This pattern, combined with `#![cfg(not(debug_assertions))]` directives in test files (which
101+
prevent tests from running in debug mode), causes Rust Analyzer to not provide IDE services like
102+
autocomplete and error checking in integration test files by default.
103+
104+
To enable IDE support for these test files, configure Rust Analyzer to disable debug assertions.
105+
For VSCode users, this is already configured in the repository's `.vscode/settings.json` file:
106+
107+
```json
108+
{
109+
"rust-analyzer.cargo.cfgs": [
110+
"!debug_assertions"
111+
]
112+
}
113+
```
114+
74115
### test_logger
75116

76117
The test_logger, located in `/common/logging/` can be used to create a `Logger` that by

common/eth2_interop_keypairs/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "eth2_interop_keypairs"
33
version = "0.2.0"
44
authors = ["Paul Hauner <paul@paulhauner.com>"]
55
edition = { workspace = true }
6+
autotests = false
67
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
78

89
[dependencies]
@@ -15,3 +16,7 @@ serde_yaml = { workspace = true }
1516

1617
[dev-dependencies]
1718
base64 = "0.13.0"
19+
20+
[[test]]
21+
name = "eth2_interop_keypairs_tests"
22+
path = "tests/main.rs"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mod from_file;
2+
mod generation;

crypto/eth2_key_derivation/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "eth2_key_derivation"
33
version = "0.1.0"
44
authors = ["Paul Hauner <paul@paulhauner.com>"]
55
edition = { workspace = true }
6+
autotests = false
67
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
78

89
[dependencies]
@@ -14,3 +15,7 @@ zeroize = { workspace = true }
1415

1516
[dev-dependencies]
1617
hex = { workspace = true }
18+
19+
[[test]]
20+
name = "eth2_key_derivation_tests"
21+
path = "tests/main.rs"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mod eip2333_vectors;
2+
mod tests;

crypto/eth2_keystore/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "eth2_keystore"
33
version = "0.1.0"
44
authors = ["Pawan Dhananjay <pawan@sigmaprime.io", "Paul Hauner <paul@paulhauner.com>"]
55
edition = { workspace = true }
6+
autotests = false
67
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
78

89
[dependencies]
@@ -24,3 +25,7 @@ zeroize = { workspace = true }
2425

2526
[dev-dependencies]
2627
tempfile = { workspace = true }
28+
29+
[[test]]
30+
name = "eth2_keystore_tests"
31+
path = "tests/main.rs"

0 commit comments

Comments
 (0)