Test some validator_info error paths (#20635)
* Test some validator_info error paths * Fix a linting issue * Improve test robustness by removing magic numbers
This commit is contained in:
parent
b825390752
commit
91de3013dd
|
@ -412,6 +412,23 @@ mod tests {
|
|||
use bincode::{serialize, serialized_size};
|
||||
use serde_json::json;
|
||||
|
||||
#[test]
|
||||
fn test_check_details_length() {
|
||||
let short_details = (0..MAX_LONG_FIELD_LENGTH).map(|_| "X").collect::<String>();
|
||||
assert_eq!(check_details_length(short_details), Ok(()));
|
||||
|
||||
let long_details = (0..MAX_LONG_FIELD_LENGTH + 1)
|
||||
.map(|_| "X")
|
||||
.collect::<String>();
|
||||
assert_eq!(
|
||||
check_details_length(long_details),
|
||||
Err(format!(
|
||||
"validator details longer than {:?}-byte limit",
|
||||
MAX_LONG_FIELD_LENGTH
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_check_url() {
|
||||
let url = "http://test.com";
|
||||
|
@ -430,6 +447,17 @@ mod tests {
|
|||
assert!(is_short_field(long_name.to_string()).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_verify_keybase_username_not_string() {
|
||||
let pubkey = solana_sdk::pubkey::new_rand();
|
||||
let value = Value::Bool(true);
|
||||
|
||||
assert_eq!(
|
||||
verify_keybase(&pubkey, &value).unwrap_err().to_string(),
|
||||
"keybase_username could not be parsed as String: true".to_string()
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_args() {
|
||||
let matches = get_clap_app("test", "desc", "version").get_matches_from(vec![
|
||||
|
@ -507,6 +535,41 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_validator_info_not_validator_info_account() {
|
||||
assert!(parse_validator_info(
|
||||
&Pubkey::default(),
|
||||
&Account {
|
||||
owner: solana_sdk::pubkey::new_rand(),
|
||||
..Account::default()
|
||||
}
|
||||
)
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("is not a validator info account"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_validator_info_empty_key_list() {
|
||||
let config = ConfigKeys { keys: vec![] };
|
||||
let validator_info = ValidatorInfo {
|
||||
info: String::new(),
|
||||
};
|
||||
let data = serialize(&(config, validator_info)).unwrap();
|
||||
|
||||
assert!(parse_validator_info(
|
||||
&Pubkey::default(),
|
||||
&Account {
|
||||
owner: solana_config_program::id(),
|
||||
data,
|
||||
..Account::default()
|
||||
},
|
||||
)
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("could not be parsed as a validator info account"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_validator_info_max_space() {
|
||||
// 70-character string
|
||||
|
|
Loading…
Reference in New Issue