From bb6c4efe9b696bb5d0758da6c5d4acef2ea6e413 Mon Sep 17 00:00:00 2001 From: Trent Nelson Date: Sat, 25 Jan 2020 22:14:07 -0700 Subject: [PATCH] CLI: Deterministic dummy keypair generation for SigningAuthority::Offline (#7971) * CLI: Deterministic dummy keypair generation for SigningAuthority::Offline * Add test --- cli/src/cli.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cli/src/cli.rs b/cli/src/cli.rs index d1c6a9cd26..8d473dda1c 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -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 for SigningAuthority { impl From 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");