mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 13:17:56 +00:00
cargo +nightly fmt (#3540)
* cargo +nightly fmt * add cargo-fmt check to ci * update ci * fmt * fmt * skip macro * ignore bridges
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
use super::*;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use futures::{future::BoxFuture, channel::oneshot};
|
||||
use futures::{channel::oneshot, future::BoxFuture};
|
||||
use parity_scale_codec::Encode;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use polkadot_primitives::v1::{Hash, BlockNumber, BlockId, Header};
|
||||
use polkadot_node_primitives::BlockWeight;
|
||||
use polkadot_node_subsystem_test_helpers::{make_subsystem_context, TestSubsystemContextHandle};
|
||||
use polkadot_primitives::v1::{BlockId, BlockNumber, Hash, Header};
|
||||
use sp_blockchain::Info as BlockInfo;
|
||||
use sp_core::testing::TaskExecutor;
|
||||
|
||||
@@ -79,10 +79,7 @@ impl Default for TestClient {
|
||||
|
||||
fn last_key_value<K: Clone, V: Clone>(map: &BTreeMap<K, V>) -> (K, V) {
|
||||
assert!(!map.is_empty());
|
||||
map.iter()
|
||||
.last()
|
||||
.map(|(k, v)| (k.clone(), v.clone()))
|
||||
.unwrap()
|
||||
map.iter().last().map(|(k, v)| (k.clone(), v.clone())).unwrap()
|
||||
}
|
||||
|
||||
impl HeaderBackend<Block> for TestClient {
|
||||
@@ -110,12 +107,9 @@ impl HeaderBackend<Block> for TestClient {
|
||||
fn header(&self, id: BlockId) -> sp_blockchain::Result<Option<Header>> {
|
||||
match id {
|
||||
// for error path testing
|
||||
BlockId::Hash(hash) if hash.is_zero() => {
|
||||
Err(sp_blockchain::Error::Backend("Zero hashes are illegal!".into()))
|
||||
}
|
||||
BlockId::Hash(hash) => {
|
||||
Ok(self.headers.get(&hash).cloned())
|
||||
}
|
||||
BlockId::Hash(hash) if hash.is_zero() =>
|
||||
Err(sp_blockchain::Error::Backend("Zero hashes are illegal!".into())),
|
||||
BlockId::Hash(hash) => Ok(self.headers.get(&hash).cloned()),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
@@ -125,8 +119,10 @@ impl HeaderBackend<Block> for TestClient {
|
||||
}
|
||||
|
||||
fn test_harness(
|
||||
test: impl FnOnce(Arc<TestClient>, TestSubsystemContextHandle<ChainApiMessage>)
|
||||
-> BoxFuture<'static, ()>,
|
||||
test: impl FnOnce(
|
||||
Arc<TestClient>,
|
||||
TestSubsystemContextHandle<ChainApiMessage>,
|
||||
) -> BoxFuture<'static, ()>,
|
||||
) {
|
||||
let (ctx, ctx_handle) = make_subsystem_context(TaskExecutor::new());
|
||||
let client = Arc::new(TestClient::default());
|
||||
@@ -174,15 +170,18 @@ fn request_block_number() {
|
||||
for (hash, expected) in &test_cases {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
|
||||
sender.send(FromOverseer::Communication {
|
||||
msg: ChainApiMessage::BlockNumber(*hash, tx),
|
||||
}).await;
|
||||
sender
|
||||
.send(FromOverseer::Communication {
|
||||
msg: ChainApiMessage::BlockNumber(*hash, tx),
|
||||
})
|
||||
.await;
|
||||
|
||||
assert_eq!(rx.await.unwrap().unwrap(), *expected);
|
||||
}
|
||||
|
||||
sender.send(FromOverseer::Signal(OverseerSignal::Conclude)).await;
|
||||
}.boxed()
|
||||
}
|
||||
.boxed()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -198,15 +197,18 @@ fn request_block_header() {
|
||||
for (hash, expected) in &test_cases {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
|
||||
sender.send(FromOverseer::Communication {
|
||||
msg: ChainApiMessage::BlockHeader(*hash, tx),
|
||||
}).await;
|
||||
sender
|
||||
.send(FromOverseer::Communication {
|
||||
msg: ChainApiMessage::BlockHeader(*hash, tx),
|
||||
})
|
||||
.await;
|
||||
|
||||
assert_eq!(rx.await.unwrap().unwrap(), *expected);
|
||||
}
|
||||
|
||||
sender.send(FromOverseer::Signal(OverseerSignal::Conclude)).await;
|
||||
}.boxed()
|
||||
}
|
||||
.boxed()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -223,15 +225,18 @@ fn request_block_weight() {
|
||||
for (hash, expected) in &test_cases {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
|
||||
sender.send(FromOverseer::Communication {
|
||||
msg: ChainApiMessage::BlockWeight(*hash, tx),
|
||||
}).await;
|
||||
sender
|
||||
.send(FromOverseer::Communication {
|
||||
msg: ChainApiMessage::BlockWeight(*hash, tx),
|
||||
})
|
||||
.await;
|
||||
|
||||
assert_eq!(rx.await.unwrap().unwrap(), *expected);
|
||||
}
|
||||
|
||||
sender.send(FromOverseer::Signal(OverseerSignal::Conclude)).await;
|
||||
}.boxed()
|
||||
}
|
||||
.boxed()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -246,15 +251,18 @@ fn request_finalized_hash() {
|
||||
for (number, expected) in &test_cases {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
|
||||
sender.send(FromOverseer::Communication {
|
||||
msg: ChainApiMessage::FinalizedBlockHash(*number, tx),
|
||||
}).await;
|
||||
sender
|
||||
.send(FromOverseer::Communication {
|
||||
msg: ChainApiMessage::FinalizedBlockHash(*number, tx),
|
||||
})
|
||||
.await;
|
||||
|
||||
assert_eq!(rx.await.unwrap().unwrap(), *expected);
|
||||
}
|
||||
|
||||
sender.send(FromOverseer::Signal(OverseerSignal::Conclude)).await;
|
||||
}.boxed()
|
||||
}
|
||||
.boxed()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -265,14 +273,17 @@ fn request_last_finalized_number() {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
|
||||
let expected = client.info().finalized_number;
|
||||
sender.send(FromOverseer::Communication {
|
||||
msg: ChainApiMessage::FinalizedBlockNumber(tx),
|
||||
}).await;
|
||||
sender
|
||||
.send(FromOverseer::Communication {
|
||||
msg: ChainApiMessage::FinalizedBlockNumber(tx),
|
||||
})
|
||||
.await;
|
||||
|
||||
assert_eq!(rx.await.unwrap().unwrap(), expected);
|
||||
|
||||
sender.send(FromOverseer::Signal(OverseerSignal::Conclude)).await;
|
||||
}.boxed()
|
||||
}
|
||||
.boxed()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -281,24 +292,35 @@ fn request_ancestors() {
|
||||
test_harness(|_client, mut sender| {
|
||||
async move {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
sender.send(FromOverseer::Communication {
|
||||
msg: ChainApiMessage::Ancestors { hash: THREE, k: 4, response_channel: tx },
|
||||
}).await;
|
||||
sender
|
||||
.send(FromOverseer::Communication {
|
||||
msg: ChainApiMessage::Ancestors { hash: THREE, k: 4, response_channel: tx },
|
||||
})
|
||||
.await;
|
||||
assert_eq!(rx.await.unwrap().unwrap(), vec![TWO, ONE]);
|
||||
|
||||
let (tx, rx) = oneshot::channel();
|
||||
sender.send(FromOverseer::Communication {
|
||||
msg: ChainApiMessage::Ancestors { hash: TWO, k: 1, response_channel: tx },
|
||||
}).await;
|
||||
sender
|
||||
.send(FromOverseer::Communication {
|
||||
msg: ChainApiMessage::Ancestors { hash: TWO, k: 1, response_channel: tx },
|
||||
})
|
||||
.await;
|
||||
assert_eq!(rx.await.unwrap().unwrap(), vec![ONE]);
|
||||
|
||||
let (tx, rx) = oneshot::channel();
|
||||
sender.send(FromOverseer::Communication {
|
||||
msg: ChainApiMessage::Ancestors { hash: ERROR_PATH, k: 2, response_channel: tx },
|
||||
}).await;
|
||||
sender
|
||||
.send(FromOverseer::Communication {
|
||||
msg: ChainApiMessage::Ancestors {
|
||||
hash: ERROR_PATH,
|
||||
k: 2,
|
||||
response_channel: tx,
|
||||
},
|
||||
})
|
||||
.await;
|
||||
assert!(rx.await.unwrap().is_err());
|
||||
|
||||
sender.send(FromOverseer::Signal(OverseerSignal::Conclude)).await;
|
||||
}.boxed()
|
||||
}
|
||||
.boxed()
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user