mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Update various versions
This commit is contained in:
@@ -31,9 +31,9 @@ serde_json = { version = "1", optional = true }
|
||||
serai-abi = { path = "../abi", version = "0.1" }
|
||||
|
||||
multiaddr = { version = "0.18", optional = true }
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "b48efb12bf49a0dba1b3633403f716010b99dc56", optional = true }
|
||||
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "b48efb12bf49a0dba1b3633403f716010b99dc56", optional = true }
|
||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "b48efb12bf49a0dba1b3633403f716010b99dc56", optional = true }
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", optional = true }
|
||||
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", optional = true }
|
||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", optional = true }
|
||||
|
||||
async-lock = "3"
|
||||
|
||||
|
||||
@@ -119,6 +119,11 @@ impl Serai {
|
||||
Ok(Serai { url, client })
|
||||
}
|
||||
|
||||
/// Fetch the latest finalized block number.
|
||||
pub async fn latest_finalized_block_number(&self) -> Result<u64, RpcError> {
|
||||
self.call("serai_latestFinalizedBlockNumber", "[]").await
|
||||
}
|
||||
|
||||
/// Fetch if a block is finalized.
|
||||
pub async fn finalized(&self, block: BlockHash) -> Result<bool, RpcError> {
|
||||
self.call("serai_isFinalized", &format!(r#"["{block}"]"#)).await
|
||||
@@ -146,11 +151,11 @@ impl Serai {
|
||||
Self::block_internal(self.call("serai_block", &format!("[{block}]"))).await
|
||||
}
|
||||
|
||||
/// Scope this RPC client to the state as of specific block.
|
||||
/// Scope this RPC client to the state as of a specific block.
|
||||
///
|
||||
/// This will yield an error if the block chosen isn't finalized. This ensures, given an honest
|
||||
/// node, that this scope will be available for the lifetime of this object.
|
||||
pub async fn at<'a>(&'a self, block: BlockHash) -> Result<TemporalSerai<'a>, RpcError> {
|
||||
pub async fn as_of<'a>(&'a self, block: BlockHash) -> Result<TemporalSerai<'a>, RpcError> {
|
||||
if !self.finalized(block).await? {
|
||||
Err(RpcError::NotFinalized)?;
|
||||
}
|
||||
|
||||
@@ -7,13 +7,50 @@ async fn blockchain() {
|
||||
"alice",
|
||||
serai_docker_tests::fresh_logs_folder(true, "serai-client/blockchain"),
|
||||
);
|
||||
test.provide_container(composition);
|
||||
test.provide_container(
|
||||
composition
|
||||
.replace_cmd(
|
||||
["serai-node", "--unsafe-rpc-external", "--rpc-cors", "all", "--dev"]
|
||||
.into_iter()
|
||||
.map(str::to_owned)
|
||||
.collect(),
|
||||
)
|
||||
.replace_env([("RUST_LOG".to_string(), "runtime=debug".to_string())].into()),
|
||||
);
|
||||
|
||||
test
|
||||
.run_async(async |ops| {
|
||||
let serai = serai_substrate_tests::rpc(&ops, handle).await;
|
||||
let block = serai.block_by_number(0).await.unwrap();
|
||||
assert_eq!(serai.block(block.header.hash()).await.unwrap(), block);
|
||||
assert!(serai.finalized(block.header.hash()).await.unwrap());
|
||||
|
||||
let test_block = |number| {
|
||||
let serai = &serai;
|
||||
async move {
|
||||
let block = serai.block_by_number(number).await.unwrap();
|
||||
assert_eq!(serai.block(block.header.hash()).await.unwrap(), block);
|
||||
assert!(serai.finalized(block.header.hash()).await.unwrap());
|
||||
}
|
||||
};
|
||||
|
||||
test_block(0).await;
|
||||
let finalized = serai.latest_finalized_block_number().await.unwrap();
|
||||
test_block(finalized).await;
|
||||
|
||||
let mut next_finalized;
|
||||
{
|
||||
let mut i = 0;
|
||||
while {
|
||||
next_finalized = serai.latest_finalized_block_number().await.unwrap();
|
||||
next_finalized == finalized
|
||||
} {
|
||||
tokio::time::sleep(core::time::Duration::from_secs(6)).await;
|
||||
i += 1;
|
||||
assert!(i < 50, "serai didn't finalize a block within five minutes");
|
||||
}
|
||||
}
|
||||
assert!(next_finalized > finalized);
|
||||
test_block(next_finalized).await;
|
||||
|
||||
println!("Finished `serai-client/blockchain` test");
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user