feat: integrated ts tests with the lite rpc cli
This commit is contained in:
parent
51fe807e4a
commit
60d0f8326e
|
@ -15,7 +15,7 @@
|
|||
"scripts": {
|
||||
"test": "jest --detectOpenHandles",
|
||||
"start:lite-rpc": "lite-rpc",
|
||||
"test:test-validator": "start-server-and-test 'solana-test-validator --reset --quiet & target/debug/lite-rpc --rpc-url http://localhost:8899 --websocket-url ws://localhost:8900/' http://localhost:8899/health test"
|
||||
"test:test-validator": "start-server-and-test 'solana-test-validator --reset --quiet & sleep 150 ; target/debug/lite-rpc run --port 9000 --rpc-url http://localhost:8899 --subscription-port 9001 --websocket-url ws://localhost:8900/' http://localhost:8899/health test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^4.8.4"
|
||||
|
|
12
src/cli.rs
12
src/cli.rs
|
@ -13,10 +13,8 @@ use clap::Parser;
|
|||
"
|
||||
)]
|
||||
pub struct Args {
|
||||
|
||||
#[clap(subcommand)]
|
||||
pub command:Command,
|
||||
|
||||
pub command: Command,
|
||||
/*
|
||||
#[arg(short, long, default_value_t = String::from("8899"))]
|
||||
pub port: String,
|
||||
|
@ -28,11 +26,11 @@ pub struct Args {
|
|||
pub websocket_url: String,
|
||||
*/
|
||||
}
|
||||
/*
|
||||
/*
|
||||
impl Args {
|
||||
|
||||
pub fn resolve_address(&mut self) {
|
||||
|
||||
|
||||
if self.rpc_url.is_empty() {
|
||||
let (_, rpc_url) = ConfigInput::compute_json_rpc_url_setting(
|
||||
self.rpc_url.as_str(),
|
||||
|
@ -50,10 +48,10 @@ impl Args {
|
|||
self.websocket_url = ws_url;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
#[derive(Subcommand,Debug)]
|
||||
#[derive(Subcommand, Debug)]
|
||||
pub enum Command {
|
||||
Run {
|
||||
#[arg(short, long, default_value_t = String::from("8899"))]
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -122,10 +122,13 @@ fn run(port: String, subscription_port: String, rpc_url: String, websocket_url:
|
|||
websocket_service.close().unwrap();
|
||||
}
|
||||
|
||||
fn ts_test(){
|
||||
|
||||
|
||||
|
||||
fn ts_test() {
|
||||
let res = std::process::Command::new("yarn")
|
||||
.args(["run", "test:test-validator"])
|
||||
.output()
|
||||
.unwrap();
|
||||
println!("{}", String::from_utf8_lossy(&res.stdout));
|
||||
println!("{}", String::from_utf8_lossy(&res.stderr));
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
|
|
96
src/rpc.rs
96
src/rpc.rs
|
@ -195,7 +195,6 @@ impl LightRpcRequestProcessor {
|
|||
for signature in signatures {
|
||||
match signature_status.entry(signature.clone()) {
|
||||
dashmap::mapref::entry::Entry::Occupied(mut x) => {
|
||||
|
||||
let signature_notification = SignatureNotification {
|
||||
signature: Signature::from_str(signature.as_str())
|
||||
.unwrap(),
|
||||
|
@ -270,7 +269,7 @@ pub mod lite_rpc {
|
|||
|
||||
use itertools::Itertools;
|
||||
use solana_sdk::{fee_calculator::FeeCalculator, pubkey::Pubkey};
|
||||
use solana_transaction_status::{TransactionStatus, TransactionConfirmationStatus};
|
||||
use solana_transaction_status::{TransactionConfirmationStatus, TransactionStatus};
|
||||
|
||||
use super::*;
|
||||
#[rpc]
|
||||
|
@ -329,7 +328,6 @@ pub mod lite_rpc {
|
|||
signature_strs: Vec<String>,
|
||||
config: Option<RpcSignatureStatusConfig>,
|
||||
) -> Result<RpcResponse<Vec<Option<TransactionStatus>>>>;
|
||||
|
||||
}
|
||||
pub struct LightRpc;
|
||||
impl Lite for LightRpc {
|
||||
|
@ -461,17 +459,15 @@ pub mod lite_rpc {
|
|||
|
||||
match k_value {
|
||||
Some(value) => match *value {
|
||||
Some(commitment_for_signature) => {
|
||||
Ok(RpcResponse {
|
||||
context: RpcResponseContext::new(slot),
|
||||
value: if commitment.eq(&CommitmentLevel::Finalized) {
|
||||
commitment_for_signature.eq(&CommitmentLevel::Finalized)
|
||||
} else {
|
||||
commitment_for_signature.eq(&CommitmentLevel::Finalized)
|
||||
|| commitment_for_signature.eq(&CommitmentLevel::Confirmed)
|
||||
},
|
||||
})
|
||||
}
|
||||
Some(commitment_for_signature) => Ok(RpcResponse {
|
||||
context: RpcResponseContext::new(slot),
|
||||
value: if commitment.eq(&CommitmentLevel::Finalized) {
|
||||
commitment_for_signature.eq(&CommitmentLevel::Finalized)
|
||||
} else {
|
||||
commitment_for_signature.eq(&CommitmentLevel::Finalized)
|
||||
|| commitment_for_signature.eq(&CommitmentLevel::Confirmed)
|
||||
},
|
||||
}),
|
||||
None => Ok(RpcResponse {
|
||||
context: RpcResponseContext::new(slot),
|
||||
value: false,
|
||||
|
@ -502,43 +498,51 @@ pub mod lite_rpc {
|
|||
signature_strs: Vec<String>,
|
||||
_config: Option<RpcSignatureStatusConfig>,
|
||||
) -> Result<RpcResponse<Vec<Option<TransactionStatus>>>> {
|
||||
let confirmed_slot = meta.context.confirmed_block_info.slot.load(Ordering::Relaxed);
|
||||
let status = signature_strs.iter().map(|x| {
|
||||
let singature_status = meta.context.signature_status.get(x);
|
||||
let k_value = singature_status;
|
||||
match k_value {
|
||||
Some(value) => match *value {
|
||||
Some(commitment_for_signature) => {
|
||||
let slot = meta.context
|
||||
let confirmed_slot = meta
|
||||
.context
|
||||
.confirmed_block_info
|
||||
.slot
|
||||
.load(Ordering::Relaxed);
|
||||
let status = signature_strs
|
||||
.iter()
|
||||
.map(|x| {
|
||||
let singature_status = meta.context.signature_status.get(x);
|
||||
let k_value = singature_status;
|
||||
match k_value {
|
||||
Some(value) => match *value {
|
||||
Some(commitment_for_signature) => {
|
||||
let slot = meta
|
||||
.context
|
||||
.confirmed_block_info
|
||||
.slot
|
||||
.load(Ordering::Relaxed);
|
||||
meta.performance_counter
|
||||
.update_confirm_transaction_counter();
|
||||
meta.performance_counter
|
||||
.update_confirm_transaction_counter();
|
||||
|
||||
let status = match commitment_for_signature {
|
||||
CommitmentLevel::Finalized => TransactionConfirmationStatus::Finalized,
|
||||
_ => TransactionConfirmationStatus::Confirmed,
|
||||
};
|
||||
Some(TransactionStatus {
|
||||
slot,
|
||||
confirmations: Some(1),
|
||||
status: Ok(()),
|
||||
err: None,
|
||||
confirmation_status : Some(status)
|
||||
})
|
||||
}
|
||||
let status = match commitment_for_signature {
|
||||
CommitmentLevel::Finalized => {
|
||||
TransactionConfirmationStatus::Finalized
|
||||
}
|
||||
_ => TransactionConfirmationStatus::Confirmed,
|
||||
};
|
||||
Some(TransactionStatus {
|
||||
slot,
|
||||
confirmations: Some(1),
|
||||
status: Ok(()),
|
||||
err: None,
|
||||
confirmation_status: Some(status),
|
||||
})
|
||||
}
|
||||
None => None,
|
||||
},
|
||||
None => None,
|
||||
},
|
||||
None => None
|
||||
}
|
||||
}).collect_vec();
|
||||
Ok(
|
||||
RpcResponse {
|
||||
context : RpcResponseContext::new(confirmed_slot),
|
||||
value: status,
|
||||
}
|
||||
)
|
||||
}
|
||||
})
|
||||
.collect_vec();
|
||||
Ok(RpcResponse {
|
||||
context: RpcResponseContext::new(confirmed_slot),
|
||||
value: status,
|
||||
})
|
||||
}
|
||||
|
||||
fn request_airdrop(
|
||||
|
|
Loading…
Reference in New Issue