forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
use { | ||
criterion::{criterion_group, criterion_main, Criterion}, solana_cli::{ | ||
cli::{CliCommand, CliCommandInfo, CliConfig}, | ||
vote::process_create_vote_account, | ||
}, solana_cli_output::cli_version, solana_rpc_client::rpc_client::RpcClient, solana_rpc_client_nonce_utils::blockhash_query, solana_sdk::signature::{read_keypair_file, write_keypair, Keypair, Signer}, std::sync::Arc, tempfile::NamedTempFile | ||
}; | ||
|
||
fn make_tmp_file() -> (String, NamedTempFile) { | ||
let tmp_file = NamedTempFile::new().unwrap(); | ||
(String::from(tmp_file.path().to_str().unwrap()), tmp_file) | ||
} | ||
|
||
struct TestSetup<'a> { | ||
config: CliConfig<'a>, | ||
rpc_client: Arc<RpcClient>, | ||
} | ||
|
||
impl<'a> TestSetup<'a> { | ||
fn new(cli_signers: &'a Vec<Keypair>) -> TestSetup<'a> { | ||
let config = CliConfig { | ||
rpc_client: Some(Arc::new(RpcClient::new_mock("succeeds".to_string()))), | ||
json_rpc_url: "http://127.0.0.1:8899".to_string(), | ||
signers: vec![&cli_signers[0], &cli_signers[1], &cli_signers[2]], | ||
..CliConfig::default() | ||
}; | ||
let rpc_client = Arc::new(RpcClient::new_with_timeouts_and_commitment( | ||
config.json_rpc_url.to_string(), | ||
config.rpc_timeout, | ||
config.commitment, | ||
config.confirm_transaction_initial_timeout, | ||
)); | ||
|
||
Self { | ||
config, | ||
rpc_client | ||
} | ||
} | ||
|
||
pub fn prep_vote_account(&self) -> CliCommandInfo { | ||
let authorized_withdrawer = Keypair::new().pubkey(); | ||
CliCommandInfo { | ||
command: CliCommand::CreateVoteAccount { | ||
vote_account: 1, | ||
seed: None, | ||
identity_account: 2, | ||
authorized_voter: None, | ||
authorized_withdrawer, | ||
commission: 10, | ||
sign_only: false, | ||
dump_transaction_message: false, | ||
blockhash_query: blockhash_query::BlockhashQuery::All(blockhash_query::Source::Cluster), | ||
nonce_account: None, | ||
nonce_authority: 0, | ||
memo: None, | ||
fee_payer: 0, | ||
compute_unit_price: None, | ||
}, | ||
signers: vec![], | ||
} | ||
} | ||
pub fn run(&self, cli_command_info : &CliCommandInfo) { | ||
let res = match &cli_command_info.command { | ||
CliCommand::CreateVoteAccount { | ||
vote_account, | ||
seed, | ||
identity_account, | ||
authorized_voter, | ||
authorized_withdrawer, | ||
commission, | ||
sign_only, | ||
dump_transaction_message, | ||
blockhash_query, | ||
nonce_account, | ||
nonce_authority, | ||
memo, | ||
fee_payer, | ||
compute_unit_price, | ||
} => process_create_vote_account( | ||
&self.rpc_client, | ||
&self.config, | ||
*vote_account, | ||
seed, | ||
*identity_account, | ||
authorized_voter, | ||
*authorized_withdrawer, | ||
*commission, | ||
*sign_only, | ||
*dump_transaction_message, | ||
blockhash_query, | ||
nonce_account.as_ref(), | ||
*nonce_authority, | ||
memo.as_ref(), | ||
*fee_payer, | ||
*compute_unit_price, | ||
), | ||
_ => panic!("Error, unknown type") | ||
}; | ||
if res.is_err() { | ||
eprintln!("{:?}", res); | ||
} | ||
} | ||
} | ||
|
||
fn bench_create_vote_account(c: &mut Criterion) { | ||
let default_keypair = Keypair::new(); | ||
let identity_keypair = Keypair::new(); | ||
let keypair = Keypair::new(); | ||
|
||
let cli_signers = vec![default_keypair, identity_keypair, keypair]; | ||
|
||
let test_setup = TestSetup::new(&cli_signers); | ||
let va = test_setup.prep_vote_account(); | ||
|
||
c.bench_function("initialize_buffer", |bencher| { | ||
bencher.iter(|| test_setup.run(&va)) | ||
}); | ||
} | ||
|
||
criterion_group!( | ||
benches, | ||
bench_create_vote_account, | ||
); | ||
criterion_main!(benches); |