Improve tests

This commit is contained in:
Paul Hauner
2022-08-24 17:54:33 +10:00
parent 0f5092e262
commit 06fa52ef5a
2 changed files with 25 additions and 16 deletions

View File

@@ -283,14 +283,7 @@ pub mod tests {
.find(|validator| validator.validating_pubkey == local_pubkey)
.expect("validator must exist on VC");
assert_eq!(&remote_validator.derivation_path, &local_keystore.path());
// It's not immediately clear why Lighthouse returns `None` rather than
// `Some(false)` here, I would expect the latter to be the most accurate.
// However, it doesn't seem like a big deal.
//
// See: https://github.com/sigp/lighthouse/pull/3490
//
// If that PR changes we'll need to change this line.
assert_eq!(remote_validator.readonly, None);
assert_eq!(remote_validator.readonly, Some(false));
}
}

View File

@@ -29,6 +29,8 @@ pub const GAS_LIMIT_FLAG: &str = "gas-limit";
pub const FEE_RECIPIENT_FLAG: &str = "suggested-fee-recipient";
pub const BUILDER_PROPOSALS_FLAG: &str = "builder-proposals";
const NO_VALIDATORS_MSG: &str = "No validators present on source validator client";
pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
App::new(CMD)
.about(
@@ -248,6 +250,10 @@ async fn run<'a>(config: MoveConfig) -> Result<(), String> {
let (dest_http_client, _dest_keystores) =
vc_http_client(dest_vc_url.clone(), &dest_vc_token_path).await?;
if src_keystores.is_empty() {
return Err(NO_VALIDATORS_MSG.to_string());
}
let pubkeys_to_move = match validators {
Validators::All => src_keystores.iter().map(|v| v.validating_pubkey).collect(),
Validators::Some(request_pubkeys) => {
@@ -561,13 +567,14 @@ mod test {
where
F: Fn(&[PublicKeyBytes]) -> Validators,
{
let import_test_result = self
.import_builder
.expect("test requires an import builder")
.run_test()
.await;
assert!(import_test_result.result.is_ok());
let src_vc = import_test_result.vc;
let src_vc = if let Some(import_builder) = self.import_builder {
let import_test_result = import_builder.run_test().await;
assert!(import_test_result.result.is_ok());
import_test_result.vc
} else {
ApiTester::new().await
};
let src_vc_token_path = self.dir.path().join(SRC_VC_TOKEN_FILE_NAME);
fs::write(&src_vc_token_path, &src_vc.api_token).unwrap();
let (src_vc_client, src_vc_initial_keystores) =
@@ -599,7 +606,7 @@ mod test {
let result = run(move_config).await;
let (dest_vc_client, dest_vc_keystores) =
let (_dest_vc_client, dest_vc_keystores) =
vc_http_client(dest_vc.url.clone(), &dest_vc_token_path)
.await
.unwrap();
@@ -634,6 +641,15 @@ mod test {
}
}
#[tokio::test]
async fn no_validators() {
TestBuilder::new()
.await
.run_test(|_| Validators::All)
.await
.assert_err_is(NO_VALIDATORS_MSG.to_string());
}
#[tokio::test]
async fn one_validator_move_all() {
TestBuilder::new()