memo: moved to helper
This commit is contained in:
parent
533ce21d92
commit
55d1fd1dc8
|
@ -1,10 +1,11 @@
|
|||
use std::{ops::Deref, sync::Arc};
|
||||
use std::{ops::Deref, str::FromStr, sync::Arc};
|
||||
|
||||
use anyhow::Context;
|
||||
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
|
||||
use solana_sdk::{
|
||||
commitment_config::CommitmentConfig,
|
||||
hash::Hash,
|
||||
instruction::Instruction,
|
||||
message::Message,
|
||||
pubkey::Pubkey,
|
||||
signature::{Keypair, Signature},
|
||||
|
@ -13,6 +14,8 @@ use solana_sdk::{
|
|||
transaction::Transaction,
|
||||
};
|
||||
|
||||
const MEMO_PROGRAM_ID: &str = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr";
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct BenchHelper {
|
||||
pub rpc_client: Arc<RpcClient>,
|
||||
|
@ -90,4 +93,19 @@ impl BenchHelper {
|
|||
|
||||
Ok(txs)
|
||||
}
|
||||
|
||||
pub async fn send_and_confirm_memo(
|
||||
&self,
|
||||
msg: &[u8],
|
||||
payer: &Keypair,
|
||||
blockhash: Hash,
|
||||
) -> anyhow::Result<String> {
|
||||
let memo = Pubkey::from_str(MEMO_PROGRAM_ID)?;
|
||||
|
||||
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(self.send_and_confirm_transaction(&tx).await?.to_string())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,36 +1,20 @@
|
|||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
|
||||
use bench::helpers::BenchHelper;
|
||||
use lite_rpc::DEFAULT_RPC_ADDR;
|
||||
use lite_rpc::DEFAULT_LITE_RPC_ADDR;
|
||||
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
|
||||
use solana_sdk::{
|
||||
instruction::Instruction, message::Message, pubkey::Pubkey, signer::Signer,
|
||||
transaction::Transaction,
|
||||
};
|
||||
|
||||
const MEMO_PROGRAM_ID: &str = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr";
|
||||
|
||||
#[tokio::test]
|
||||
async fn memo() -> anyhow::Result<()> {
|
||||
let rpc_client = Arc::new(RpcClient::new(DEFAULT_RPC_ADDR.to_owned()));
|
||||
let blockhash = rpc_client.get_latest_blockhash().await.unwrap();
|
||||
async fn memo() {
|
||||
let rpc_client = Arc::new(RpcClient::new(DEFAULT_LITE_RPC_ADDR.to_owned()));
|
||||
let helper = BenchHelper::new(rpc_client);
|
||||
let payer = helper.get_payer().await.unwrap();
|
||||
let blockhash = helper.get_latest_blockhash().await.unwrap();
|
||||
|
||||
let bench_helper = BenchHelper::new(rpc_client);
|
||||
let payer = bench_helper.get_payer().await.unwrap();
|
||||
|
||||
let memo = Pubkey::from_str(MEMO_PROGRAM_ID).unwrap();
|
||||
|
||||
let instruction = Instruction::new_with_bytes(memo, b"Hello", vec![]);
|
||||
let message = Message::new(&[instruction], Some(&payer.pubkey()));
|
||||
let tx = Transaction::new(&[&payer], message, blockhash);
|
||||
|
||||
let sig = bench_helper
|
||||
.send_and_confirm_transaction(&tx)
|
||||
let sig = helper
|
||||
.send_and_confirm_memo(b"hello", &payer, blockhash)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
println!("{sig}");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue