diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml index 98ef2d38d4..413dd2b95d 100644 --- a/.github/workflows/test-suite.yml +++ b/.github/workflows/test-suite.yml @@ -247,61 +247,8 @@ jobs: with: channel: stable cache-target: release -<<<<<<< HEAD - - name: Install Foundry (anvil) - uses: foundry-rs/foundry-toolchain@v1 - with: - version: nightly-ca67d15f4abd46394b324c50e21e66f306a1162d - - name: Run the beacon chain sim and go through the merge transition - run: cargo run --release --bin simulator eth1-sim --post-merge - no-eth1-simulator-ubuntu: - name: no-eth1-simulator-ubuntu - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Get latest version of stable Rust - uses: moonrepo/setup-rust@v1 - with: - channel: stable - cache-target: release - - name: Run the beacon chain sim without an eth1 connection - run: cargo run --release --bin simulator no-eth1-sim - fallback-simulator-ubuntu: - name: fallback-simulator-ubuntu - runs-on: ubuntu-latest - needs: cargo-fmt - steps: - - uses: actions/checkout@v3 - - name: Get latest version of stable Rust - run: rustup update stable - - name: Install Protoc - uses: arduino/setup-protoc@e52d9eb8f7b63115df1ac544a1376fdbf5a39612 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - - name: Install Foundry (anvil) - uses: foundry-rs/foundry-toolchain@v1 - - name: Run the fallback simulator - run: cargo run --release --bin simulator fallback-sim - syncing-simulator-ubuntu: - name: syncing-simulator-ubuntu - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Get latest version of stable Rust - uses: moonrepo/setup-rust@v1 - with: - channel: stable - cache-target: release - - name: Install Foundry (anvil) - uses: foundry-rs/foundry-toolchain@v1 - with: - version: nightly-ca67d15f4abd46394b324c50e21e66f306a1162d - - name: Run the syncing simulator - run: cargo run --release --bin simulator syncing-sim -======= - name: Run a beacon chain sim which tests VC fallback behaviour run: cargo run --release --bin simulator fallback-sim ->>>>>>> unstable doppelganger-protection-test: name: doppelganger-protection-test runs-on: ${{ github.repository == 'sigp/lighthouse' && fromJson('["self-hosted", "linux", "CI", "small"]') || 'ubuntu-latest' }} diff --git a/.github/workflows/test-suite.yml.orig b/.github/workflows/test-suite.yml.orig deleted file mode 100644 index 98ef2d38d4..0000000000 --- a/.github/workflows/test-suite.yml.orig +++ /dev/null @@ -1,475 +0,0 @@ -name: test-suite - -on: - push: - branches: - - stable - - staging - - trying - - 'pr/*' - pull_request: - merge_group: - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -env: - # Deny warnings in CI - # Disable debug info (see https://github.com/sigp/lighthouse/issues/4005) - RUSTFLAGS: "-D warnings -C debuginfo=0" - # Prevent Github API rate limiting. - LIGHTHOUSE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # Enable self-hosted runners for the sigp repo only. - SELF_HOSTED_RUNNERS: ${{ github.repository == 'sigp/lighthouse' }} - # Self-hosted runners need to reference a different host for `./watch` tests. - WATCH_HOST: ${{ github.repository == 'sigp/lighthouse' && 'host.docker.internal' || 'localhost' }} - # Disable incremental compilation - CARGO_INCREMENTAL: 0 - # Enable portable to prevent issues with caching `blst` for the wrong CPU type - TEST_FEATURES: portable -jobs: - target-branch-check: - name: target-branch-check - runs-on: ubuntu-latest - if: github.event_name == 'pull_request' || github.event_name == 'merge_group' - steps: - - name: Check that the pull request is not targeting the stable branch - run: test ${{ github.base_ref }} != "stable" - release-tests-ubuntu: - name: release-tests-ubuntu - # Use self-hosted runners only on the sigp repo. - runs-on: ${{ github.repository == 'sigp/lighthouse' && fromJson('["self-hosted", "linux", "CI", "large"]') || 'ubuntu-latest' }} - steps: - - uses: actions/checkout@v4 - - name: Get latest version of stable Rust - if: env.SELF_HOSTED_RUNNERS == 'false' - uses: moonrepo/setup-rust@v1 - with: - channel: stable - cache-target: release - bins: cargo-nextest - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Install Foundry (anvil) - if: env.SELF_HOSTED_RUNNERS == 'false' - uses: foundry-rs/foundry-toolchain@v1 - with: - version: nightly-ca67d15f4abd46394b324c50e21e66f306a1162d - - name: Run tests in release - run: make nextest-release - - name: Show cache stats - if: env.SELF_HOSTED_RUNNERS == 'true' - run: sccache --show-stats - release-tests-windows: - name: release-tests-windows - runs-on: ${{ github.repository == 'sigp/lighthouse' && fromJson('["self-hosted", "windows", "CI"]') || 'windows-2019' }} - steps: - - uses: actions/checkout@v4 - - name: Get latest version of stable Rust - if: env.SELF_HOSTED_RUNNERS == 'false' - uses: moonrepo/setup-rust@v1 - with: - channel: stable - cache-target: release - bins: cargo-nextest - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Install Foundry (anvil) - if: env.SELF_HOSTED_RUNNERS == 'false' - uses: foundry-rs/foundry-toolchain@v1 - with: - version: nightly-ca67d15f4abd46394b324c50e21e66f306a1162d - - name: Install make - if: env.SELF_HOSTED_RUNNERS == 'false' - run: choco install -y make -# - uses: KyleMayes/install-llvm-action@v1 -# if: env.SELF_HOSTED_RUNNERS == 'false' -# with: -# version: "16.0" -# directory: ${{ runner.temp }}/llvm - - name: Set LIBCLANG_PATH - run: echo "LIBCLANG_PATH=$((gcm clang).source -replace "clang.exe")" >> $env:GITHUB_ENV - - name: Run tests in release - run: make nextest-release - - name: Show cache stats - if: env.SELF_HOSTED_RUNNERS == 'true' - run: sccache --show-stats - beacon-chain-tests: - name: beacon-chain-tests - # Use self-hosted runners only on the sigp repo. - runs-on: ${{ github.repository == 'sigp/lighthouse' && fromJson('["self-hosted", "linux", "CI", "large"]') || 'ubuntu-latest' }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - steps: - - uses: actions/checkout@v4 - - name: Get latest version of stable Rust - if: env.SELF_HOSTED_RUNNERS == 'false' - uses: moonrepo/setup-rust@v1 - with: - channel: stable - cache-target: release - bins: cargo-nextest - - name: Run beacon_chain tests for all known forks - run: make test-beacon-chain - - name: Show cache stats - if: env.SELF_HOSTED_RUNNERS == 'true' - run: sccache --show-stats - op-pool-tests: - name: op-pool-tests - runs-on: ubuntu-latest - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - steps: - - uses: actions/checkout@v4 - - name: Get latest version of stable Rust - uses: moonrepo/setup-rust@v1 - with: - channel: stable - cache-target: release - bins: cargo-nextest - - name: Run operation_pool tests for all known forks - run: make test-op-pool - network-tests: - name: network-tests - runs-on: ubuntu-latest - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - steps: - - uses: actions/checkout@v4 - - name: Get latest version of stable Rust - uses: moonrepo/setup-rust@v1 - with: - channel: stable - cache-target: release - bins: cargo-nextest - - name: Run network tests for all known forks - run: make test-network - slasher-tests: - name: slasher-tests - runs-on: ubuntu-latest - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - steps: - - uses: actions/checkout@v4 - - name: Get latest version of stable Rust - uses: moonrepo/setup-rust@v1 - with: - channel: stable - cache-target: release - bins: cargo-nextest - - name: Run slasher tests for all supported backends - run: make test-slasher - debug-tests-ubuntu: - name: debug-tests-ubuntu - # Use self-hosted runners only on the sigp repo. - runs-on: ${{ github.repository == 'sigp/lighthouse' && fromJson('["self-hosted", "linux", "CI", "large"]') || 'ubuntu-latest' }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - steps: - - uses: actions/checkout@v4 - - name: Get latest version of stable Rust - if: env.SELF_HOSTED_RUNNERS == 'false' - uses: moonrepo/setup-rust@v1 - with: - channel: stable - bins: cargo-nextest - - name: Install Foundry (anvil) - if: env.SELF_HOSTED_RUNNERS == 'false' - uses: foundry-rs/foundry-toolchain@v1 - with: - version: nightly-ca67d15f4abd46394b324c50e21e66f306a1162d - - name: Run tests in debug - run: make nextest-debug - - name: Show cache stats - if: env.SELF_HOSTED_RUNNERS == 'true' - run: sccache --show-stats - state-transition-vectors-ubuntu: - name: state-transition-vectors-ubuntu - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Get latest version of stable Rust - uses: moonrepo/setup-rust@v1 - with: - channel: stable - cache-target: release - - name: Run state_transition_vectors in release. - run: make run-state-transition-tests - ef-tests-ubuntu: - name: ef-tests-ubuntu - # Use self-hosted runners only on the sigp repo. - runs-on: ${{ github.repository == 'sigp/lighthouse' && fromJson('["self-hosted", "linux", "CI", "small"]') || 'ubuntu-latest' }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - steps: - - uses: actions/checkout@v4 - - name: Get latest version of stable Rust - if: env.SELF_HOSTED_RUNNERS == 'false' - uses: moonrepo/setup-rust@v1 - with: - channel: stable - cache-target: release - bins: cargo-nextest - - name: Run consensus-spec-tests with blst and fake_crypto - run: make nextest-ef - - name: Show cache stats - if: env.SELF_HOSTED_RUNNERS == 'true' - run: sccache --show-stats - dockerfile-ubuntu: - name: dockerfile-ubuntu - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Build the root Dockerfile - run: docker build --build-arg FEATURES=portable -t lighthouse:local . - - name: Test the built image - run: docker run -t lighthouse:local lighthouse --version - basic-simulator-ubuntu: - name: basic-simulator-ubuntu - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Get latest version of stable Rust - uses: moonrepo/setup-rust@v1 - with: - channel: stable - cache-target: release - - name: Run a basic beacon chain sim that starts from Bellatrix - run: cargo run --release --bin simulator basic-sim - fallback-simulator-ubuntu: - name: fallback-simulator-ubuntu - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Get latest version of stable Rust - uses: moonrepo/setup-rust@v1 - with: - channel: stable - cache-target: release -<<<<<<< HEAD - - name: Install Foundry (anvil) - uses: foundry-rs/foundry-toolchain@v1 - with: - version: nightly-ca67d15f4abd46394b324c50e21e66f306a1162d - - name: Run the beacon chain sim and go through the merge transition - run: cargo run --release --bin simulator eth1-sim --post-merge - no-eth1-simulator-ubuntu: - name: no-eth1-simulator-ubuntu - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Get latest version of stable Rust - uses: moonrepo/setup-rust@v1 - with: - channel: stable - cache-target: release - - name: Run the beacon chain sim without an eth1 connection - run: cargo run --release --bin simulator no-eth1-sim - fallback-simulator-ubuntu: - name: fallback-simulator-ubuntu - runs-on: ubuntu-latest - needs: cargo-fmt - steps: - - uses: actions/checkout@v3 - - name: Get latest version of stable Rust - run: rustup update stable - - name: Install Protoc - uses: arduino/setup-protoc@e52d9eb8f7b63115df1ac544a1376fdbf5a39612 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - - name: Install Foundry (anvil) - uses: foundry-rs/foundry-toolchain@v1 - - name: Run the fallback simulator - run: cargo run --release --bin simulator fallback-sim - syncing-simulator-ubuntu: - name: syncing-simulator-ubuntu - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Get latest version of stable Rust - uses: moonrepo/setup-rust@v1 - with: - channel: stable - cache-target: release - - name: Install Foundry (anvil) - uses: foundry-rs/foundry-toolchain@v1 - with: - version: nightly-ca67d15f4abd46394b324c50e21e66f306a1162d - - name: Run the syncing simulator - run: cargo run --release --bin simulator syncing-sim -======= - - name: Run a beacon chain sim which tests VC fallback behaviour - run: cargo run --release --bin simulator fallback-sim ->>>>>>> unstable - doppelganger-protection-test: - name: doppelganger-protection-test - runs-on: ${{ github.repository == 'sigp/lighthouse' && fromJson('["self-hosted", "linux", "CI", "small"]') || 'ubuntu-latest' }} - env: - # Enable portable to prevent issues with caching `blst` for the wrong CPU type - FEATURES: jemalloc,portable - steps: - - uses: actions/checkout@v4 - - name: Get latest version of stable Rust - if: env.SELF_HOSTED_RUNNERS == 'false' - uses: moonrepo/setup-rust@v1 - with: - channel: stable - cache-target: release - - name: Install geth - if: env.SELF_HOSTED_RUNNERS == 'false' - run: | - sudo add-apt-repository -y ppa:ethereum/ethereum - sudo apt-get update - sudo apt-get install ethereum - - name: Install lighthouse - run: | - make - - name: Install lcli - # TODO: uncomment after the version of lcli in https://github.com/sigp/lighthouse/pull/5137 - # is installed on the runners - # if: env.SELF_HOSTED_RUNNERS == 'false' - run: make install-lcli - - name: Run the doppelganger protection failure test script - run: | - cd scripts/tests - ./doppelganger_protection.sh failure genesis.json - - name: Run the doppelganger protection success test script - run: | - cd scripts/tests - ./doppelganger_protection.sh success genesis.json - execution-engine-integration-ubuntu: - name: execution-engine-integration-ubuntu - runs-on: ${{ github.repository == 'sigp/lighthouse' && fromJson('["self-hosted", "linux", "CI", "small"]') || 'ubuntu-latest' }} - steps: - - uses: actions/checkout@v4 - - name: Get latest version of stable Rust - if: env.SELF_HOSTED_RUNNERS == 'false' - uses: moonrepo/setup-rust@v1 - with: - channel: stable - cache-target: release - cache: false - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Add go compiler to $PATH - if: env.SELF_HOSTED_RUNNERS == 'true' - run: echo "/usr/local/go/bin" >> $GITHUB_PATH - - name: Run exec engine integration tests in release - run: make test-exec-engine - check-code: - name: check-code - runs-on: ubuntu-latest - env: - CARGO_INCREMENTAL: 1 - steps: - - uses: actions/checkout@v4 - - name: Get latest version of stable Rust - uses: moonrepo/setup-rust@v1 - with: - channel: stable - cache-target: release - components: rustfmt,clippy - bins: cargo-audit - - name: Check formatting with cargo fmt - run: make cargo-fmt - - name: Lint code for quality and style with Clippy - run: make lint - - name: Certify Cargo.lock freshness - run: git diff --exit-code Cargo.lock - - name: Typecheck benchmark code without running it - run: make check-benches - - name: Validate state_processing feature arbitrary-fuzz - run: make arbitrary-fuzz - - name: Run cargo audit - run: make audit-CI - - name: Run cargo vendor to make sure dependencies can be vendored for packaging, reproducibility and archival purpose - run: CARGO_HOME=$(readlink -f $HOME) make vendor - check-msrv: - name: check-msrv - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Install Rust at Minimum Supported Rust Version (MSRV) - run: | - metadata=$(cargo metadata --no-deps --format-version 1) - msrv=$(echo $metadata | jq -r '.packages | map(select(.name == "lighthouse")) | .[0].rust_version') - rustup override set $msrv - - name: Run cargo check - run: cargo check --workspace - cargo-udeps: - name: cargo-udeps - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Get latest version of nightly Rust - uses: moonrepo/setup-rust@v1 - with: - channel: nightly - bins: cargo-udeps - cache: false - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Create Cargo config dir - run: mkdir -p .cargo - - name: Install custom Cargo config - run: cp -f .github/custom/config.toml .cargo/config.toml - - name: Run cargo udeps to identify unused crates in the dependency graph - run: make udeps - env: - # Allow warnings on Nightly - RUSTFLAGS: "" - compile-with-beta-compiler: - name: compile-with-beta-compiler - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Install dependencies - run: sudo apt update && sudo apt install -y git gcc g++ make cmake pkg-config llvm-dev libclang-dev clang - - name: Use Rust beta - run: rustup override set beta - - name: Run make - run: make - cli-check: - name: cli-check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Get latest version of stable Rust - uses: moonrepo/setup-rust@v1 - with: - channel: stable - cache-target: release - - name: Run Makefile to trigger the bash script - run: make cli - # This job succeeds ONLY IF all others succeed. It is used by the merge queue to determine whether - # a PR is safe to merge. New jobs should be added here. - test-suite-success: - name: test-suite-success - runs-on: ubuntu-latest - needs: [ - 'target-branch-check', - 'release-tests-ubuntu', - 'release-tests-windows', - 'beacon-chain-tests', - 'op-pool-tests', - 'network-tests', - 'slasher-tests', - 'debug-tests-ubuntu', - 'state-transition-vectors-ubuntu', - 'ef-tests-ubuntu', - 'dockerfile-ubuntu', - 'basic-simulator-ubuntu', - 'fallback-simulator-ubuntu', - 'doppelganger-protection-test', - 'execution-engine-integration-ubuntu', - 'check-code', - 'check-msrv', - 'cargo-udeps', - 'compile-with-beta-compiler', - 'cli-check', - ] - steps: - - uses: actions/checkout@v4 - - name: Check that success job is dependent on all others - run: ./scripts/ci/check-success-job.sh ./.github/workflows/test-suite.yml test-suite-success diff --git a/lighthouse/tests/validator_client_BACKUP_4094175.rs b/lighthouse/tests/validator_client_BACKUP_4094175.rs deleted file mode 100644 index c785dc24fc..0000000000 --- a/lighthouse/tests/validator_client_BACKUP_4094175.rs +++ /dev/null @@ -1,705 +0,0 @@ -use validator_client::{config::DEFAULT_WEB3SIGNER_KEEP_ALIVE, ApiTopic, BeaconNodeSyncDistanceTiers, Config}; - -use crate::exec::CommandLineTestExec; -use bls::{Keypair, PublicKeyBytes}; -use std::fs::File; -use std::io::Write; -use std::net::IpAddr; -use std::path::PathBuf; -use std::process::Command; -use std::str::FromStr; -use std::string::ToString; -use std::time::Duration; -use tempfile::TempDir; -use types::{Address, Slot}; - -/// Returns the `lighthouse validator_client` command. -fn base_cmd() -> Command { - let lighthouse_bin = env!("CARGO_BIN_EXE_lighthouse"); - let path = lighthouse_bin - .parse::() - .expect("should parse CARGO_TARGET_DIR"); - - let mut cmd = Command::new(path); - cmd.arg("validator_client"); - cmd -} - -// Wrapper around `Command` for easier Command Line Testing. -struct CommandLineTest { - cmd: Command, -} -impl CommandLineTest { - fn new() -> CommandLineTest { - let base_cmd = base_cmd(); - CommandLineTest { cmd: base_cmd } - } -} - -impl CommandLineTestExec for CommandLineTest { - type Config = Config; - - fn cmd_mut(&mut self) -> &mut Command { - &mut self.cmd - } -} - -#[test] -fn datadir_flag() { - CommandLineTest::new() - .run() - .with_config_and_dir(|config, dir| { - assert_eq!(config.validator_dir, dir.path().join("validators")); - assert_eq!(config.secrets_dir, dir.path().join("secrets")); - }); -} - -#[test] -fn validators_and_secrets_dir_flags() { - let dir = TempDir::new().expect("Unable to create temporary directory"); - CommandLineTest::new() - .flag("validators-dir", dir.path().join("validators").to_str()) - .flag("secrets-dir", dir.path().join("secrets").to_str()) - .run_with_no_datadir() - .with_config(|config| { - assert_eq!(config.validator_dir, dir.path().join("validators")); - assert_eq!(config.secrets_dir, dir.path().join("secrets")); - }); -} - -#[test] -fn validators_dir_alias_flags() { - let dir = TempDir::new().expect("Unable to create temporary directory"); - CommandLineTest::new() - .flag("validator-dir", dir.path().join("validators").to_str()) - .flag("secrets-dir", dir.path().join("secrets").to_str()) - .run_with_no_datadir() - .with_config(|config| { - assert_eq!(config.validator_dir, dir.path().join("validators")); - assert_eq!(config.secrets_dir, dir.path().join("secrets")); - }); -} - -#[test] -fn beacon_nodes_flag() { - CommandLineTest::new() - .flag( - "beacon-nodes", - Some("http://localhost:1001,https://project:secret@infura.io/"), - ) - .run() - .with_config(|config| { - assert_eq!( - config.beacon_nodes[0].full.to_string(), - "http://localhost:1001/" - ); - assert_eq!(config.beacon_nodes[0].to_string(), "http://localhost:1001/"); - assert_eq!( - config.beacon_nodes[1].full.to_string(), - "https://project:secret@infura.io/" - ); - assert_eq!(config.beacon_nodes[1].to_string(), "https://infura.io/"); - }); -} - -#[test] -fn disable_auto_discover_flag() { - CommandLineTest::new() - .flag("disable-auto-discover", None) - .run() - .with_config(|config| assert!(config.disable_auto_discover)); -} - -#[test] -fn init_slashing_protections_flag() { - CommandLineTest::new() - .flag("init-slashing-protection", None) - .run() - .with_config(|config| assert!(config.init_slashing_protection)); -} - -#[test] -fn use_long_timeouts_flag() { - CommandLineTest::new() - .flag("use-long-timeouts", None) - .run() - .with_config(|config| assert!(config.use_long_timeouts)); -} - -#[test] -fn beacon_nodes_tls_certs_flag() { - let dir = TempDir::new().expect("Unable to create temporary directory"); - CommandLineTest::new() - .flag( - "beacon-nodes-tls-certs", - Some( - vec![ - dir.path().join("certificate.crt").to_str().unwrap(), - dir.path().join("certificate2.crt").to_str().unwrap(), - ] - .join(",") - .as_str(), - ), - ) - .run() - .with_config(|config| { - assert_eq!( - config.beacon_nodes_tls_certs, - Some(vec![ - dir.path().join("certificate.crt"), - dir.path().join("certificate2.crt") - ]) - ) - }); -} - -// Tests for Graffiti flags. -#[test] -fn graffiti_flag() { - CommandLineTest::new() - .flag("graffiti", Some("nice-graffiti")) - .run() - .with_config(|config| { - assert_eq!( - config.graffiti.unwrap().to_string(), - "0x6e6963652d677261666669746900000000000000000000000000000000000000" - ) - }); -} -#[test] -fn graffiti_file_flag() { - let dir = TempDir::new().expect("Unable to create temporary directory"); - let mut file = File::create(dir.path().join("graffiti.txt")).expect("Unable to create file"); - let new_key = Keypair::random(); - let pubkeybytes = PublicKeyBytes::from(new_key.pk); - let contents = "default:nice-graffiti"; - file.write_all(contents.as_bytes()) - .expect("Unable to write to file"); - CommandLineTest::new() - .flag( - "graffiti-file", - dir.path().join("graffiti.txt").as_os_str().to_str(), - ) - .run() - .with_config(|config| { - // Public key not present so load default. - assert_eq!( - config - .graffiti_file - .clone() - .unwrap() - .load_graffiti(&pubkeybytes) - .unwrap() - .unwrap() - .to_string(), - "0x6e6963652d677261666669746900000000000000000000000000000000000000" - ) - }); -} -#[test] -fn graffiti_file_with_pk_flag() { - let dir = TempDir::new().expect("Unable to create temporary directory"); - let mut file = File::create(dir.path().join("graffiti.txt")).expect("Unable to create file"); - let new_key = Keypair::random(); - let pubkeybytes = PublicKeyBytes::from(new_key.pk); - let contents = format!("{}:nice-graffiti", pubkeybytes.to_string()); - file.write_all(contents.as_bytes()) - .expect("Unable to write to file"); - CommandLineTest::new() - .flag( - "graffiti-file", - dir.path().join("graffiti.txt").as_os_str().to_str(), - ) - .run() - .with_config(|config| { - assert_eq!( - config - .graffiti_file - .clone() - .unwrap() - .load_graffiti(&pubkeybytes) - .unwrap() - .unwrap() - .to_string(), - "0x6e6963652d677261666669746900000000000000000000000000000000000000" - ) - }); -} - -// Tests for suggested-fee-recipient flags. -#[test] -fn fee_recipient_flag() { - CommandLineTest::new() - .flag( - "suggested-fee-recipient", - Some("0x00000000219ab540356cbb839cbe05303d7705fa"), - ) - .run() - .with_config(|config| { - assert_eq!( - config.fee_recipient, - Some(Address::from_str("0x00000000219ab540356cbb839cbe05303d7705fa").unwrap()) - ) - }); -} - -// Tests for HTTP flags. -#[test] -fn http_flag() { - CommandLineTest::new() - .flag("http", None) - .run() - .with_config(|config| assert!(config.http_api.enabled)); -} -#[test] -fn http_address_flag() { - let addr = "127.0.0.99".parse::().unwrap(); - CommandLineTest::new() - .flag("http", None) - .flag("http-address", Some("127.0.0.99")) - .flag("unencrypted-http-transport", None) - .run() - .with_config(|config| assert_eq!(config.http_api.listen_addr, addr)); -} -#[test] -fn http_address_ipv6_flag() { - let addr = "::1".parse::().unwrap(); - CommandLineTest::new() - .flag("http", None) - .flag("http-address", Some("::1")) - .flag("unencrypted-http-transport", None) - .run() - .with_config(|config| assert_eq!(config.http_api.listen_addr, addr)); -} -#[test] -#[should_panic] -fn missing_unencrypted_http_transport_flag() { - let addr = "127.0.0.99".parse::().unwrap(); - CommandLineTest::new() - .flag("http", None) - .flag("http-address", Some("127.0.0.99")) - .run() - .with_config(|config| assert_eq!(config.http_api.listen_addr, addr)); -} -#[test] -fn http_port_flag() { - CommandLineTest::new() - .flag("http", None) - .flag("http-port", Some("9090")) - .run() - .with_config(|config| assert_eq!(config.http_api.listen_port, 9090)); -} -#[test] -fn http_allow_origin_flag() { - CommandLineTest::new() - .flag("http", None) - .flag("http-allow-origin", Some("http://localhost:9009")) - .run() - .with_config(|config| { - assert_eq!( - config.http_api.allow_origin, - Some("http://localhost:9009".to_string()) - ); - }); -} -#[test] -fn http_allow_origin_all_flag() { - CommandLineTest::new() - .flag("http", None) - .flag("http-allow-origin", Some("*")) - .run() - .with_config(|config| assert_eq!(config.http_api.allow_origin, Some("*".to_string()))); -} -#[test] -fn http_allow_keystore_export_default() { - CommandLineTest::new() - .flag("http", None) - .run() - .with_config(|config| assert!(!config.http_api.allow_keystore_export)); -} -#[test] -fn http_allow_keystore_export_present() { - CommandLineTest::new() - .flag("http", None) - .flag("http-allow-keystore-export", None) - .run() - .with_config(|config| assert!(config.http_api.allow_keystore_export)); -} -#[test] -fn http_store_keystore_passwords_in_secrets_dir_default() { - CommandLineTest::new() - .flag("http", None) - .run() - .with_config(|config| assert!(!config.http_api.store_passwords_in_secrets_dir)); -} -#[test] -fn http_store_keystore_passwords_in_secrets_dir_present() { - CommandLineTest::new() - .flag("http", None) - .flag("http-store-passwords-in-secrets-dir", None) - .run() - .with_config(|config| assert!(config.http_api.store_passwords_in_secrets_dir)); -} - -// Tests for Metrics flags. -#[test] -fn metrics_flag() { - CommandLineTest::new() - .flag("metrics", None) - .run() - .with_config(|config| assert!(config.http_metrics.enabled)); -} -#[test] -fn metrics_address_flag() { - let addr = "127.0.0.99".parse::().unwrap(); - CommandLineTest::new() - .flag("metrics", None) - .flag("metrics-address", Some("127.0.0.99")) - .run() - .with_config(|config| assert_eq!(config.http_metrics.listen_addr, addr)); -} -#[test] -fn metrics_address_ipv6_flag() { - let addr = "::1".parse::().unwrap(); - CommandLineTest::new() - .flag("metrics", None) - .flag("metrics-address", Some("::1")) - .run() - .with_config(|config| assert_eq!(config.http_metrics.listen_addr, addr)); -} -#[test] -fn metrics_port_flag() { - CommandLineTest::new() - .flag("metrics", None) - .flag("metrics-port", Some("9090")) - .run() - .with_config(|config| assert_eq!(config.http_metrics.listen_port, 9090)); -} -#[test] -fn metrics_allow_origin_flag() { - CommandLineTest::new() - .flag("metrics", None) - .flag("metrics-allow-origin", Some("http://localhost:9009")) - .run() - .with_config(|config| { - assert_eq!( - config.http_metrics.allow_origin, - Some("http://localhost:9009".to_string()) - ); - }); -} -#[test] -fn metrics_allow_origin_all_flag() { - CommandLineTest::new() - .flag("metrics", None) - .flag("metrics-allow-origin", Some("*")) - .run() - .with_config(|config| assert_eq!(config.http_metrics.allow_origin, Some("*".to_string()))); -} -#[test] -pub fn malloc_tuning_flag() { - CommandLineTest::new() - .flag("disable-malloc-tuning", None) - .run() - .with_config(|config| assert_eq!(config.http_metrics.allocator_metrics_enabled, false)); -} -#[test] -pub fn malloc_tuning_default() { - CommandLineTest::new() - .run() - .with_config(|config| assert_eq!(config.http_metrics.allocator_metrics_enabled, true)); -} -#[test] -fn doppelganger_protection_flag() { - CommandLineTest::new() - .flag("enable-doppelganger-protection", None) - .run() - .with_config(|config| assert!(config.enable_doppelganger_protection)); -} -#[test] -fn no_doppelganger_protection_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert!(!config.enable_doppelganger_protection)); -} -#[test] -fn produce_block_v3_flag() { - CommandLineTest::new() - .flag("produce-block-v3", None) - .run() - .with_config(|config| assert!(config.produce_block_v3)); -} - -#[test] -fn no_produce_block_v3_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert!(!config.produce_block_v3)); -} - -#[test] -fn no_gas_limit_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert!(config.gas_limit.is_none())); -} -#[test] -fn gas_limit_flag() { - CommandLineTest::new() - .flag("gas-limit", Some("600")) - .flag("builder-proposals", None) - .run() - .with_config(|config| assert_eq!(config.gas_limit, Some(600))); -} -#[test] -fn no_builder_proposals_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert!(!config.builder_proposals)); -} -#[test] -fn builder_proposals_flag() { - CommandLineTest::new() - .flag("builder-proposals", None) - .run() - .with_config(|config| assert!(config.builder_proposals)); -} -#[test] -fn builder_boost_factor_flag() { - CommandLineTest::new() - .flag("builder-boost-factor", Some("150")) - .run() - .with_config(|config| assert_eq!(config.builder_boost_factor, Some(150))); -} -#[test] -fn no_builder_boost_factor_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert_eq!(config.builder_boost_factor, None)); -} -#[test] -fn prefer_builder_proposals_flag() { - CommandLineTest::new() - .flag("prefer-builder-proposals", None) - .run() - .with_config(|config| assert!(config.prefer_builder_proposals)); -} -#[test] -fn no_prefer_builder_proposals_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert!(!config.prefer_builder_proposals)); -} -#[test] -fn no_builder_registration_timestamp_override_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert!(config.builder_registration_timestamp_override.is_none())); -} -#[test] -fn builder_registration_timestamp_override_flag() { - CommandLineTest::new() - .flag("builder-registration-timestamp-override", Some("100")) - .run() - .with_config(|config| { - assert_eq!(config.builder_registration_timestamp_override, Some(100)) - }); -} -#[test] -fn monitoring_endpoint() { - CommandLineTest::new() - .flag("monitoring-endpoint", Some("http://example:8000")) - .flag("monitoring-endpoint-period", Some("30")) - .run() - .with_config(|config| { - let api_conf = config.monitoring_api.as_ref().unwrap(); - assert_eq!(api_conf.monitoring_endpoint.as_str(), "http://example:8000"); - assert_eq!(api_conf.update_period_secs, Some(30)); - }); -} -#[test] -fn disable_run_on_all_flag() { - CommandLineTest::new() - .flag("disable-run-on-all", None) - .run() - .with_config(|config| { - assert_eq!(config.broadcast_topics, vec![]); - }); - // --broadcast flag takes precedence - CommandLineTest::new() - .flag("disable-run-on-all", None) - .flag("broadcast", Some("attestations")) - .run() - .with_config(|config| { - assert_eq!(config.broadcast_topics, vec![ApiTopic::Attestations]); - }); -} - -#[test] -fn no_broadcast_flag() { - CommandLineTest::new().run().with_config(|config| { - assert_eq!(config.broadcast_topics, vec![ApiTopic::Subscriptions]); - }); -} - -#[test] -fn broadcast_flag() { - // "none" variant - CommandLineTest::new() - .flag("broadcast", Some("none")) - .run() - .with_config(|config| { - assert_eq!(config.broadcast_topics, vec![]); - }); - // "none" with other values is ignored - CommandLineTest::new() - .flag("broadcast", Some("none,sync-committee")) - .run() - .with_config(|config| { - assert_eq!(config.broadcast_topics, vec![ApiTopic::SyncCommittee]); - }); - // Other valid variants - CommandLineTest::new() - .flag("broadcast", Some("blocks, subscriptions")) - .run() - .with_config(|config| { - assert_eq!( - config.broadcast_topics, - vec![ApiTopic::Blocks, ApiTopic::Subscriptions], - ); - }); - // Omitted "subscription" overrides default - CommandLineTest::new() - .flag("broadcast", Some("attestations")) - .run() - .with_config(|config| { - assert_eq!(config.broadcast_topics, vec![ApiTopic::Attestations]); - }); -} - -/// Tests for validator fallback flags. -#[test] -fn beacon_nodes_sync_tolerances_flag_default() { - CommandLineTest::new().run().with_config(|config| { - assert_eq!( - config.beacon_node_fallback.sync_tolerances, - BeaconNodeSyncDistanceTiers::default() - ) - }); -} -#[test] -fn beacon_nodes_sync_tolerances_flag() { - CommandLineTest::new() - .flag("beacon-nodes-sync-tolerances", Some("4,4,4")) - .run() - .with_config(|config| { - assert_eq!( - config.beacon_node_fallback.sync_tolerances, - BeaconNodeSyncDistanceTiers { - synced: Slot::new(4), - small: Slot::new(8), - medium: Slot::new(12), - } - ); - }); -} - -#[test] -#[should_panic(expected = "Unknown API topic")] -fn wrong_broadcast_flag() { - CommandLineTest::new() - .flag("broadcast", Some("foo, subscriptions")) - .run() - .with_config(|config| { - assert_eq!( - config.broadcast_topics, - vec![ApiTopic::Blocks, ApiTopic::Subscriptions], - ); - }); -} - -#[test] -fn latency_measurement_service() { - CommandLineTest::new().run().with_config(|config| { - assert!(config.enable_latency_measurement_service); - }); - CommandLineTest::new() - .flag("latency-measurement-service", None) - .run() - .with_config(|config| { - assert!(config.enable_latency_measurement_service); - }); - CommandLineTest::new() - .flag("latency-measurement-service", Some("true")) - .run() - .with_config(|config| { - assert!(config.enable_latency_measurement_service); - }); - CommandLineTest::new() - .flag("latency-measurement-service", Some("false")) - .run() - .with_config(|config| { - assert!(!config.enable_latency_measurement_service); - }); -} - -#[test] -fn validator_registration_batch_size() { - CommandLineTest::new().run().with_config(|config| { - assert_eq!(config.validator_registration_batch_size, 500); - }); - CommandLineTest::new() - .flag("validator-registration-batch-size", Some("100")) - .run() - .with_config(|config| { - assert_eq!(config.validator_registration_batch_size, 100); - }); -} - -#[test] -#[should_panic] -fn validator_registration_batch_size_zero_value() { - CommandLineTest::new() - .flag("validator-registration-batch-size", Some("0")) - .run(); -} - -#[test] -fn validator_disable_web3_signer_slashing_protection_default() { - CommandLineTest::new().run().with_config(|config| { - assert!(config.enable_web3signer_slashing_protection); - }); -} - -#[test] -fn validator_disable_web3_signer_slashing_protection() { - CommandLineTest::new() - .flag("disable-slashing-protection-web3signer", None) - .run() - .with_config(|config| { - assert!(!config.enable_web3signer_slashing_protection); - }); -} - -#[test] -fn validator_web3_signer_keep_alive_default() { - CommandLineTest::new().run().with_config(|config| { - assert_eq!( - config.web3_signer_keep_alive_timeout, - DEFAULT_WEB3SIGNER_KEEP_ALIVE - ); - }); -} - -#[test] -fn validator_web3_signer_keep_alive_override() { - CommandLineTest::new() - .flag("web3-signer-keep-alive-timeout", Some("1000")) - .run() - .with_config(|config| { - assert_eq!( - config.web3_signer_keep_alive_timeout, - Some(Duration::from_secs(1)) - ); - }); -} diff --git a/lighthouse/tests/validator_client_BASE_4094175.rs b/lighthouse/tests/validator_client_BASE_4094175.rs deleted file mode 100644 index 764fd87ccd..0000000000 --- a/lighthouse/tests/validator_client_BASE_4094175.rs +++ /dev/null @@ -1,655 +0,0 @@ -use validator_client::{ApiTopic, Config}; - -use crate::exec::CommandLineTestExec; -use bls::{Keypair, PublicKeyBytes}; -use std::fs::File; -use std::io::Write; -use std::net::IpAddr; -use std::path::PathBuf; -use std::process::Command; -use std::str::FromStr; -use std::string::ToString; -use tempfile::TempDir; -use types::Address; - -/// Returns the `lighthouse validator_client` command. -fn base_cmd() -> Command { - let lighthouse_bin = env!("CARGO_BIN_EXE_lighthouse"); - let path = lighthouse_bin - .parse::() - .expect("should parse CARGO_TARGET_DIR"); - - let mut cmd = Command::new(path); - cmd.arg("validator_client"); - cmd -} - -// Wrapper around `Command` for easier Command Line Testing. -struct CommandLineTest { - cmd: Command, -} -impl CommandLineTest { - fn new() -> CommandLineTest { - let base_cmd = base_cmd(); - CommandLineTest { cmd: base_cmd } - } -} - -impl CommandLineTestExec for CommandLineTest { - type Config = Config; - - fn cmd_mut(&mut self) -> &mut Command { - &mut self.cmd - } -} - -#[test] -fn datadir_flag() { - CommandLineTest::new() - .run() - .with_config_and_dir(|config, dir| { - assert_eq!(config.validator_dir, dir.path().join("validators")); - assert_eq!(config.secrets_dir, dir.path().join("secrets")); - }); -} - -#[test] -fn validators_and_secrets_dir_flags() { - let dir = TempDir::new().expect("Unable to create temporary directory"); - CommandLineTest::new() - .flag("validators-dir", dir.path().join("validators").to_str()) - .flag("secrets-dir", dir.path().join("secrets").to_str()) - .run_with_no_datadir() - .with_config(|config| { - assert_eq!(config.validator_dir, dir.path().join("validators")); - assert_eq!(config.secrets_dir, dir.path().join("secrets")); - }); -} - -#[test] -fn validators_dir_alias_flags() { - let dir = TempDir::new().expect("Unable to create temporary directory"); - CommandLineTest::new() - .flag("validator-dir", dir.path().join("validators").to_str()) - .flag("secrets-dir", dir.path().join("secrets").to_str()) - .run_with_no_datadir() - .with_config(|config| { - assert_eq!(config.validator_dir, dir.path().join("validators")); - assert_eq!(config.secrets_dir, dir.path().join("secrets")); - }); -} - -#[test] -fn beacon_nodes_flag() { - CommandLineTest::new() - .flag( - "beacon-nodes", - Some("http://localhost:1001,https://project:secret@infura.io/"), - ) - .run() - .with_config(|config| { - assert_eq!( - config.beacon_nodes[0].full.to_string(), - "http://localhost:1001/" - ); - assert_eq!(config.beacon_nodes[0].to_string(), "http://localhost:1001/"); - assert_eq!( - config.beacon_nodes[1].full.to_string(), - "https://project:secret@infura.io/" - ); - assert_eq!(config.beacon_nodes[1].to_string(), "https://infura.io/"); - }); -} - -#[test] -fn disable_auto_discover_flag() { - CommandLineTest::new() - .flag("disable-auto-discover", None) - .run() - .with_config(|config| assert!(config.disable_auto_discover)); -} - -#[test] -fn init_slashing_protections_flag() { - CommandLineTest::new() - .flag("init-slashing-protection", None) - .run() - .with_config(|config| assert!(config.init_slashing_protection)); -} - -#[test] -fn use_long_timeouts_flag() { - CommandLineTest::new() - .flag("use-long-timeouts", None) - .run() - .with_config(|config| assert!(config.use_long_timeouts)); -} - -#[test] -fn beacon_nodes_tls_certs_flag() { - let dir = TempDir::new().expect("Unable to create temporary directory"); - CommandLineTest::new() - .flag( - "beacon-nodes-tls-certs", - Some( - vec![ - dir.path().join("certificate.crt").to_str().unwrap(), - dir.path().join("certificate2.crt").to_str().unwrap(), - ] - .join(",") - .as_str(), - ), - ) - .run() - .with_config(|config| { - assert_eq!( - config.beacon_nodes_tls_certs, - Some(vec![ - dir.path().join("certificate.crt"), - dir.path().join("certificate2.crt") - ]) - ) - }); -} - -// Tests for Graffiti flags. -#[test] -fn graffiti_flag() { - CommandLineTest::new() - .flag("graffiti", Some("nice-graffiti")) - .run() - .with_config(|config| { - assert_eq!( - config.graffiti.unwrap().to_string(), - "0x6e6963652d677261666669746900000000000000000000000000000000000000" - ) - }); -} -#[test] -fn graffiti_file_flag() { - let dir = TempDir::new().expect("Unable to create temporary directory"); - let mut file = File::create(dir.path().join("graffiti.txt")).expect("Unable to create file"); - let new_key = Keypair::random(); - let pubkeybytes = PublicKeyBytes::from(new_key.pk); - let contents = "default:nice-graffiti"; - file.write_all(contents.as_bytes()) - .expect("Unable to write to file"); - CommandLineTest::new() - .flag( - "graffiti-file", - dir.path().join("graffiti.txt").as_os_str().to_str(), - ) - .run() - .with_config(|config| { - // Public key not present so load default. - assert_eq!( - config - .graffiti_file - .clone() - .unwrap() - .load_graffiti(&pubkeybytes) - .unwrap() - .unwrap() - .to_string(), - "0x6e6963652d677261666669746900000000000000000000000000000000000000" - ) - }); -} -#[test] -fn graffiti_file_with_pk_flag() { - let dir = TempDir::new().expect("Unable to create temporary directory"); - let mut file = File::create(dir.path().join("graffiti.txt")).expect("Unable to create file"); - let new_key = Keypair::random(); - let pubkeybytes = PublicKeyBytes::from(new_key.pk); - let contents = format!("{}:nice-graffiti", pubkeybytes.to_string()); - file.write_all(contents.as_bytes()) - .expect("Unable to write to file"); - CommandLineTest::new() - .flag( - "graffiti-file", - dir.path().join("graffiti.txt").as_os_str().to_str(), - ) - .run() - .with_config(|config| { - assert_eq!( - config - .graffiti_file - .clone() - .unwrap() - .load_graffiti(&pubkeybytes) - .unwrap() - .unwrap() - .to_string(), - "0x6e6963652d677261666669746900000000000000000000000000000000000000" - ) - }); -} - -// Tests for suggested-fee-recipient flags. -#[test] -fn fee_recipient_flag() { - CommandLineTest::new() - .flag( - "suggested-fee-recipient", - Some("0x00000000219ab540356cbb839cbe05303d7705fa"), - ) - .run() - .with_config(|config| { - assert_eq!( - config.fee_recipient, - Some(Address::from_str("0x00000000219ab540356cbb839cbe05303d7705fa").unwrap()) - ) - }); -} - -// Tests for HTTP flags. -#[test] -fn http_flag() { - CommandLineTest::new() - .flag("http", None) - .run() - .with_config(|config| assert!(config.http_api.enabled)); -} -#[test] -fn http_address_flag() { - let addr = "127.0.0.99".parse::().unwrap(); - CommandLineTest::new() - .flag("http", None) - .flag("http-address", Some("127.0.0.99")) - .flag("unencrypted-http-transport", None) - .run() - .with_config(|config| assert_eq!(config.http_api.listen_addr, addr)); -} -#[test] -fn http_address_ipv6_flag() { - let addr = "::1".parse::().unwrap(); - CommandLineTest::new() - .flag("http", None) - .flag("http-address", Some("::1")) - .flag("unencrypted-http-transport", None) - .run() - .with_config(|config| assert_eq!(config.http_api.listen_addr, addr)); -} -#[test] -#[should_panic] -fn missing_unencrypted_http_transport_flag() { - let addr = "127.0.0.99".parse::().unwrap(); - CommandLineTest::new() - .flag("http", None) - .flag("http-address", Some("127.0.0.99")) - .run() - .with_config(|config| assert_eq!(config.http_api.listen_addr, addr)); -} -#[test] -fn http_port_flag() { - CommandLineTest::new() - .flag("http", None) - .flag("http-port", Some("9090")) - .run() - .with_config(|config| assert_eq!(config.http_api.listen_port, 9090)); -} -#[test] -fn http_allow_origin_flag() { - CommandLineTest::new() - .flag("http", None) - .flag("http-allow-origin", Some("http://localhost:9009")) - .run() - .with_config(|config| { - assert_eq!( - config.http_api.allow_origin, - Some("http://localhost:9009".to_string()) - ); - }); -} -#[test] -fn http_allow_origin_all_flag() { - CommandLineTest::new() - .flag("http", None) - .flag("http-allow-origin", Some("*")) - .run() - .with_config(|config| assert_eq!(config.http_api.allow_origin, Some("*".to_string()))); -} -#[test] -fn http_allow_keystore_export_default() { - CommandLineTest::new() - .flag("http", None) - .run() - .with_config(|config| assert!(!config.http_api.allow_keystore_export)); -} -#[test] -fn http_allow_keystore_export_present() { - CommandLineTest::new() - .flag("http", None) - .flag("http-allow-keystore-export", None) - .run() - .with_config(|config| assert!(config.http_api.allow_keystore_export)); -} -#[test] -fn http_store_keystore_passwords_in_secrets_dir_default() { - CommandLineTest::new() - .flag("http", None) - .run() - .with_config(|config| assert!(!config.http_api.store_passwords_in_secrets_dir)); -} -#[test] -fn http_store_keystore_passwords_in_secrets_dir_present() { - CommandLineTest::new() - .flag("http", None) - .flag("http-store-passwords-in-secrets-dir", None) - .run() - .with_config(|config| assert!(config.http_api.store_passwords_in_secrets_dir)); -} - -// Tests for Metrics flags. -#[test] -fn metrics_flag() { - CommandLineTest::new() - .flag("metrics", None) - .run() - .with_config(|config| assert!(config.http_metrics.enabled)); -} -#[test] -fn metrics_address_flag() { - let addr = "127.0.0.99".parse::().unwrap(); - CommandLineTest::new() - .flag("metrics", None) - .flag("metrics-address", Some("127.0.0.99")) - .run() - .with_config(|config| assert_eq!(config.http_metrics.listen_addr, addr)); -} -#[test] -fn metrics_address_ipv6_flag() { - let addr = "::1".parse::().unwrap(); - CommandLineTest::new() - .flag("metrics", None) - .flag("metrics-address", Some("::1")) - .run() - .with_config(|config| assert_eq!(config.http_metrics.listen_addr, addr)); -} -#[test] -fn metrics_port_flag() { - CommandLineTest::new() - .flag("metrics", None) - .flag("metrics-port", Some("9090")) - .run() - .with_config(|config| assert_eq!(config.http_metrics.listen_port, 9090)); -} -#[test] -fn metrics_allow_origin_flag() { - CommandLineTest::new() - .flag("metrics", None) - .flag("metrics-allow-origin", Some("http://localhost:9009")) - .run() - .with_config(|config| { - assert_eq!( - config.http_metrics.allow_origin, - Some("http://localhost:9009".to_string()) - ); - }); -} -#[test] -fn metrics_allow_origin_all_flag() { - CommandLineTest::new() - .flag("metrics", None) - .flag("metrics-allow-origin", Some("*")) - .run() - .with_config(|config| assert_eq!(config.http_metrics.allow_origin, Some("*".to_string()))); -} -#[test] -pub fn malloc_tuning_flag() { - CommandLineTest::new() - .flag("disable-malloc-tuning", None) - .run() - .with_config(|config| assert_eq!(config.http_metrics.allocator_metrics_enabled, false)); -} -#[test] -pub fn malloc_tuning_default() { - CommandLineTest::new() - .run() - .with_config(|config| assert_eq!(config.http_metrics.allocator_metrics_enabled, true)); -} -#[test] -fn doppelganger_protection_flag() { - CommandLineTest::new() - .flag("enable-doppelganger-protection", None) - .run() - .with_config(|config| assert!(config.enable_doppelganger_protection)); -} -#[test] -fn no_doppelganger_protection_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert!(!config.enable_doppelganger_protection)); -} -#[test] -fn produce_block_v3_flag() { - CommandLineTest::new() - .flag("produce-block-v3", None) - .run() - .with_config(|config| assert!(config.produce_block_v3)); -} - -#[test] -fn no_produce_block_v3_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert!(!config.produce_block_v3)); -} - -#[test] -fn no_gas_limit_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert!(config.gas_limit.is_none())); -} -#[test] -fn gas_limit_flag() { - CommandLineTest::new() - .flag("gas-limit", Some("600")) - .flag("builder-proposals", None) - .run() - .with_config(|config| assert_eq!(config.gas_limit, Some(600))); -} -#[test] -fn no_builder_proposals_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert!(!config.builder_proposals)); -} -#[test] -fn builder_proposals_flag() { - CommandLineTest::new() - .flag("builder-proposals", None) - .run() - .with_config(|config| assert!(config.builder_proposals)); -} -#[test] -fn builder_boost_factor_flag() { - CommandLineTest::new() - .flag("builder-boost-factor", Some("150")) - .run() - .with_config(|config| assert_eq!(config.builder_boost_factor, Some(150))); -} -#[test] -fn no_builder_boost_factor_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert_eq!(config.builder_boost_factor, None)); -} -#[test] -fn prefer_builder_proposals_flag() { - CommandLineTest::new() - .flag("prefer-builder-proposals", None) - .run() - .with_config(|config| assert!(config.prefer_builder_proposals)); -} -#[test] -fn no_prefer_builder_proposals_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert!(!config.prefer_builder_proposals)); -} -#[test] -fn no_builder_registration_timestamp_override_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert!(config.builder_registration_timestamp_override.is_none())); -} -#[test] -fn builder_registration_timestamp_override_flag() { - CommandLineTest::new() - .flag("builder-registration-timestamp-override", Some("100")) - .run() - .with_config(|config| { - assert_eq!(config.builder_registration_timestamp_override, Some(100)) - }); -} -#[test] -fn monitoring_endpoint() { - CommandLineTest::new() - .flag("monitoring-endpoint", Some("http://example:8000")) - .flag("monitoring-endpoint-period", Some("30")) - .run() - .with_config(|config| { - let api_conf = config.monitoring_api.as_ref().unwrap(); - assert_eq!(api_conf.monitoring_endpoint.as_str(), "http://example:8000"); - assert_eq!(api_conf.update_period_secs, Some(30)); - }); -} - -#[test] -fn disable_run_on_all_flag() { - CommandLineTest::new() - .flag("disable-run-on-all", None) - .run() - .with_config(|config| { - assert_eq!(config.broadcast_topics, vec![]); - }); - // --broadcast flag takes precedence - CommandLineTest::new() - .flag("disable-run-on-all", None) - .flag("broadcast", Some("attestations")) - .run() - .with_config(|config| { - assert_eq!(config.broadcast_topics, vec![ApiTopic::Attestations]); - }); -} - -#[test] -fn no_broadcast_flag() { - CommandLineTest::new().run().with_config(|config| { - assert_eq!(config.broadcast_topics, vec![ApiTopic::Subscriptions]); - }); -} - -#[test] -fn broadcast_flag() { - // "none" variant - CommandLineTest::new() - .flag("broadcast", Some("none")) - .run() - .with_config(|config| { - assert_eq!(config.broadcast_topics, vec![]); - }); - // "none" with other values is ignored - CommandLineTest::new() - .flag("broadcast", Some("none,sync-committee")) - .run() - .with_config(|config| { - assert_eq!(config.broadcast_topics, vec![ApiTopic::SyncCommittee]); - }); - // Other valid variants - CommandLineTest::new() - .flag("broadcast", Some("blocks, subscriptions")) - .run() - .with_config(|config| { - assert_eq!( - config.broadcast_topics, - vec![ApiTopic::Blocks, ApiTopic::Subscriptions], - ); - }); - // Omitted "subscription" overrides default - CommandLineTest::new() - .flag("broadcast", Some("attestations")) - .run() - .with_config(|config| { - assert_eq!(config.broadcast_topics, vec![ApiTopic::Attestations]); - }); -} - -#[test] -#[should_panic(expected = "Unknown API topic")] -fn wrong_broadcast_flag() { - CommandLineTest::new() - .flag("broadcast", Some("foo, subscriptions")) - .run() - .with_config(|config| { - assert_eq!( - config.broadcast_topics, - vec![ApiTopic::Blocks, ApiTopic::Subscriptions], - ); - }); -} - -#[test] -fn latency_measurement_service() { - CommandLineTest::new().run().with_config(|config| { - assert!(config.enable_latency_measurement_service); - }); - CommandLineTest::new() - .flag("latency-measurement-service", None) - .run() - .with_config(|config| { - assert!(config.enable_latency_measurement_service); - }); - CommandLineTest::new() - .flag("latency-measurement-service", Some("true")) - .run() - .with_config(|config| { - assert!(config.enable_latency_measurement_service); - }); - CommandLineTest::new() - .flag("latency-measurement-service", Some("false")) - .run() - .with_config(|config| { - assert!(!config.enable_latency_measurement_service); - }); -} - -#[test] -fn validator_registration_batch_size() { - CommandLineTest::new().run().with_config(|config| { - assert_eq!(config.validator_registration_batch_size, 500); - }); - CommandLineTest::new() - .flag("validator-registration-batch-size", Some("100")) - .run() - .with_config(|config| { - assert_eq!(config.validator_registration_batch_size, 100); - }); -} - -#[test] -#[should_panic] -fn validator_registration_batch_size_zero_value() { - CommandLineTest::new() - .flag("validator-registration-batch-size", Some("0")) - .run(); -} - -#[test] -fn validator_disable_web3_signer_slashing_protection_default() { - CommandLineTest::new().run().with_config(|config| { - assert!(config.enable_web3signer_slashing_protection); - }); -} - -#[test] -fn validator_disable_web3_signer_slashing_protection() { - CommandLineTest::new() - .flag("disable-slashing-protection-web3signer", None) - .run() - .with_config(|config| { - assert!(!config.enable_web3signer_slashing_protection); - }); -} diff --git a/lighthouse/tests/validator_client_LOCAL_4094175.rs b/lighthouse/tests/validator_client_LOCAL_4094175.rs deleted file mode 100644 index 285f3596d9..0000000000 --- a/lighthouse/tests/validator_client_LOCAL_4094175.rs +++ /dev/null @@ -1,681 +0,0 @@ -use validator_client::{ApiTopic, BeaconNodeSyncDistanceTiers, Config}; - -use crate::exec::CommandLineTestExec; -use bls::{Keypair, PublicKeyBytes}; -use std::fs::File; -use std::io::Write; -use std::net::IpAddr; -use std::path::PathBuf; -use std::process::Command; -use std::str::FromStr; -use std::string::ToString; -use tempfile::TempDir; -use types::{Address, Slot}; - -/// Returns the `lighthouse validator_client` command. -fn base_cmd() -> Command { - let lighthouse_bin = env!("CARGO_BIN_EXE_lighthouse"); - let path = lighthouse_bin - .parse::() - .expect("should parse CARGO_TARGET_DIR"); - - let mut cmd = Command::new(path); - cmd.arg("validator_client"); - cmd -} - -// Wrapper around `Command` for easier Command Line Testing. -struct CommandLineTest { - cmd: Command, -} -impl CommandLineTest { - fn new() -> CommandLineTest { - let base_cmd = base_cmd(); - CommandLineTest { cmd: base_cmd } - } -} - -impl CommandLineTestExec for CommandLineTest { - type Config = Config; - - fn cmd_mut(&mut self) -> &mut Command { - &mut self.cmd - } -} - -#[test] -fn datadir_flag() { - CommandLineTest::new() - .run() - .with_config_and_dir(|config, dir| { - assert_eq!(config.validator_dir, dir.path().join("validators")); - assert_eq!(config.secrets_dir, dir.path().join("secrets")); - }); -} - -#[test] -fn validators_and_secrets_dir_flags() { - let dir = TempDir::new().expect("Unable to create temporary directory"); - CommandLineTest::new() - .flag("validators-dir", dir.path().join("validators").to_str()) - .flag("secrets-dir", dir.path().join("secrets").to_str()) - .run_with_no_datadir() - .with_config(|config| { - assert_eq!(config.validator_dir, dir.path().join("validators")); - assert_eq!(config.secrets_dir, dir.path().join("secrets")); - }); -} - -#[test] -fn validators_dir_alias_flags() { - let dir = TempDir::new().expect("Unable to create temporary directory"); - CommandLineTest::new() - .flag("validator-dir", dir.path().join("validators").to_str()) - .flag("secrets-dir", dir.path().join("secrets").to_str()) - .run_with_no_datadir() - .with_config(|config| { - assert_eq!(config.validator_dir, dir.path().join("validators")); - assert_eq!(config.secrets_dir, dir.path().join("secrets")); - }); -} - -#[test] -fn beacon_nodes_flag() { - CommandLineTest::new() - .flag( - "beacon-nodes", - Some("http://localhost:1001,https://project:secret@infura.io/"), - ) - .run() - .with_config(|config| { - assert_eq!( - config.beacon_nodes[0].full.to_string(), - "http://localhost:1001/" - ); - assert_eq!(config.beacon_nodes[0].to_string(), "http://localhost:1001/"); - assert_eq!( - config.beacon_nodes[1].full.to_string(), - "https://project:secret@infura.io/" - ); - assert_eq!(config.beacon_nodes[1].to_string(), "https://infura.io/"); - }); -} - -#[test] -fn disable_auto_discover_flag() { - CommandLineTest::new() - .flag("disable-auto-discover", None) - .run() - .with_config(|config| assert!(config.disable_auto_discover)); -} - -#[test] -fn init_slashing_protections_flag() { - CommandLineTest::new() - .flag("init-slashing-protection", None) - .run() - .with_config(|config| assert!(config.init_slashing_protection)); -} - -#[test] -fn use_long_timeouts_flag() { - CommandLineTest::new() - .flag("use-long-timeouts", None) - .run() - .with_config(|config| assert!(config.use_long_timeouts)); -} - -#[test] -fn beacon_nodes_tls_certs_flag() { - let dir = TempDir::new().expect("Unable to create temporary directory"); - CommandLineTest::new() - .flag( - "beacon-nodes-tls-certs", - Some( - vec![ - dir.path().join("certificate.crt").to_str().unwrap(), - dir.path().join("certificate2.crt").to_str().unwrap(), - ] - .join(",") - .as_str(), - ), - ) - .run() - .with_config(|config| { - assert_eq!( - config.beacon_nodes_tls_certs, - Some(vec![ - dir.path().join("certificate.crt"), - dir.path().join("certificate2.crt") - ]) - ) - }); -} - -// Tests for Graffiti flags. -#[test] -fn graffiti_flag() { - CommandLineTest::new() - .flag("graffiti", Some("nice-graffiti")) - .run() - .with_config(|config| { - assert_eq!( - config.graffiti.unwrap().to_string(), - "0x6e6963652d677261666669746900000000000000000000000000000000000000" - ) - }); -} -#[test] -fn graffiti_file_flag() { - let dir = TempDir::new().expect("Unable to create temporary directory"); - let mut file = File::create(dir.path().join("graffiti.txt")).expect("Unable to create file"); - let new_key = Keypair::random(); - let pubkeybytes = PublicKeyBytes::from(new_key.pk); - let contents = "default:nice-graffiti"; - file.write_all(contents.as_bytes()) - .expect("Unable to write to file"); - CommandLineTest::new() - .flag( - "graffiti-file", - dir.path().join("graffiti.txt").as_os_str().to_str(), - ) - .run() - .with_config(|config| { - // Public key not present so load default. - assert_eq!( - config - .graffiti_file - .clone() - .unwrap() - .load_graffiti(&pubkeybytes) - .unwrap() - .unwrap() - .to_string(), - "0x6e6963652d677261666669746900000000000000000000000000000000000000" - ) - }); -} -#[test] -fn graffiti_file_with_pk_flag() { - let dir = TempDir::new().expect("Unable to create temporary directory"); - let mut file = File::create(dir.path().join("graffiti.txt")).expect("Unable to create file"); - let new_key = Keypair::random(); - let pubkeybytes = PublicKeyBytes::from(new_key.pk); - let contents = format!("{}:nice-graffiti", pubkeybytes.to_string()); - file.write_all(contents.as_bytes()) - .expect("Unable to write to file"); - CommandLineTest::new() - .flag( - "graffiti-file", - dir.path().join("graffiti.txt").as_os_str().to_str(), - ) - .run() - .with_config(|config| { - assert_eq!( - config - .graffiti_file - .clone() - .unwrap() - .load_graffiti(&pubkeybytes) - .unwrap() - .unwrap() - .to_string(), - "0x6e6963652d677261666669746900000000000000000000000000000000000000" - ) - }); -} - -// Tests for suggested-fee-recipient flags. -#[test] -fn fee_recipient_flag() { - CommandLineTest::new() - .flag( - "suggested-fee-recipient", - Some("0x00000000219ab540356cbb839cbe05303d7705fa"), - ) - .run() - .with_config(|config| { - assert_eq!( - config.fee_recipient, - Some(Address::from_str("0x00000000219ab540356cbb839cbe05303d7705fa").unwrap()) - ) - }); -} - -// Tests for HTTP flags. -#[test] -fn http_flag() { - CommandLineTest::new() - .flag("http", None) - .run() - .with_config(|config| assert!(config.http_api.enabled)); -} -#[test] -fn http_address_flag() { - let addr = "127.0.0.99".parse::().unwrap(); - CommandLineTest::new() - .flag("http", None) - .flag("http-address", Some("127.0.0.99")) - .flag("unencrypted-http-transport", None) - .run() - .with_config(|config| assert_eq!(config.http_api.listen_addr, addr)); -} -#[test] -fn http_address_ipv6_flag() { - let addr = "::1".parse::().unwrap(); - CommandLineTest::new() - .flag("http", None) - .flag("http-address", Some("::1")) - .flag("unencrypted-http-transport", None) - .run() - .with_config(|config| assert_eq!(config.http_api.listen_addr, addr)); -} -#[test] -#[should_panic] -fn missing_unencrypted_http_transport_flag() { - let addr = "127.0.0.99".parse::().unwrap(); - CommandLineTest::new() - .flag("http", None) - .flag("http-address", Some("127.0.0.99")) - .run() - .with_config(|config| assert_eq!(config.http_api.listen_addr, addr)); -} -#[test] -fn http_port_flag() { - CommandLineTest::new() - .flag("http", None) - .flag("http-port", Some("9090")) - .run() - .with_config(|config| assert_eq!(config.http_api.listen_port, 9090)); -} -#[test] -fn http_allow_origin_flag() { - CommandLineTest::new() - .flag("http", None) - .flag("http-allow-origin", Some("http://localhost:9009")) - .run() - .with_config(|config| { - assert_eq!( - config.http_api.allow_origin, - Some("http://localhost:9009".to_string()) - ); - }); -} -#[test] -fn http_allow_origin_all_flag() { - CommandLineTest::new() - .flag("http", None) - .flag("http-allow-origin", Some("*")) - .run() - .with_config(|config| assert_eq!(config.http_api.allow_origin, Some("*".to_string()))); -} -#[test] -fn http_allow_keystore_export_default() { - CommandLineTest::new() - .flag("http", None) - .run() - .with_config(|config| assert!(!config.http_api.allow_keystore_export)); -} -#[test] -fn http_allow_keystore_export_present() { - CommandLineTest::new() - .flag("http", None) - .flag("http-allow-keystore-export", None) - .run() - .with_config(|config| assert!(config.http_api.allow_keystore_export)); -} -#[test] -fn http_store_keystore_passwords_in_secrets_dir_default() { - CommandLineTest::new() - .flag("http", None) - .run() - .with_config(|config| assert!(!config.http_api.store_passwords_in_secrets_dir)); -} -#[test] -fn http_store_keystore_passwords_in_secrets_dir_present() { - CommandLineTest::new() - .flag("http", None) - .flag("http-store-passwords-in-secrets-dir", None) - .run() - .with_config(|config| assert!(config.http_api.store_passwords_in_secrets_dir)); -} - -// Tests for Metrics flags. -#[test] -fn metrics_flag() { - CommandLineTest::new() - .flag("metrics", None) - .run() - .with_config(|config| assert!(config.http_metrics.enabled)); -} -#[test] -fn metrics_address_flag() { - let addr = "127.0.0.99".parse::().unwrap(); - CommandLineTest::new() - .flag("metrics", None) - .flag("metrics-address", Some("127.0.0.99")) - .run() - .with_config(|config| assert_eq!(config.http_metrics.listen_addr, addr)); -} -#[test] -fn metrics_address_ipv6_flag() { - let addr = "::1".parse::().unwrap(); - CommandLineTest::new() - .flag("metrics", None) - .flag("metrics-address", Some("::1")) - .run() - .with_config(|config| assert_eq!(config.http_metrics.listen_addr, addr)); -} -#[test] -fn metrics_port_flag() { - CommandLineTest::new() - .flag("metrics", None) - .flag("metrics-port", Some("9090")) - .run() - .with_config(|config| assert_eq!(config.http_metrics.listen_port, 9090)); -} -#[test] -fn metrics_allow_origin_flag() { - CommandLineTest::new() - .flag("metrics", None) - .flag("metrics-allow-origin", Some("http://localhost:9009")) - .run() - .with_config(|config| { - assert_eq!( - config.http_metrics.allow_origin, - Some("http://localhost:9009".to_string()) - ); - }); -} -#[test] -fn metrics_allow_origin_all_flag() { - CommandLineTest::new() - .flag("metrics", None) - .flag("metrics-allow-origin", Some("*")) - .run() - .with_config(|config| assert_eq!(config.http_metrics.allow_origin, Some("*".to_string()))); -} -#[test] -pub fn malloc_tuning_flag() { - CommandLineTest::new() - .flag("disable-malloc-tuning", None) - .run() - .with_config(|config| assert_eq!(config.http_metrics.allocator_metrics_enabled, false)); -} -#[test] -pub fn malloc_tuning_default() { - CommandLineTest::new() - .run() - .with_config(|config| assert_eq!(config.http_metrics.allocator_metrics_enabled, true)); -} -#[test] -fn doppelganger_protection_flag() { - CommandLineTest::new() - .flag("enable-doppelganger-protection", None) - .run() - .with_config(|config| assert!(config.enable_doppelganger_protection)); -} -#[test] -fn no_doppelganger_protection_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert!(!config.enable_doppelganger_protection)); -} -#[test] -fn produce_block_v3_flag() { - CommandLineTest::new() - .flag("produce-block-v3", None) - .run() - .with_config(|config| assert!(config.produce_block_v3)); -} - -#[test] -fn no_produce_block_v3_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert!(!config.produce_block_v3)); -} - -#[test] -fn no_gas_limit_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert!(config.gas_limit.is_none())); -} -#[test] -fn gas_limit_flag() { - CommandLineTest::new() - .flag("gas-limit", Some("600")) - .flag("builder-proposals", None) - .run() - .with_config(|config| assert_eq!(config.gas_limit, Some(600))); -} -#[test] -fn no_builder_proposals_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert!(!config.builder_proposals)); -} -#[test] -fn builder_proposals_flag() { - CommandLineTest::new() - .flag("builder-proposals", None) - .run() - .with_config(|config| assert!(config.builder_proposals)); -} -#[test] -fn builder_boost_factor_flag() { - CommandLineTest::new() - .flag("builder-boost-factor", Some("150")) - .run() - .with_config(|config| assert_eq!(config.builder_boost_factor, Some(150))); -} -#[test] -fn no_builder_boost_factor_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert_eq!(config.builder_boost_factor, None)); -} -#[test] -fn prefer_builder_proposals_flag() { - CommandLineTest::new() - .flag("prefer-builder-proposals", None) - .run() - .with_config(|config| assert!(config.prefer_builder_proposals)); -} -#[test] -fn no_prefer_builder_proposals_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert!(!config.prefer_builder_proposals)); -} -#[test] -fn no_builder_registration_timestamp_override_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert!(config.builder_registration_timestamp_override.is_none())); -} -#[test] -fn builder_registration_timestamp_override_flag() { - CommandLineTest::new() - .flag("builder-registration-timestamp-override", Some("100")) - .run() - .with_config(|config| { - assert_eq!(config.builder_registration_timestamp_override, Some(100)) - }); -} -#[test] -fn monitoring_endpoint() { - CommandLineTest::new() - .flag("monitoring-endpoint", Some("http://example:8000")) - .flag("monitoring-endpoint-period", Some("30")) - .run() - .with_config(|config| { - let api_conf = config.monitoring_api.as_ref().unwrap(); - assert_eq!(api_conf.monitoring_endpoint.as_str(), "http://example:8000"); - assert_eq!(api_conf.update_period_secs, Some(30)); - }); -} -#[test] -fn disable_run_on_all_flag() { - CommandLineTest::new() - .flag("disable-run-on-all", None) - .run() - .with_config(|config| { - assert_eq!(config.broadcast_topics, vec![]); - }); - // --broadcast flag takes precedence - CommandLineTest::new() - .flag("disable-run-on-all", None) - .flag("broadcast", Some("attestations")) - .run() - .with_config(|config| { - assert_eq!(config.broadcast_topics, vec![ApiTopic::Attestations]); - }); -} - -#[test] -fn no_broadcast_flag() { - CommandLineTest::new().run().with_config(|config| { - assert_eq!(config.broadcast_topics, vec![ApiTopic::Subscriptions]); - }); -} - -#[test] -fn broadcast_flag() { - // "none" variant - CommandLineTest::new() - .flag("broadcast", Some("none")) - .run() - .with_config(|config| { - assert_eq!(config.broadcast_topics, vec![]); - }); - // "none" with other values is ignored - CommandLineTest::new() - .flag("broadcast", Some("none,sync-committee")) - .run() - .with_config(|config| { - assert_eq!(config.broadcast_topics, vec![ApiTopic::SyncCommittee]); - }); - // Other valid variants - CommandLineTest::new() - .flag("broadcast", Some("blocks, subscriptions")) - .run() - .with_config(|config| { - assert_eq!( - config.broadcast_topics, - vec![ApiTopic::Blocks, ApiTopic::Subscriptions], - ); - }); - // Omitted "subscription" overrides default - CommandLineTest::new() - .flag("broadcast", Some("attestations")) - .run() - .with_config(|config| { - assert_eq!(config.broadcast_topics, vec![ApiTopic::Attestations]); - }); -} - -/// Tests for validator fallback flags. -#[test] -fn beacon_nodes_sync_tolerances_flag_default() { - CommandLineTest::new().run().with_config(|config| { - assert_eq!( - config.beacon_node_fallback.sync_tolerances, - BeaconNodeSyncDistanceTiers::default() - ) - }); -} -#[test] -fn beacon_nodes_sync_tolerances_flag() { - CommandLineTest::new() - .flag("beacon-nodes-sync-tolerances", Some("4,4,4")) - .run() - .with_config(|config| { - assert_eq!( - config.beacon_node_fallback.sync_tolerances, - BeaconNodeSyncDistanceTiers { - synced: Slot::new(4), - small: Slot::new(8), - medium: Slot::new(12), - } - ); - }); -} - -#[test] -#[should_panic(expected = "Unknown API topic")] -fn wrong_broadcast_flag() { - CommandLineTest::new() - .flag("broadcast", Some("foo, subscriptions")) - .run() - .with_config(|config| { - assert_eq!( - config.broadcast_topics, - vec![ApiTopic::Blocks, ApiTopic::Subscriptions], - ); - }); -} - -#[test] -fn latency_measurement_service() { - CommandLineTest::new().run().with_config(|config| { - assert!(config.enable_latency_measurement_service); - }); - CommandLineTest::new() - .flag("latency-measurement-service", None) - .run() - .with_config(|config| { - assert!(config.enable_latency_measurement_service); - }); - CommandLineTest::new() - .flag("latency-measurement-service", Some("true")) - .run() - .with_config(|config| { - assert!(config.enable_latency_measurement_service); - }); - CommandLineTest::new() - .flag("latency-measurement-service", Some("false")) - .run() - .with_config(|config| { - assert!(!config.enable_latency_measurement_service); - }); -} - -#[test] -fn validator_registration_batch_size() { - CommandLineTest::new().run().with_config(|config| { - assert_eq!(config.validator_registration_batch_size, 500); - }); - CommandLineTest::new() - .flag("validator-registration-batch-size", Some("100")) - .run() - .with_config(|config| { - assert_eq!(config.validator_registration_batch_size, 100); - }); -} - -#[test] -#[should_panic] -fn validator_registration_batch_size_zero_value() { - CommandLineTest::new() - .flag("validator-registration-batch-size", Some("0")) - .run(); -} - -#[test] -fn validator_disable_web3_signer_slashing_protection_default() { - CommandLineTest::new().run().with_config(|config| { - assert!(config.enable_web3signer_slashing_protection); - }); -} - -#[test] -fn validator_disable_web3_signer_slashing_protection() { - CommandLineTest::new() - .flag("disable-slashing-protection-web3signer", None) - .run() - .with_config(|config| { - assert!(!config.enable_web3signer_slashing_protection); - }); -} diff --git a/lighthouse/tests/validator_client_REMOTE_4094175.rs b/lighthouse/tests/validator_client_REMOTE_4094175.rs deleted file mode 100644 index cdf8fa15aa..0000000000 --- a/lighthouse/tests/validator_client_REMOTE_4094175.rs +++ /dev/null @@ -1,679 +0,0 @@ -use validator_client::{config::DEFAULT_WEB3SIGNER_KEEP_ALIVE, ApiTopic, Config}; - -use crate::exec::CommandLineTestExec; -use bls::{Keypair, PublicKeyBytes}; -use std::fs::File; -use std::io::Write; -use std::net::IpAddr; -use std::path::PathBuf; -use std::process::Command; -use std::str::FromStr; -use std::string::ToString; -use std::time::Duration; -use tempfile::TempDir; -use types::Address; - -/// Returns the `lighthouse validator_client` command. -fn base_cmd() -> Command { - let lighthouse_bin = env!("CARGO_BIN_EXE_lighthouse"); - let path = lighthouse_bin - .parse::() - .expect("should parse CARGO_TARGET_DIR"); - - let mut cmd = Command::new(path); - cmd.arg("validator_client"); - cmd -} - -// Wrapper around `Command` for easier Command Line Testing. -struct CommandLineTest { - cmd: Command, -} -impl CommandLineTest { - fn new() -> CommandLineTest { - let base_cmd = base_cmd(); - CommandLineTest { cmd: base_cmd } - } -} - -impl CommandLineTestExec for CommandLineTest { - type Config = Config; - - fn cmd_mut(&mut self) -> &mut Command { - &mut self.cmd - } -} - -#[test] -fn datadir_flag() { - CommandLineTest::new() - .run() - .with_config_and_dir(|config, dir| { - assert_eq!(config.validator_dir, dir.path().join("validators")); - assert_eq!(config.secrets_dir, dir.path().join("secrets")); - }); -} - -#[test] -fn validators_and_secrets_dir_flags() { - let dir = TempDir::new().expect("Unable to create temporary directory"); - CommandLineTest::new() - .flag("validators-dir", dir.path().join("validators").to_str()) - .flag("secrets-dir", dir.path().join("secrets").to_str()) - .run_with_no_datadir() - .with_config(|config| { - assert_eq!(config.validator_dir, dir.path().join("validators")); - assert_eq!(config.secrets_dir, dir.path().join("secrets")); - }); -} - -#[test] -fn validators_dir_alias_flags() { - let dir = TempDir::new().expect("Unable to create temporary directory"); - CommandLineTest::new() - .flag("validator-dir", dir.path().join("validators").to_str()) - .flag("secrets-dir", dir.path().join("secrets").to_str()) - .run_with_no_datadir() - .with_config(|config| { - assert_eq!(config.validator_dir, dir.path().join("validators")); - assert_eq!(config.secrets_dir, dir.path().join("secrets")); - }); -} - -#[test] -fn beacon_nodes_flag() { - CommandLineTest::new() - .flag( - "beacon-nodes", - Some("http://localhost:1001,https://project:secret@infura.io/"), - ) - .run() - .with_config(|config| { - assert_eq!( - config.beacon_nodes[0].full.to_string(), - "http://localhost:1001/" - ); - assert_eq!(config.beacon_nodes[0].to_string(), "http://localhost:1001/"); - assert_eq!( - config.beacon_nodes[1].full.to_string(), - "https://project:secret@infura.io/" - ); - assert_eq!(config.beacon_nodes[1].to_string(), "https://infura.io/"); - }); -} - -#[test] -fn disable_auto_discover_flag() { - CommandLineTest::new() - .flag("disable-auto-discover", None) - .run() - .with_config(|config| assert!(config.disable_auto_discover)); -} - -#[test] -fn init_slashing_protections_flag() { - CommandLineTest::new() - .flag("init-slashing-protection", None) - .run() - .with_config(|config| assert!(config.init_slashing_protection)); -} - -#[test] -fn use_long_timeouts_flag() { - CommandLineTest::new() - .flag("use-long-timeouts", None) - .run() - .with_config(|config| assert!(config.use_long_timeouts)); -} - -#[test] -fn beacon_nodes_tls_certs_flag() { - let dir = TempDir::new().expect("Unable to create temporary directory"); - CommandLineTest::new() - .flag( - "beacon-nodes-tls-certs", - Some( - vec![ - dir.path().join("certificate.crt").to_str().unwrap(), - dir.path().join("certificate2.crt").to_str().unwrap(), - ] - .join(",") - .as_str(), - ), - ) - .run() - .with_config(|config| { - assert_eq!( - config.beacon_nodes_tls_certs, - Some(vec![ - dir.path().join("certificate.crt"), - dir.path().join("certificate2.crt") - ]) - ) - }); -} - -// Tests for Graffiti flags. -#[test] -fn graffiti_flag() { - CommandLineTest::new() - .flag("graffiti", Some("nice-graffiti")) - .run() - .with_config(|config| { - assert_eq!( - config.graffiti.unwrap().to_string(), - "0x6e6963652d677261666669746900000000000000000000000000000000000000" - ) - }); -} -#[test] -fn graffiti_file_flag() { - let dir = TempDir::new().expect("Unable to create temporary directory"); - let mut file = File::create(dir.path().join("graffiti.txt")).expect("Unable to create file"); - let new_key = Keypair::random(); - let pubkeybytes = PublicKeyBytes::from(new_key.pk); - let contents = "default:nice-graffiti"; - file.write_all(contents.as_bytes()) - .expect("Unable to write to file"); - CommandLineTest::new() - .flag( - "graffiti-file", - dir.path().join("graffiti.txt").as_os_str().to_str(), - ) - .run() - .with_config(|config| { - // Public key not present so load default. - assert_eq!( - config - .graffiti_file - .clone() - .unwrap() - .load_graffiti(&pubkeybytes) - .unwrap() - .unwrap() - .to_string(), - "0x6e6963652d677261666669746900000000000000000000000000000000000000" - ) - }); -} -#[test] -fn graffiti_file_with_pk_flag() { - let dir = TempDir::new().expect("Unable to create temporary directory"); - let mut file = File::create(dir.path().join("graffiti.txt")).expect("Unable to create file"); - let new_key = Keypair::random(); - let pubkeybytes = PublicKeyBytes::from(new_key.pk); - let contents = format!("{}:nice-graffiti", pubkeybytes.to_string()); - file.write_all(contents.as_bytes()) - .expect("Unable to write to file"); - CommandLineTest::new() - .flag( - "graffiti-file", - dir.path().join("graffiti.txt").as_os_str().to_str(), - ) - .run() - .with_config(|config| { - assert_eq!( - config - .graffiti_file - .clone() - .unwrap() - .load_graffiti(&pubkeybytes) - .unwrap() - .unwrap() - .to_string(), - "0x6e6963652d677261666669746900000000000000000000000000000000000000" - ) - }); -} - -// Tests for suggested-fee-recipient flags. -#[test] -fn fee_recipient_flag() { - CommandLineTest::new() - .flag( - "suggested-fee-recipient", - Some("0x00000000219ab540356cbb839cbe05303d7705fa"), - ) - .run() - .with_config(|config| { - assert_eq!( - config.fee_recipient, - Some(Address::from_str("0x00000000219ab540356cbb839cbe05303d7705fa").unwrap()) - ) - }); -} - -// Tests for HTTP flags. -#[test] -fn http_flag() { - CommandLineTest::new() - .flag("http", None) - .run() - .with_config(|config| assert!(config.http_api.enabled)); -} -#[test] -fn http_address_flag() { - let addr = "127.0.0.99".parse::().unwrap(); - CommandLineTest::new() - .flag("http", None) - .flag("http-address", Some("127.0.0.99")) - .flag("unencrypted-http-transport", None) - .run() - .with_config(|config| assert_eq!(config.http_api.listen_addr, addr)); -} -#[test] -fn http_address_ipv6_flag() { - let addr = "::1".parse::().unwrap(); - CommandLineTest::new() - .flag("http", None) - .flag("http-address", Some("::1")) - .flag("unencrypted-http-transport", None) - .run() - .with_config(|config| assert_eq!(config.http_api.listen_addr, addr)); -} -#[test] -#[should_panic] -fn missing_unencrypted_http_transport_flag() { - let addr = "127.0.0.99".parse::().unwrap(); - CommandLineTest::new() - .flag("http", None) - .flag("http-address", Some("127.0.0.99")) - .run() - .with_config(|config| assert_eq!(config.http_api.listen_addr, addr)); -} -#[test] -fn http_port_flag() { - CommandLineTest::new() - .flag("http", None) - .flag("http-port", Some("9090")) - .run() - .with_config(|config| assert_eq!(config.http_api.listen_port, 9090)); -} -#[test] -fn http_allow_origin_flag() { - CommandLineTest::new() - .flag("http", None) - .flag("http-allow-origin", Some("http://localhost:9009")) - .run() - .with_config(|config| { - assert_eq!( - config.http_api.allow_origin, - Some("http://localhost:9009".to_string()) - ); - }); -} -#[test] -fn http_allow_origin_all_flag() { - CommandLineTest::new() - .flag("http", None) - .flag("http-allow-origin", Some("*")) - .run() - .with_config(|config| assert_eq!(config.http_api.allow_origin, Some("*".to_string()))); -} -#[test] -fn http_allow_keystore_export_default() { - CommandLineTest::new() - .flag("http", None) - .run() - .with_config(|config| assert!(!config.http_api.allow_keystore_export)); -} -#[test] -fn http_allow_keystore_export_present() { - CommandLineTest::new() - .flag("http", None) - .flag("http-allow-keystore-export", None) - .run() - .with_config(|config| assert!(config.http_api.allow_keystore_export)); -} -#[test] -fn http_store_keystore_passwords_in_secrets_dir_default() { - CommandLineTest::new() - .flag("http", None) - .run() - .with_config(|config| assert!(!config.http_api.store_passwords_in_secrets_dir)); -} -#[test] -fn http_store_keystore_passwords_in_secrets_dir_present() { - CommandLineTest::new() - .flag("http", None) - .flag("http-store-passwords-in-secrets-dir", None) - .run() - .with_config(|config| assert!(config.http_api.store_passwords_in_secrets_dir)); -} - -// Tests for Metrics flags. -#[test] -fn metrics_flag() { - CommandLineTest::new() - .flag("metrics", None) - .run() - .with_config(|config| assert!(config.http_metrics.enabled)); -} -#[test] -fn metrics_address_flag() { - let addr = "127.0.0.99".parse::().unwrap(); - CommandLineTest::new() - .flag("metrics", None) - .flag("metrics-address", Some("127.0.0.99")) - .run() - .with_config(|config| assert_eq!(config.http_metrics.listen_addr, addr)); -} -#[test] -fn metrics_address_ipv6_flag() { - let addr = "::1".parse::().unwrap(); - CommandLineTest::new() - .flag("metrics", None) - .flag("metrics-address", Some("::1")) - .run() - .with_config(|config| assert_eq!(config.http_metrics.listen_addr, addr)); -} -#[test] -fn metrics_port_flag() { - CommandLineTest::new() - .flag("metrics", None) - .flag("metrics-port", Some("9090")) - .run() - .with_config(|config| assert_eq!(config.http_metrics.listen_port, 9090)); -} -#[test] -fn metrics_allow_origin_flag() { - CommandLineTest::new() - .flag("metrics", None) - .flag("metrics-allow-origin", Some("http://localhost:9009")) - .run() - .with_config(|config| { - assert_eq!( - config.http_metrics.allow_origin, - Some("http://localhost:9009".to_string()) - ); - }); -} -#[test] -fn metrics_allow_origin_all_flag() { - CommandLineTest::new() - .flag("metrics", None) - .flag("metrics-allow-origin", Some("*")) - .run() - .with_config(|config| assert_eq!(config.http_metrics.allow_origin, Some("*".to_string()))); -} -#[test] -pub fn malloc_tuning_flag() { - CommandLineTest::new() - .flag("disable-malloc-tuning", None) - .run() - .with_config(|config| assert_eq!(config.http_metrics.allocator_metrics_enabled, false)); -} -#[test] -pub fn malloc_tuning_default() { - CommandLineTest::new() - .run() - .with_config(|config| assert_eq!(config.http_metrics.allocator_metrics_enabled, true)); -} -#[test] -fn doppelganger_protection_flag() { - CommandLineTest::new() - .flag("enable-doppelganger-protection", None) - .run() - .with_config(|config| assert!(config.enable_doppelganger_protection)); -} -#[test] -fn no_doppelganger_protection_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert!(!config.enable_doppelganger_protection)); -} -#[test] -fn produce_block_v3_flag() { - CommandLineTest::new() - .flag("produce-block-v3", None) - .run() - .with_config(|config| assert!(config.produce_block_v3)); -} - -#[test] -fn no_produce_block_v3_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert!(!config.produce_block_v3)); -} - -#[test] -fn no_gas_limit_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert!(config.gas_limit.is_none())); -} -#[test] -fn gas_limit_flag() { - CommandLineTest::new() - .flag("gas-limit", Some("600")) - .flag("builder-proposals", None) - .run() - .with_config(|config| assert_eq!(config.gas_limit, Some(600))); -} -#[test] -fn no_builder_proposals_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert!(!config.builder_proposals)); -} -#[test] -fn builder_proposals_flag() { - CommandLineTest::new() - .flag("builder-proposals", None) - .run() - .with_config(|config| assert!(config.builder_proposals)); -} -#[test] -fn builder_boost_factor_flag() { - CommandLineTest::new() - .flag("builder-boost-factor", Some("150")) - .run() - .with_config(|config| assert_eq!(config.builder_boost_factor, Some(150))); -} -#[test] -fn no_builder_boost_factor_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert_eq!(config.builder_boost_factor, None)); -} -#[test] -fn prefer_builder_proposals_flag() { - CommandLineTest::new() - .flag("prefer-builder-proposals", None) - .run() - .with_config(|config| assert!(config.prefer_builder_proposals)); -} -#[test] -fn no_prefer_builder_proposals_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert!(!config.prefer_builder_proposals)); -} -#[test] -fn no_builder_registration_timestamp_override_flag() { - CommandLineTest::new() - .run() - .with_config(|config| assert!(config.builder_registration_timestamp_override.is_none())); -} -#[test] -fn builder_registration_timestamp_override_flag() { - CommandLineTest::new() - .flag("builder-registration-timestamp-override", Some("100")) - .run() - .with_config(|config| { - assert_eq!(config.builder_registration_timestamp_override, Some(100)) - }); -} -#[test] -fn monitoring_endpoint() { - CommandLineTest::new() - .flag("monitoring-endpoint", Some("http://example:8000")) - .flag("monitoring-endpoint-period", Some("30")) - .run() - .with_config(|config| { - let api_conf = config.monitoring_api.as_ref().unwrap(); - assert_eq!(api_conf.monitoring_endpoint.as_str(), "http://example:8000"); - assert_eq!(api_conf.update_period_secs, Some(30)); - }); -} - -#[test] -fn disable_run_on_all_flag() { - CommandLineTest::new() - .flag("disable-run-on-all", None) - .run() - .with_config(|config| { - assert_eq!(config.broadcast_topics, vec![]); - }); - // --broadcast flag takes precedence - CommandLineTest::new() - .flag("disable-run-on-all", None) - .flag("broadcast", Some("attestations")) - .run() - .with_config(|config| { - assert_eq!(config.broadcast_topics, vec![ApiTopic::Attestations]); - }); -} - -#[test] -fn no_broadcast_flag() { - CommandLineTest::new().run().with_config(|config| { - assert_eq!(config.broadcast_topics, vec![ApiTopic::Subscriptions]); - }); -} - -#[test] -fn broadcast_flag() { - // "none" variant - CommandLineTest::new() - .flag("broadcast", Some("none")) - .run() - .with_config(|config| { - assert_eq!(config.broadcast_topics, vec![]); - }); - // "none" with other values is ignored - CommandLineTest::new() - .flag("broadcast", Some("none,sync-committee")) - .run() - .with_config(|config| { - assert_eq!(config.broadcast_topics, vec![ApiTopic::SyncCommittee]); - }); - // Other valid variants - CommandLineTest::new() - .flag("broadcast", Some("blocks, subscriptions")) - .run() - .with_config(|config| { - assert_eq!( - config.broadcast_topics, - vec![ApiTopic::Blocks, ApiTopic::Subscriptions], - ); - }); - // Omitted "subscription" overrides default - CommandLineTest::new() - .flag("broadcast", Some("attestations")) - .run() - .with_config(|config| { - assert_eq!(config.broadcast_topics, vec![ApiTopic::Attestations]); - }); -} - -#[test] -#[should_panic(expected = "Unknown API topic")] -fn wrong_broadcast_flag() { - CommandLineTest::new() - .flag("broadcast", Some("foo, subscriptions")) - .run() - .with_config(|config| { - assert_eq!( - config.broadcast_topics, - vec![ApiTopic::Blocks, ApiTopic::Subscriptions], - ); - }); -} - -#[test] -fn latency_measurement_service() { - CommandLineTest::new().run().with_config(|config| { - assert!(config.enable_latency_measurement_service); - }); - CommandLineTest::new() - .flag("latency-measurement-service", None) - .run() - .with_config(|config| { - assert!(config.enable_latency_measurement_service); - }); - CommandLineTest::new() - .flag("latency-measurement-service", Some("true")) - .run() - .with_config(|config| { - assert!(config.enable_latency_measurement_service); - }); - CommandLineTest::new() - .flag("latency-measurement-service", Some("false")) - .run() - .with_config(|config| { - assert!(!config.enable_latency_measurement_service); - }); -} - -#[test] -fn validator_registration_batch_size() { - CommandLineTest::new().run().with_config(|config| { - assert_eq!(config.validator_registration_batch_size, 500); - }); - CommandLineTest::new() - .flag("validator-registration-batch-size", Some("100")) - .run() - .with_config(|config| { - assert_eq!(config.validator_registration_batch_size, 100); - }); -} - -#[test] -#[should_panic] -fn validator_registration_batch_size_zero_value() { - CommandLineTest::new() - .flag("validator-registration-batch-size", Some("0")) - .run(); -} - -#[test] -fn validator_disable_web3_signer_slashing_protection_default() { - CommandLineTest::new().run().with_config(|config| { - assert!(config.enable_web3signer_slashing_protection); - }); -} - -#[test] -fn validator_disable_web3_signer_slashing_protection() { - CommandLineTest::new() - .flag("disable-slashing-protection-web3signer", None) - .run() - .with_config(|config| { - assert!(!config.enable_web3signer_slashing_protection); - }); -} - -#[test] -fn validator_web3_signer_keep_alive_default() { - CommandLineTest::new().run().with_config(|config| { - assert_eq!( - config.web3_signer_keep_alive_timeout, - DEFAULT_WEB3SIGNER_KEEP_ALIVE - ); - }); -} - -#[test] -fn validator_web3_signer_keep_alive_override() { - CommandLineTest::new() - .flag("web3-signer-keep-alive-timeout", Some("1000")) - .run() - .with_config(|config| { - assert_eq!( - config.web3_signer_keep_alive_timeout, - Some(Duration::from_secs(1)) - ); - }); -}