mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-02 16:21:42 +00:00
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:
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"rust-analyzer.cargo.cfgs": [
|
||||
"!debug_assertions"
|
||||
]
|
||||
}
|
||||
@@ -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"
|
||||
|
||||
2
beacon_node/lighthouse_network/tests/main.rs
Normal file
2
beacon_node/lighthouse_network/tests/main.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
mod common;
|
||||
mod rpc_tests;
|
||||
@@ -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};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
2
common/eth2_interop_keypairs/tests/main.rs
Normal file
2
common/eth2_interop_keypairs/tests/main.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
mod from_file;
|
||||
mod generation;
|
||||
@@ -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"
|
||||
|
||||
2
crypto/eth2_key_derivation/tests/main.rs
Normal file
2
crypto/eth2_key_derivation/tests/main.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
mod eip2333_vectors;
|
||||
mod tests;
|
||||
@@ -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"
|
||||
|
||||
4
crypto/eth2_keystore/tests/main.rs
Normal file
4
crypto/eth2_keystore/tests/main.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
mod eip2335_vectors;
|
||||
mod json;
|
||||
mod params;
|
||||
mod tests;
|
||||
@@ -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"
|
||||
|
||||
3
crypto/eth2_wallet/tests/main.rs
Normal file
3
crypto/eth2_wallet/tests/main.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
mod eip2386_vectors;
|
||||
mod json;
|
||||
mod tests;
|
||||
@@ -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
5
slasher/tests/main.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
mod attester_slashings;
|
||||
mod backend;
|
||||
mod proposer_slashings;
|
||||
mod random;
|
||||
mod wrap_around;
|
||||
@@ -2,6 +2,7 @@ allocator
|
||||
APIs
|
||||
ARMv
|
||||
AUR
|
||||
autocomplete
|
||||
Backends
|
||||
Backfilling
|
||||
Beaconcha
|
||||
@@ -110,6 +111,7 @@ Validator
|
||||
VC
|
||||
VCs
|
||||
VPN
|
||||
VSCode
|
||||
WalletConnect
|
||||
Withdrawable
|
||||
WSL
|
||||
|
||||
Reference in New Issue
Block a user