Skip to content

Commit

Permalink
Vote cu
Browse files Browse the repository at this point in the history
  • Loading branch information
ksolana committed Jan 8, 2025
1 parent f27dda7 commit b64e828
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,18 @@ tiny-bip39 = { workspace = true }

[dev-dependencies]
assert_matches = { workspace = true }
criterion = { workspace = true }
solana-faucet = { workspace = true }
solana-rpc = { workspace = true }
solana-streamer = { workspace = true }
solana-test-validator = { workspace = true }
tempfile = { workspace = true }
test-case = { workspace = true }

[[bench]]
name = "vote"
harness = false

[[bin]]
name = "solana"
path = "src/main.rs"
Expand Down
123 changes: 123 additions & 0 deletions cli/benches/vote.rs
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);

0 comments on commit b64e828

Please sign in to comment.