From 6e02b8daf9381e600f8c6be231127b808e1c1471 Mon Sep 17 00:00:00 2001 From: aniketfuryrocks Date: Wed, 8 Feb 2023 03:21:56 +0530 Subject: [PATCH] use memo --- bench/src/helpers.rs | 28 ++++++++++++---------------- bench/src/main.rs | 4 +--- tests/client.rs | 8 ++------ tests/part_send_n_confirm.rs | 4 +++- 4 files changed, 18 insertions(+), 26 deletions(-) diff --git a/bench/src/helpers.rs b/bench/src/helpers.rs index c99dfffb..52543c08 100644 --- a/bench/src/helpers.rs +++ b/bench/src/helpers.rs @@ -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> { - let mut txs = Vec::with_capacity(num_of_txs); + ) -> Vec { + (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 { - 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) } } diff --git a/bench/src/main.rs b/bench/src/main.rs index ec1d5478..8ef3f444 100644 --- a/bench/src/main.rs +++ b/bench/src/main.rs @@ -62,9 +62,7 @@ async fn bench(rpc_client: Arc, 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> = HashMap::with_capacity(txs.len()); diff --git a/tests/client.rs b/tests/client.rs index fc40ed68..02079f59 100644 --- a/tests/client.rs +++ b/tests/client.rs @@ -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(); diff --git a/tests/part_send_n_confirm.rs b/tests/part_send_n_confirm.rs index 030da65a..b36434a9 100644 --- a/tests/part_send_n_confirm.rs +++ b/tests/part_send_n_confirm.rs @@ -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(()) }