lite-rpc/tests/blockhash.rs

26 lines
745 B
Rust
Raw Normal View History

2023-02-09 04:05:18 -08:00
use lite_rpc::DEFAULT_LITE_RPC_ADDR;
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
2023-03-03 13:37:44 -08:00
const BLOCKHASH_INTERVAL_MS: u64 = 3000;
2023-02-09 04:05:18 -08:00
#[tokio::test]
async fn blockhash() -> anyhow::Result<()> {
let lite_rpc = RpcClient::new(DEFAULT_LITE_RPC_ADDR.to_string());
let mut prev_blockhash = lite_rpc.get_latest_blockhash().await.unwrap();
2023-03-03 13:37:44 -08:00
for _ in 0..10 {
tokio::time::sleep(tokio::time::Duration::from_millis(BLOCKHASH_INTERVAL_MS)).await;
2023-02-09 04:05:18 -08:00
let blockhash = lite_rpc.get_latest_blockhash().await.unwrap();
if prev_blockhash != blockhash {
prev_blockhash = blockhash;
} else {
2023-03-03 13:37:44 -08:00
panic!("Blockhash didn't change in appx {BLOCKHASH_INTERVAL_MS}ms");
2023-02-09 04:05:18 -08:00
}
}
Ok(())
}