mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 04:41:02 +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:
@@ -15,15 +15,13 @@
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use always_assert::always;
|
||||
use async_std::{
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
use async_std::path::{Path, PathBuf};
|
||||
use parity_scale_codec::{Decode, Encode};
|
||||
use polkadot_parachain::primitives::ValidationCodeHash;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
time::{Duration, SystemTime},
|
||||
};
|
||||
use parity_scale_codec::{Encode, Decode};
|
||||
|
||||
/// A final product of preparation process. Contains either a ready to run compiled artifact or
|
||||
/// a description what went wrong.
|
||||
@@ -70,8 +68,8 @@ impl ArtifactId {
|
||||
/// Tries to recover the artifact id from the given file name.
|
||||
#[cfg(test)]
|
||||
pub fn from_file_name(file_name: &str) -> Option<Self> {
|
||||
use std::str::FromStr as _;
|
||||
use polkadot_core_primitives::Hash;
|
||||
use std::str::FromStr as _;
|
||||
|
||||
let file_name = file_name.strip_prefix(Self::PREFIX)?;
|
||||
let code_hash = Hash::from_str(file_name).ok()?.into();
|
||||
@@ -123,9 +121,7 @@ impl Artifacts {
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn empty() -> Self {
|
||||
Self {
|
||||
artifacts: HashMap::new(),
|
||||
}
|
||||
Self { artifacts: HashMap::new() }
|
||||
}
|
||||
|
||||
/// Returns the state of the given artifact by its ID.
|
||||
@@ -139,10 +135,7 @@ impl Artifacts {
|
||||
/// replacing existing ones.
|
||||
pub fn insert_preparing(&mut self, artifact_id: ArtifactId) {
|
||||
// See the precondition.
|
||||
always!(self
|
||||
.artifacts
|
||||
.insert(artifact_id, ArtifactState::Preparing)
|
||||
.is_none());
|
||||
always!(self.artifacts.insert(artifact_id, ArtifactState::Preparing).is_none());
|
||||
}
|
||||
|
||||
/// Insert an artifact with the given ID as "prepared".
|
||||
@@ -164,9 +157,7 @@ impl Artifacts {
|
||||
|
||||
let mut to_remove = vec![];
|
||||
for (k, v) in self.artifacts.iter() {
|
||||
if let ArtifactState::Prepared {
|
||||
last_time_needed, ..
|
||||
} = *v {
|
||||
if let ArtifactState::Prepared { last_time_needed, .. } = *v {
|
||||
if now
|
||||
.duration_since(last_time_needed)
|
||||
.map(|age| age > artifact_ttl)
|
||||
@@ -187,8 +178,8 @@ impl Artifacts {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{ArtifactId, Artifacts};
|
||||
use async_std::path::Path;
|
||||
use super::{Artifacts, ArtifactId};
|
||||
use sp_core::H256;
|
||||
use std::str::FromStr;
|
||||
|
||||
@@ -213,17 +204,24 @@ mod tests {
|
||||
#[test]
|
||||
fn path() {
|
||||
let path = Path::new("/test");
|
||||
let hash = H256::from_str("1234567890123456789012345678901234567890123456789012345678901234").unwrap().into();
|
||||
let hash =
|
||||
H256::from_str("1234567890123456789012345678901234567890123456789012345678901234")
|
||||
.unwrap()
|
||||
.into();
|
||||
|
||||
assert_eq!(
|
||||
ArtifactId::new(hash).path(path).to_str(),
|
||||
Some("/test/wasmtime_0x1234567890123456789012345678901234567890123456789012345678901234"),
|
||||
Some(
|
||||
"/test/wasmtime_0x1234567890123456789012345678901234567890123456789012345678901234"
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn artifacts_removes_cache_on_startup() {
|
||||
let fake_cache_path = async_std::task::block_on(async move { crate::worker_common::tmpfile("test-cache").await.unwrap() });
|
||||
let fake_cache_path = async_std::task::block_on(async move {
|
||||
crate::worker_common::tmpfile("test-cache").await.unwrap()
|
||||
});
|
||||
let fake_artifact_path = {
|
||||
let mut p = fake_cache_path.clone();
|
||||
p.push("wasmtime_0x1234567890123456789012345678901234567890123456789012345678901234");
|
||||
|
||||
Reference in New Issue
Block a user