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>
This commit is contained in:
Daniel
2025-11-27 00:53:57 -05:00
committed by GitHub
parent 070e395714
commit e291955400
16 changed files with 98 additions and 3 deletions

5
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,5 @@
{
"rust-analyzer.cargo.cfgs": [
"!debug_assertions"
]
}

View File

@@ -3,6 +3,7 @@ name = "lighthouse_network"
version = "0.2.0"
authors = ["Sigma Prime <contact@sigmaprime.io>"]
edition = { workspace = true }
autotests = false
[features]
libp2p-websocket = []
@@ -74,3 +75,7 @@ async-channel = { workspace = true }
logging = { workspace = true }
proptest = { workspace = true }
tempfile = { workspace = true }
[[test]]
name = "lighthouse_network_tests"
path = "tests/main.rs"

View File

@@ -0,0 +1,2 @@
mod common;
mod rpc_tests;

View File

@@ -1,9 +1,8 @@
#![cfg(test)]
mod common;
use crate::common;
use crate::common::spec_with_all_forks_enabled;
use common::{Protocol, build_tracing_subscriber};
use crate::common::{Protocol, build_tracing_subscriber};
use lighthouse_network::rpc::{RequestType, methods::*};
use lighthouse_network::service::api_types::AppRequestId;
use lighthouse_network::{NetworkEvent, ReportSource, Response};

View File

@@ -71,6 +71,47 @@ $ cargo nextest run -p safe_arith
Summary [ 0.012s] 8 tests run: 8 passed, 0 skipped
```
### Integration tests
Due to the size and complexity of the test suite, Lighthouse uses a pattern that differs from how
[integration tests are usually defined](https://doc.rust-lang.org/rust-by-example/testing/integration_testing.html).
This pattern helps manage large test suites more effectively and ensures tests only run in release
mode to avoid stack overflow issues.
#### The "main pattern"
For packages with integration tests that require more than one file, Lighthouse uses the following
structure:
- A `main.rs` file is defined at `package/tests/main.rs` that declares other test files as modules
- In `package/Cargo.toml`, integration tests are explicitly configured:
```toml
[package]
autotests = false
[[test]]
name = "package_tests"
path = "tests/main.rs"
```
#### Rust Analyzer configuration
This pattern, combined with `#![cfg(not(debug_assertions))]` directives in test files (which
prevent tests from running in debug mode), causes Rust Analyzer to not provide IDE services like
autocomplete and error checking in integration test files by default.
To enable IDE support for these test files, configure Rust Analyzer to disable debug assertions.
For VSCode users, this is already configured in the repository's `.vscode/settings.json` file:
```json
{
"rust-analyzer.cargo.cfgs": [
"!debug_assertions"
]
}
```
### test_logger
The test_logger, located in `/common/logging/` can be used to create a `Logger` that by

View File

@@ -3,6 +3,7 @@ name = "eth2_interop_keypairs"
version = "0.2.0"
authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = { workspace = true }
autotests = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
@@ -15,3 +16,7 @@ serde_yaml = { workspace = true }
[dev-dependencies]
base64 = "0.13.0"
[[test]]
name = "eth2_interop_keypairs_tests"
path = "tests/main.rs"

View File

@@ -0,0 +1,2 @@
mod from_file;
mod generation;

View File

@@ -3,6 +3,7 @@ name = "eth2_key_derivation"
version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = { workspace = true }
autotests = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
@@ -14,3 +15,7 @@ zeroize = { workspace = true }
[dev-dependencies]
hex = { workspace = true }
[[test]]
name = "eth2_key_derivation_tests"
path = "tests/main.rs"

View File

@@ -0,0 +1,2 @@
mod eip2333_vectors;
mod tests;

View File

@@ -3,6 +3,7 @@ name = "eth2_keystore"
version = "0.1.0"
authors = ["Pawan Dhananjay <pawan@sigmaprime.io", "Paul Hauner <paul@paulhauner.com>"]
edition = { workspace = true }
autotests = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
@@ -24,3 +25,7 @@ zeroize = { workspace = true }
[dev-dependencies]
tempfile = { workspace = true }
[[test]]
name = "eth2_keystore_tests"
path = "tests/main.rs"

View File

@@ -0,0 +1,4 @@
mod eip2335_vectors;
mod json;
mod params;
mod tests;

View File

@@ -3,6 +3,7 @@ name = "eth2_wallet"
version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = { workspace = true }
autotests = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
@@ -18,3 +19,7 @@ uuid = { workspace = true }
[dev-dependencies]
hex = { workspace = true }
tempfile = { workspace = true }
[[test]]
name = "eth2_wallet_tests"
path = "tests/main.rs"

View File

@@ -0,0 +1,3 @@
mod eip2386_vectors;
mod json;
mod tests;

View File

@@ -3,6 +3,7 @@ name = "slasher"
version = "0.1.0"
authors = ["Michael Sproul <michael@sigmaprime.io>"]
edition = { workspace = true }
autotests = false
[features]
default = ["lmdb"]
@@ -43,3 +44,7 @@ types = { workspace = true }
maplit = { workspace = true }
rayon = { workspace = true }
tempfile = { workspace = true }
[[test]]
name = "slasher_tests"
path = "tests/main.rs"

5
slasher/tests/main.rs Normal file
View File

@@ -0,0 +1,5 @@
mod attester_slashings;
mod backend;
mod proposer_slashings;
mod random;
mod wrap_around;

View File

@@ -2,6 +2,7 @@ allocator
APIs
ARMv
AUR
autocomplete
Backends
Backfilling
Beaconcha
@@ -110,6 +111,7 @@ Validator
VC
VCs
VPN
VSCode
WalletConnect
Withdrawable
WSL