CLI: Deterministic dummy keypair generation for SigningAuthority::Offline (#7971)

* CLI: Deterministic dummy keypair generation for SigningAuthority::Offline

* Add test
This commit is contained in:
Trent Nelson 2020-01-25 22:14:07 -07:00 committed by GitHub
parent c324e71768
commit bb6c4efe9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 2 deletions

View File

@ -31,7 +31,7 @@ use solana_sdk::{
message::Message,
native_token::lamports_to_sol,
pubkey::Pubkey,
signature::{Keypair, KeypairUtil, Signature},
signature::{keypair_from_seed, Keypair, KeypairUtil, Signature},
system_instruction::{create_address_with_seed, SystemError, MAX_ADDRESS_SEED_LEN},
system_transaction,
transaction::{Transaction, TransactionError},
@ -125,7 +125,7 @@ impl From<Keypair> for SigningAuthority {
impl From<Pubkey> for SigningAuthority {
fn from(pubkey: Pubkey) -> Self {
SigningAuthority::Offline(pubkey, Keypair::new())
SigningAuthority::Offline(pubkey, keypair_from_seed(pubkey.as_ref()).unwrap())
}
}
@ -2092,6 +2092,7 @@ mod tests {
use solana_sdk::{
account::Account,
nonce_state::{Meta as NonceMeta, NonceState},
pubkey::Pubkey,
signature::{read_keypair_file, write_keypair_file},
system_program,
transaction::TransactionError,
@ -2112,6 +2113,13 @@ mod tests {
path
}
#[test]
fn test_signing_authority_dummy_keypairs() {
let signing_authority: SigningAuthority = Pubkey::new(&[1u8; 32]).into();
assert_eq!(signing_authority, Pubkey::new(&[1u8; 32]).into());
assert_ne!(signing_authority, Pubkey::new(&[2u8; 32]).into());
}
#[test]
fn test_cli_parse_command() {
let test_commands = app("test", "desc", "version");