fixed tests
This commit is contained in:
parent
05f32c9c97
commit
e69bdb5d48
|
@ -9,7 +9,7 @@ use crate::{
|
|||
DEFAULT_TX_MAX_RETRIES,
|
||||
};
|
||||
|
||||
use std::{net::ToSocketAddrs, str::FromStr, sync::Arc};
|
||||
use std::{net::ToSocketAddrs, ops::Deref, str::FromStr, sync::Arc};
|
||||
|
||||
use actix_web::{web, App, HttpServer, Responder};
|
||||
use reqwest::Url;
|
||||
|
@ -167,3 +167,11 @@ impl LiteBridge {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for LiteBridge {
|
||||
type Target = RpcClient;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.tpu_client.rpc_client()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Context;
|
||||
use anyhow::{bail, Context};
|
||||
use futures::StreamExt;
|
||||
use log::info;
|
||||
use solana_client::nonblocking::pubsub_client::PubsubClient;
|
||||
|
@ -57,7 +57,7 @@ impl BlockListener {
|
|||
tokio::spawn(async move {
|
||||
info!("Subscribing to blocks");
|
||||
|
||||
let (mut recv, un_sub) = self
|
||||
let (mut recv, _) = self
|
||||
.pub_sub_client
|
||||
.block_subscribe(
|
||||
RpcBlockSubscribeFilter::All,
|
||||
|
@ -91,11 +91,7 @@ impl BlockListener {
|
|||
}
|
||||
}
|
||||
|
||||
info!("Stopped Listening to confirmed blocks");
|
||||
|
||||
un_sub();
|
||||
|
||||
Ok(())
|
||||
bail!("Stopped Listening to confirmed blocks")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,89 +0,0 @@
|
|||
use std::str::FromStr;
|
||||
use std::time::Duration;
|
||||
|
||||
use lite_rpc::{DEFAULT_RPC_ADDR, DEFAULT_WS_ADDR};
|
||||
use reqwest::Url;
|
||||
use solana_client::rpc_response::RpcVersionInfo;
|
||||
use solana_sdk::{
|
||||
message::Message, native_token::LAMPORTS_PER_SOL, pubkey::Pubkey, signature::Keypair,
|
||||
signer::Signer, system_instruction, transaction::Transaction,
|
||||
};
|
||||
|
||||
use lite_rpc::{bridge::LiteBridge, encoding::BinaryEncoding, rpc::SendTransactionParams};
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_version() {
|
||||
let lite_bridge = LiteBridge::new(Url::from_str(DEFAULT_RPC_ADDR).unwrap(), DEFAULT_WS_ADDR)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let RpcVersionInfo {
|
||||
solana_core,
|
||||
feature_set,
|
||||
} = lite_bridge.get_version();
|
||||
let version_crate = solana_version::Version::default();
|
||||
|
||||
assert_eq!(solana_core, version_crate.to_string());
|
||||
assert_eq!(feature_set.unwrap(), version_crate.feature_set);
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn test_send_transaction() {
|
||||
let lite_bridge = LiteBridge::new(Url::from_str(DEFAULT_RPC_ADDR).unwrap(), DEFAULT_WS_ADDR)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let payer = Keypair::new();
|
||||
|
||||
lite_bridge
|
||||
.tpu_client
|
||||
.rpc_client()
|
||||
.request_airdrop(&payer.pubkey(), LAMPORTS_PER_SOL * 2)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
std::thread::sleep(Duration::from_secs(2));
|
||||
|
||||
let to_pubkey = Pubkey::new_unique();
|
||||
let instruction = system_instruction::transfer(&payer.pubkey(), &to_pubkey, LAMPORTS_PER_SOL);
|
||||
|
||||
let message = Message::new(&[instruction], Some(&payer.pubkey()));
|
||||
|
||||
let blockhash = lite_bridge
|
||||
.tpu_client
|
||||
.rpc_client()
|
||||
.get_latest_blockhash()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let tx = Transaction::new(&[&payer], message, blockhash);
|
||||
let signature = tx.signatures[0];
|
||||
let encoded_signature = BinaryEncoding::Base58.encode(signature);
|
||||
|
||||
let tx = BinaryEncoding::Base58.encode(bincode::serialize(&tx).unwrap());
|
||||
|
||||
assert_eq!(
|
||||
lite_bridge
|
||||
.send_transaction(SendTransactionParams(tx, Default::default()))
|
||||
.await
|
||||
.unwrap(),
|
||||
encoded_signature
|
||||
);
|
||||
|
||||
std::thread::sleep(Duration::from_secs(5));
|
||||
|
||||
let mut passed = false;
|
||||
|
||||
for _ in 0..100 {
|
||||
passed = lite_bridge
|
||||
.tpu_client
|
||||
.rpc_client()
|
||||
.confirm_transaction(&signature)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
std::thread::sleep(Duration::from_millis(100));
|
||||
}
|
||||
|
||||
passed.then_some(()).unwrap();
|
||||
}
|
|
@ -2,7 +2,7 @@ use std::sync::Arc;
|
|||
use std::time::Duration;
|
||||
|
||||
use bench_utils::helpers::{create_transaction, new_funded_payer};
|
||||
use futures::future::join;
|
||||
use futures::future::try_join_all;
|
||||
use lite_rpc::{
|
||||
encoding::BinaryEncoding,
|
||||
workers::{BlockListener, TxSender},
|
||||
|
@ -27,7 +27,10 @@ async fn send_and_confirm_txs() {
|
|||
|
||||
let tx_sender = TxSender::new(tpu_client, block_listener.clone());
|
||||
|
||||
let services = join(block_listener.clone().listen(), tx_sender.clone().execute());
|
||||
let services = try_join_all(vec![
|
||||
block_listener.clone().listen(),
|
||||
tx_sender.clone().execute(),
|
||||
]);
|
||||
|
||||
let confirm = tokio::spawn(async move {
|
||||
let funded_payer = new_funded_payer(&rpc_client, LAMPORTS_PER_SOL * 2)
|
||||
|
|
Loading…
Reference in New Issue