This commit is contained in:
aniketfuryrocks 2023-02-08 03:21:56 +05:30 committed by Godmode Galactus
parent 0e986dbd6a
commit 6e02b8daf9
No known key found for this signature in database
GPG Key ID: A04142C71ABB0DEA
4 changed files with 18 additions and 26 deletions

View File

@ -62,31 +62,27 @@ impl BenchHelper {
Transaction::new(&[funded_payer], message, blockhash)
}
pub async fn generate_txs(
#[inline]
pub fn generate_txs(
num_of_txs: usize,
funded_payer: &Keypair,
blockhash: Hash,
) -> anyhow::Result<Vec<Transaction>> {
let mut txs = Vec::with_capacity(num_of_txs);
) -> Vec<Transaction> {
(0..num_of_txs)
.into_iter()
.map(|_| Self::create_memo_tx(b"hello" ,funded_payer, blockhash))
.collect()
}
for _ in 0..num_of_txs {
txs.push(Self::create_transaction(funded_payer, blockhash));
}
Ok(txs)
}
pub async fn create_memo_tx(
pub fn create_memo_tx(
msg: &[u8],
payer: &Keypair,
blockhash: Hash,
) -> anyhow::Result<Transaction> {
let memo = Pubkey::from_str(MEMO_PROGRAM_ID)?;
) -> Transaction {
let memo = Pubkey::from_str(MEMO_PROGRAM_ID).unwrap();
let instruction = Instruction::new_with_bytes(memo, msg, vec![]);
let message = Message::new(&[instruction], Some(&payer.pubkey()));
let tx = Transaction::new(&[payer], message, blockhash);
Ok(tx)
Transaction::new(&[payer], message, blockhash)
}
}

View File

@ -62,9 +62,7 @@ async fn bench(rpc_client: Arc<RpcClient>, tx_count: usize) -> Metric {
let funded_payer = BenchHelper::get_payer().await.unwrap();
let blockhash = rpc_client.get_latest_blockhash().await.unwrap();
let txs = BenchHelper::generate_txs(tx_count, &funded_payer, blockhash)
.await
.unwrap();
let txs = BenchHelper::generate_txs(tx_count, &funded_payer, blockhash);
let mut un_confirmed_txs: HashMap<Signature, Option<Instant>> =
HashMap::with_capacity(txs.len());

View File

@ -17,9 +17,7 @@ async fn send_and_confirm_txs_get_signature_statuses() {
let funded_payer = BenchHelper::get_payer().await.unwrap();
let blockhash = rpc_client.get_latest_blockhash().await.unwrap();
let txs = BenchHelper::generate_txs(AMOUNT, &funded_payer, blockhash)
.await
.unwrap();
let txs = BenchHelper::generate_txs(AMOUNT, &funded_payer, blockhash);
info!("Sending and Confirming {AMOUNT} tx(s)");
@ -45,9 +43,7 @@ async fn send_and_confirm_tx_rpc_client() {
let funded_payer = BenchHelper::get_payer().await.unwrap();
let blockhash = rpc_client.get_latest_blockhash().await.unwrap();
let tx = &BenchHelper::generate_txs(1, &funded_payer, blockhash)
.await
.unwrap()[0];
let tx = &BenchHelper::generate_txs(1, &funded_payer, blockhash)[0];
let sig = tx.get_signature();

View File

@ -20,10 +20,12 @@ pub async fn send_and_confirm_memo(
let payer = BenchHelper::get_payer().await?;
let blockhash = send_rpc.get_latest_blockhash().await?;
let memo_tx = BenchHelper::create_memo_tx(b"hi", &payer, blockhash).await?;
let memo_tx = BenchHelper::create_memo_tx(b"hi", &payer, blockhash);
let memo_sig = send_rpc.send_transaction(&memo_tx).await?;
confirm_rpc.confirm_transaction(&memo_sig).await?;
println!("{memo_sig}");
Ok(())
}