Skip to content

Commit

Permalink
Vote cu
Browse files Browse the repository at this point in the history
  • Loading branch information
ksolana committed Jan 16, 2025
1 parent 91d0d0c commit edca611
Show file tree
Hide file tree
Showing 3 changed files with 85 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 @@ -66,13 +66,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
79 changes: 79 additions & 0 deletions cli/benches/vote.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
use {
criterion::{criterion_group, criterion_main, Criterion},
solana_cli::cli::{
process_command, request_and_confirm_airdrop, CliCommand, CliConfig,
},
solana_commitment_config::CommitmentConfig,
solana_faucet::faucet::run_local_faucet,
solana_rpc_client::rpc_client::RpcClient,
solana_rpc_client_nonce_utils::blockhash_query,
solana_rpc_client_nonce_utils::blockhash_query::BlockhashQuery,
solana_sdk::signature::{Keypair, Signer},
solana_streamer::socket::SocketAddrSpace,
solana_test_validator::TestValidator,
};

struct TestSetup {
compute_unit_price: Option<u64>,
}

impl TestSetup {
fn new(p: u64) -> TestSetup {
Self {
compute_unit_price: Some(p),
}
}

pub fn run(&self) {
let mint_keypair = Keypair::new();
let mint_pubkey = mint_keypair.pubkey();
let faucet_addr = run_local_faucet(mint_keypair, None);
let test_validator = TestValidator::with_no_fees(
mint_pubkey,
Some(faucet_addr),
SocketAddrSpace::Unspecified,
);

let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
let default_signer = Keypair::new();

let mut config = CliConfig::recent_for_tests();
config.json_rpc_url = test_validator.rpc_url();
config.signers = vec![&default_signer];

request_and_confirm_airdrop(&rpc_client, &config, &config.signers[0].pubkey(), 100_000)
.unwrap();

// Create vote account
let vote_account_keypair = Keypair::new();
config.signers = vec![&default_signer, &vote_account_keypair];
config.command = CliCommand::CreateVoteAccount {
vote_account: 1,
seed: None,
identity_account: 0,
authorized_voter: None,
authorized_withdrawer: config.signers[0].pubkey(),
commission: 0,
sign_only: false,
dump_transaction_message: false,
blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
nonce_account: None,
nonce_authority: 0,
memo: None,
fee_payer: 0,
compute_unit_price: self.compute_unit_price,
};
process_command(&config).unwrap();
}
}

fn bench_create_vote_account(c: &mut Criterion) {
let test_setup = TestSetup::new(1_000_000);
c.bench_function("create_vote_account", |bencher| {
bencher.iter(|| test_setup.run())
});
}

criterion_group!(benches, bench_create_vote_account,);
criterion_main!(benches);

0 comments on commit edca611

Please sign in to comment.