Enable lints for tests only running optimized (#6664)

* enable linting optimized-only tests

* fix automatically fixable or obvious lints

* fix suspicious_open_options by removing manual options

* fix `await_holding_lock`s

* avoid failing lint due to now disabled `#[cfg(debug_assertions)]`

* reduce future sizes in tests

* fix accidently flipped assert logic

* restore holding lock for web3signer download

* Merge branch 'unstable' into lint-opt-tests
This commit is contained in:
Daniel Knopik
2024-12-17 01:40:35 +01:00
committed by GitHub
parent 847c8019c7
commit 02cb2d68ff
34 changed files with 572 additions and 574 deletions

View File

@@ -115,7 +115,7 @@ fn create_wallet<P: AsRef<Path>>(
.arg(base_dir.as_ref().as_os_str())
.arg(CREATE_CMD)
.arg(format!("--{}", NAME_FLAG))
.arg(&name)
.arg(name)
.arg(format!("--{}", PASSWORD_FLAG))
.arg(password.as_ref().as_os_str())
.arg(format!("--{}", MNEMONIC_FLAG))
@@ -273,16 +273,16 @@ impl TestValidator {
.expect("stdout is not utf8")
.to_string();
if stdout == "" {
if stdout.is_empty() {
return Ok(vec![]);
}
let pubkeys = stdout[..stdout.len() - 1]
.split("\n")
.filter_map(|line| {
.map(|line| {
let tab = line.find("\t").expect("line must have tab");
let (_, pubkey) = line.split_at(tab + 1);
Some(pubkey.to_string())
pubkey.to_string()
})
.collect::<Vec<_>>();
@@ -446,7 +446,9 @@ fn validator_import_launchpad() {
}
}
stdin.write(format!("{}\n", PASSWORD).as_bytes()).unwrap();
stdin
.write_all(format!("{}\n", PASSWORD).as_bytes())
.unwrap();
child.wait().unwrap();
@@ -504,7 +506,7 @@ fn validator_import_launchpad() {
};
assert!(
defs.as_slice() == &[expected_def.clone()],
defs.as_slice() == [expected_def.clone()],
"validator defs file should be accurate"
);
@@ -525,7 +527,7 @@ fn validator_import_launchpad() {
expected_def.enabled = true;
assert!(
defs.as_slice() == &[expected_def.clone()],
defs.as_slice() == [expected_def.clone()],
"validator defs file should be accurate"
);
}
@@ -582,7 +584,7 @@ fn validator_import_launchpad_no_password_then_add_password() {
let mut child = validator_import_key_cmd();
wait_for_password_prompt(&mut child);
let stdin = child.stdin.as_mut().unwrap();
stdin.write("\n".as_bytes()).unwrap();
stdin.write_all("\n".as_bytes()).unwrap();
child.wait().unwrap();
assert!(
@@ -628,14 +630,16 @@ fn validator_import_launchpad_no_password_then_add_password() {
};
assert!(
defs.as_slice() == &[expected_def.clone()],
defs.as_slice() == [expected_def.clone()],
"validator defs file should be accurate"
);
let mut child = validator_import_key_cmd();
wait_for_password_prompt(&mut child);
let stdin = child.stdin.as_mut().unwrap();
stdin.write(format!("{}\n", PASSWORD).as_bytes()).unwrap();
stdin
.write_all(format!("{}\n", PASSWORD).as_bytes())
.unwrap();
child.wait().unwrap();
let expected_def = ValidatorDefinition {
@@ -657,7 +661,7 @@ fn validator_import_launchpad_no_password_then_add_password() {
let defs = ValidatorDefinitions::open(&dst_dir).unwrap();
assert!(
defs.as_slice() == &[expected_def.clone()],
defs.as_slice() == [expected_def.clone()],
"validator defs file should be accurate"
);
}
@@ -759,7 +763,7 @@ fn validator_import_launchpad_password_file() {
};
assert!(
defs.as_slice() == &[expected_def],
defs.as_slice() == [expected_def],
"validator defs file should be accurate"
);
}

View File

@@ -9,7 +9,6 @@ use beacon_node::beacon_chain::graffiti_calculator::GraffitiOrigin;
use beacon_processor::BeaconProcessorConfig;
use eth1::Eth1Endpoint;
use lighthouse_network::PeerId;
use lighthouse_version;
use std::fs::File;
use std::io::{Read, Write};
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
@@ -128,7 +127,7 @@ fn allow_insecure_genesis_sync_default() {
CommandLineTest::new()
.run_with_zero_port_and_no_genesis_sync()
.with_config(|config| {
assert_eq!(config.allow_insecure_genesis_sync, false);
assert!(!config.allow_insecure_genesis_sync);
});
}
@@ -146,7 +145,7 @@ fn allow_insecure_genesis_sync_enabled() {
.flag("allow-insecure-genesis-sync", None)
.run_with_zero_port_and_no_genesis_sync()
.with_config(|config| {
assert_eq!(config.allow_insecure_genesis_sync, true);
assert!(config.allow_insecure_genesis_sync);
});
}
@@ -359,11 +358,11 @@ fn default_graffiti() {
#[test]
fn trusted_peers_flag() {
let peers = vec![PeerId::random(), PeerId::random()];
let peers = [PeerId::random(), PeerId::random()];
CommandLineTest::new()
.flag(
"trusted-peers",
Some(format!("{},{}", peers[0].to_string(), peers[1].to_string()).as_str()),
Some(format!("{},{}", peers[0], peers[1]).as_str()),
)
.run_with_zero_port()
.with_config(|config| {
@@ -383,7 +382,7 @@ fn genesis_backfill_flag() {
CommandLineTest::new()
.flag("genesis-backfill", None)
.run_with_zero_port()
.with_config(|config| assert_eq!(config.chain.genesis_backfill, true));
.with_config(|config| assert!(config.chain.genesis_backfill));
}
/// The genesis backfill flag should be enabled if historic states flag is set.
@@ -392,7 +391,7 @@ fn genesis_backfill_with_historic_flag() {
CommandLineTest::new()
.flag("reconstruct-historic-states", None)
.run_with_zero_port()
.with_config(|config| assert_eq!(config.chain.genesis_backfill, true));
.with_config(|config| assert!(config.chain.genesis_backfill));
}
// Tests for Eth1 flags.
@@ -448,7 +447,7 @@ fn eth1_cache_follow_distance_manual() {
// Tests for Bellatrix flags.
fn run_bellatrix_execution_endpoints_flag_test(flag: &str) {
use sensitive_url::SensitiveUrl;
let urls = vec!["http://sigp.io/no-way:1337", "http://infura.not_real:4242"];
let urls = ["http://sigp.io/no-way:1337", "http://infura.not_real:4242"];
// we don't support redundancy for execution-endpoints
// only the first provided endpoint is parsed.
@@ -480,10 +479,10 @@ fn run_bellatrix_execution_endpoints_flag_test(flag: &str) {
.run_with_zero_port()
.with_config(|config| {
let config = config.execution_layer.as_ref().unwrap();
assert_eq!(config.execution_endpoint.is_some(), true);
assert!(config.execution_endpoint.is_some());
assert_eq!(
config.execution_endpoint.as_ref().unwrap().clone(),
SensitiveUrl::parse(&urls[0]).unwrap()
SensitiveUrl::parse(urls[0]).unwrap()
);
// Only the first secret file should be used.
assert_eq!(
@@ -595,7 +594,7 @@ fn run_payload_builder_flag_test(flag: &str, builders: &str) {
let config = config.execution_layer.as_ref().unwrap();
// Only first provided endpoint is parsed as we don't support
// redundancy.
assert_eq!(config.builder_url, all_builders.get(0).cloned());
assert_eq!(config.builder_url, all_builders.first().cloned());
})
}
fn run_payload_builder_flag_test_with_config<F: Fn(&Config)>(
@@ -661,7 +660,7 @@ fn builder_fallback_flags() {
Some("builder-fallback-disable-checks"),
None,
|config| {
assert_eq!(config.chain.builder_fallback_disable_checks, true);
assert!(config.chain.builder_fallback_disable_checks);
},
);
}
@@ -1657,19 +1656,19 @@ fn http_enable_beacon_processor() {
CommandLineTest::new()
.flag("http", None)
.run_with_zero_port()
.with_config(|config| assert_eq!(config.http_api.enable_beacon_processor, true));
.with_config(|config| assert!(config.http_api.enable_beacon_processor));
CommandLineTest::new()
.flag("http", None)
.flag("http-enable-beacon-processor", Some("true"))
.run_with_zero_port()
.with_config(|config| assert_eq!(config.http_api.enable_beacon_processor, true));
.with_config(|config| assert!(config.http_api.enable_beacon_processor));
CommandLineTest::new()
.flag("http", None)
.flag("http-enable-beacon-processor", Some("false"))
.run_with_zero_port()
.with_config(|config| assert_eq!(config.http_api.enable_beacon_processor, false));
.with_config(|config| assert!(!config.http_api.enable_beacon_processor));
}
#[test]
fn http_tls_flags() {
@@ -2221,7 +2220,7 @@ fn slasher_broadcast_flag_false() {
});
}
#[cfg(all(feature = "slasher-lmdb"))]
#[cfg(feature = "slasher-lmdb")]
#[test]
fn slasher_backend_override_to_default() {
// Hard to test this flag because all but one backend is disabled by default and the backend
@@ -2429,7 +2428,7 @@ fn logfile_no_restricted_perms_flag() {
.flag("logfile-no-restricted-perms", None)
.run_with_zero_port()
.with_config(|config| {
assert!(config.logger_config.is_restricted == false);
assert!(!config.logger_config.is_restricted);
});
}
#[test]
@@ -2454,7 +2453,7 @@ fn logfile_format_flag() {
fn sync_eth1_chain_default() {
CommandLineTest::new()
.run_with_zero_port()
.with_config(|config| assert_eq!(config.sync_eth1_chain, true));
.with_config(|config| assert!(config.sync_eth1_chain));
}
#[test]
@@ -2467,7 +2466,7 @@ fn sync_eth1_chain_execution_endpoints_flag() {
dir.path().join("jwt-file").as_os_str().to_str(),
)
.run_with_zero_port()
.with_config(|config| assert_eq!(config.sync_eth1_chain, true));
.with_config(|config| assert!(config.sync_eth1_chain));
}
#[test]
@@ -2481,7 +2480,7 @@ fn sync_eth1_chain_disable_deposit_contract_sync_flag() {
dir.path().join("jwt-file").as_os_str().to_str(),
)
.run_with_zero_port()
.with_config(|config| assert_eq!(config.sync_eth1_chain, false));
.with_config(|config| assert!(!config.sync_eth1_chain));
}
#[test]
@@ -2504,9 +2503,9 @@ fn light_client_server_default() {
CommandLineTest::new()
.run_with_zero_port()
.with_config(|config| {
assert_eq!(config.network.enable_light_client_server, false);
assert_eq!(config.chain.enable_light_client_server, false);
assert_eq!(config.http_api.enable_light_client_server, false);
assert!(!config.network.enable_light_client_server);
assert!(!config.chain.enable_light_client_server);
assert!(!config.http_api.enable_light_client_server);
});
}
@@ -2516,8 +2515,8 @@ fn light_client_server_enabled() {
.flag("light-client-server", None)
.run_with_zero_port()
.with_config(|config| {
assert_eq!(config.network.enable_light_client_server, true);
assert_eq!(config.chain.enable_light_client_server, true);
assert!(config.network.enable_light_client_server);
assert!(config.chain.enable_light_client_server);
});
}
@@ -2528,7 +2527,7 @@ fn light_client_http_server_enabled() {
.flag("light-client-server", None)
.run_with_zero_port()
.with_config(|config| {
assert_eq!(config.http_api.enable_light_client_server, true);
assert!(config.http_api.enable_light_client_server);
});
}

View File

@@ -149,7 +149,7 @@ fn disable_packet_filter_flag() {
.flag("disable-packet-filter", None)
.run_with_ip()
.with_config(|config| {
assert_eq!(config.disable_packet_filter, true);
assert!(config.disable_packet_filter);
});
}
@@ -159,7 +159,7 @@ fn enable_enr_auto_update_flag() {
.flag("enable-enr-auto-update", None)
.run_with_ip()
.with_config(|config| {
assert_eq!(config.enable_enr_auto_update, true);
assert!(config.enable_enr_auto_update);
});
}

View File

@@ -136,7 +136,7 @@ fn beacon_nodes_tls_certs_flag() {
.flag(
"beacon-nodes-tls-certs",
Some(
vec![
[
dir.path().join("certificate.crt").to_str().unwrap(),
dir.path().join("certificate2.crt").to_str().unwrap(),
]
@@ -205,7 +205,7 @@ fn graffiti_file_with_pk_flag() {
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());
let contents = format!("{}:nice-graffiti", pubkeybytes);
file.write_all(contents.as_bytes())
.expect("Unable to write to file");
CommandLineTest::new()
@@ -419,13 +419,13 @@ 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));
.with_config(|config| assert!(!config.http_metrics.allocator_metrics_enabled));
}
#[test]
pub fn malloc_tuning_default() {
CommandLineTest::new()
.run()
.with_config(|config| assert_eq!(config.http_metrics.allocator_metrics_enabled, true));
.with_config(|config| assert!(config.http_metrics.allocator_metrics_enabled));
}
#[test]
fn doppelganger_protection_flag() {

View File

@@ -136,7 +136,7 @@ pub fn validator_create_defaults() {
count: 1,
deposit_gwei: MainnetEthSpec::default_spec().max_effective_balance,
mnemonic_path: None,
stdin_inputs: cfg!(windows) || false,
stdin_inputs: cfg!(windows),
disable_deposits: false,
specify_voting_keystore_password: false,
eth1_withdrawal_address: None,
@@ -201,7 +201,7 @@ pub fn validator_create_disable_deposits() {
.flag("--disable-deposits", None)
.flag("--builder-proposals", Some("false"))
.assert_success(|config| {
assert_eq!(config.disable_deposits, true);
assert!(config.disable_deposits);
assert_eq!(config.builder_proposals, Some(false));
});
}
@@ -300,7 +300,7 @@ pub fn validator_move_defaults() {
fee_recipient: None,
gas_limit: None,
password_source: PasswordSource::Interactive {
stdin_inputs: cfg!(windows) || false,
stdin_inputs: cfg!(windows),
},
};
assert_eq!(expected, config);
@@ -350,7 +350,7 @@ pub fn validator_move_misc_flags_1() {
.flag("--src-vc-token", Some("./1.json"))
.flag("--dest-vc-url", Some("http://localhost:2"))
.flag("--dest-vc-token", Some("./2.json"))
.flag("--validators", Some(&format!("{}", EXAMPLE_PUBKEY_0)))
.flag("--validators", Some(EXAMPLE_PUBKEY_0))
.flag("--builder-proposals", Some("false"))
.flag("--prefer-builder-proposals", Some("false"))
.assert_success(|config| {
@@ -368,7 +368,7 @@ pub fn validator_move_misc_flags_1() {
fee_recipient: None,
gas_limit: None,
password_source: PasswordSource::Interactive {
stdin_inputs: cfg!(windows) || false,
stdin_inputs: cfg!(windows),
},
};
assert_eq!(expected, config);
@@ -382,7 +382,7 @@ pub fn validator_move_misc_flags_2() {
.flag("--src-vc-token", Some("./1.json"))
.flag("--dest-vc-url", Some("http://localhost:2"))
.flag("--dest-vc-token", Some("./2.json"))
.flag("--validators", Some(&format!("{}", EXAMPLE_PUBKEY_0)))
.flag("--validators", Some(EXAMPLE_PUBKEY_0))
.flag("--builder-proposals", Some("false"))
.flag("--builder-boost-factor", Some("100"))
.assert_success(|config| {
@@ -400,7 +400,7 @@ pub fn validator_move_misc_flags_2() {
fee_recipient: None,
gas_limit: None,
password_source: PasswordSource::Interactive {
stdin_inputs: cfg!(windows) || false,
stdin_inputs: cfg!(windows),
},
};
assert_eq!(expected, config);
@@ -428,7 +428,7 @@ pub fn validator_move_count() {
fee_recipient: None,
gas_limit: None,
password_source: PasswordSource::Interactive {
stdin_inputs: cfg!(windows) || false,
stdin_inputs: cfg!(windows),
},
};
assert_eq!(expected, config);