Durable Nonce - Authorized Noncer (#7417)
* Durable Nonce: Add authorized noncer to initialize instruction * CLI: Adapt to nonce authority * Durable Nonce: Introduce Authorize instruction * Specify who needs to sign ix * 'authorized-noncer' -> 'nonce-authority' * Document signing authority for all instructions
This commit is contained in:
@ -4,7 +4,7 @@ use solana_faucet::faucet::run_local_faucet;
|
||||
use solana_sdk::{
|
||||
hash::Hash,
|
||||
pubkey::Pubkey,
|
||||
signature::{read_keypair_file, write_keypair, KeypairUtil},
|
||||
signature::{read_keypair_file, write_keypair, Keypair, KeypairUtil},
|
||||
};
|
||||
use std::fs::remove_dir_all;
|
||||
use std::sync::mpsc::channel;
|
||||
@ -53,6 +53,63 @@ fn test_nonce() {
|
||||
let (keypair_file, mut tmp_file) = make_tmp_file();
|
||||
write_keypair(&config_nonce.keypair, tmp_file.as_file_mut()).unwrap();
|
||||
|
||||
full_battery_tests(
|
||||
&rpc_client,
|
||||
&drone_addr,
|
||||
&mut config_payer,
|
||||
&mut config_nonce,
|
||||
&keypair_file,
|
||||
&keypair_file,
|
||||
);
|
||||
|
||||
server.close().unwrap();
|
||||
remove_dir_all(ledger_path).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_nonce_with_authority() {
|
||||
let (server, leader_data, alice, ledger_path) = new_validator_for_tests();
|
||||
let (sender, receiver) = channel();
|
||||
run_local_drone(alice, sender, None);
|
||||
let drone_addr = receiver.recv().unwrap();
|
||||
|
||||
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
||||
|
||||
let mut config_payer = CliConfig::default();
|
||||
config_payer.json_rpc_url =
|
||||
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||
|
||||
let mut config_nonce = CliConfig::default();
|
||||
config_nonce.json_rpc_url =
|
||||
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||
let (nonce_keypair_file, mut tmp_file) = make_tmp_file();
|
||||
write_keypair(&config_nonce.keypair, tmp_file.as_file_mut()).unwrap();
|
||||
|
||||
let nonce_authority = Keypair::new();
|
||||
let (authority_keypair_file, mut tmp_file2) = make_tmp_file();
|
||||
write_keypair(&nonce_authority, tmp_file2.as_file_mut()).unwrap();
|
||||
|
||||
full_battery_tests(
|
||||
&rpc_client,
|
||||
&drone_addr,
|
||||
&mut config_payer,
|
||||
&mut config_nonce,
|
||||
&nonce_keypair_file,
|
||||
&authority_keypair_file,
|
||||
);
|
||||
|
||||
server.close().unwrap();
|
||||
remove_dir_all(ledger_path).unwrap();
|
||||
}
|
||||
|
||||
fn full_battery_tests(
|
||||
rpc_client: &RpcClient,
|
||||
drone_addr: &std::net::SocketAddr,
|
||||
config_payer: &mut CliConfig,
|
||||
config_nonce: &mut CliConfig,
|
||||
nonce_keypair_file: &str,
|
||||
authority_keypair_file: &str,
|
||||
) {
|
||||
request_and_confirm_airdrop(
|
||||
&rpc_client,
|
||||
&faucet_addr,
|
||||
@ -64,7 +121,8 @@ fn test_nonce() {
|
||||
|
||||
// Create nonce account
|
||||
config_payer.command = CliCommand::CreateNonceAccount {
|
||||
nonce_account: read_keypair_file(&keypair_file).unwrap().into(),
|
||||
nonce_account: read_keypair_file(&nonce_keypair_file).unwrap().into(),
|
||||
nonce_authority: read_keypair_file(&authority_keypair_file).unwrap().pubkey(),
|
||||
lamports: 1000,
|
||||
};
|
||||
process_command(&config_payer).unwrap();
|
||||
@ -84,7 +142,10 @@ fn test_nonce() {
|
||||
assert_eq!(first_nonce, second_nonce);
|
||||
|
||||
// New nonce
|
||||
config_payer.command = CliCommand::NewNonce(read_keypair_file(&keypair_file).unwrap().into());
|
||||
config_payer.command = CliCommand::NewNonce {
|
||||
nonce_account: read_keypair_file(&nonce_keypair_file).unwrap().pubkey(),
|
||||
nonce_authority: read_keypair_file(&authority_keypair_file).unwrap().into(),
|
||||
};
|
||||
process_command(&config_payer).unwrap();
|
||||
|
||||
// Get nonce
|
||||
@ -97,7 +158,8 @@ fn test_nonce() {
|
||||
// Withdraw from nonce account
|
||||
let payee_pubkey = Pubkey::new_rand();
|
||||
config_payer.command = CliCommand::WithdrawFromNonceAccount {
|
||||
nonce_account: read_keypair_file(&keypair_file).unwrap().into(),
|
||||
nonce_account: read_keypair_file(&nonce_keypair_file).unwrap().pubkey(),
|
||||
nonce_authority: read_keypair_file(&authority_keypair_file).unwrap().into(),
|
||||
destination_account_pubkey: payee_pubkey,
|
||||
lamports: 100,
|
||||
};
|
||||
@ -112,7 +174,4 @@ fn test_nonce() {
|
||||
use_lamports_unit: true,
|
||||
};
|
||||
process_command(&config_payer).unwrap();
|
||||
|
||||
server.close().unwrap();
|
||||
remove_dir_all(ledger_path).unwrap();
|
||||
}
|
||||
|
Reference in New Issue
Block a user