Add CLI commands for nonces (#7329)

automerge
This commit is contained in:
Jack May
2019-12-10 00:24:44 -08:00
committed by Grimes
parent 19ecce1e32
commit a03062af4f
6 changed files with 707 additions and 0 deletions

View File

@ -89,6 +89,7 @@ mod tests {
.multiple(true),
)
.arg(Arg::with_name("single").takes_value(true).long("single"))
.arg(Arg::with_name("unit").takes_value(true).long("unit"))
}
fn tmp_file_path(name: &str, pubkey: &Pubkey) -> String {
@ -208,4 +209,18 @@ mod tests {
Some(vec![(key1, sig1), (key2, sig2)])
);
}
#[test]
fn test_amount_of() {
let matches = app()
.clone()
.get_matches_from(vec!["test", "--single", "50", "--unit", "lamports"]);
assert_eq!(amount_of(&matches, "single", "unit"), Some(50));
let matches = app()
.clone()
.get_matches_from(vec!["test", "--single", "50", "--unit", "SOL"]);
assert_eq!(amount_of(&matches, "single", "unit"), Some(50000000000));
assert_eq!(amount_of(&matches, "multiple", "unit"), None);
assert_eq!(amount_of(&matches, "multiple", "unit"), None);
}
}

View File

@ -118,3 +118,10 @@ pub fn is_valid_percentage(percentage: String) -> Result<(), String> {
}
})
}
pub fn is_amount(amount: String) -> Result<(), String> {
amount
.parse::<u64>()
.map(|_| ())
.map_err(|e| format!("{:?}", e))
}