Skip to content

Commit

Permalink
more clippy + use more default
Browse files Browse the repository at this point in the history
  • Loading branch information
nanocryk committed Feb 16, 2024
1 parent c86552e commit d6f1c4e
Show file tree
Hide file tree
Showing 17 changed files with 233 additions and 276 deletions.
4 changes: 2 additions & 2 deletions container-chains/templates/frontier/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ pub fn run() -> Result<()> {
.into(),
)),
#[cfg(feature = "runtime-benchmarks")]
BenchmarkCmd::Storage(cmd) => runner.sync_run(|mut config| {
let partials = NodeConfig::new_builder(&mut config, None)?;
BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| {
let partials = NodeConfig::new_builder(&config, None)?;
let db = partials.backend.expose_db();
let storage = partials.backend.expose_storage();
cmd.run(config, partials.client.clone(), db, storage)
Expand Down
96 changes: 34 additions & 62 deletions pallets/author-noting/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,30 @@ use {
hex_literal::hex,
parity_scale_codec::Encode,
sp_consensus_aura::{inherents::InherentType, AURA_ENGINE_ID},
sp_core::H256,
sp_core::{H256, U256},
sp_runtime::{
generic::DigestItem,
traits::{BlakeTwo256, HashingFor},
traits::{BlakeTwo256, Hash as HashT, HashingFor},
},
test_relay_sproof_builder::{HeaderAs, ParaHeaderSproofBuilder, ParaHeaderSproofBuilderItem},
tp_traits::GetCurrentContainerChains,
};

fn default<T: Default>() -> T {
T::default()
}

fn default_header<Number: Copy + Into<U256> + TryFrom<U256> + Default, Hash: HashT>(
) -> sp_runtime::generic::Header<Number, Hash> {
sp_runtime::generic::Header {
parent_hash: default(),
number: default(),
state_root: default(),
extrinsics_root: default(),
digest: default(),
}
}

#[test]
fn test_author_id_insertion() {
BlockTests::new()
Expand All @@ -49,13 +64,11 @@ fn test_author_id_insertion() {
u32,
BlakeTwo256,
> {
parent_hash: Default::default(),
number: 1,
state_root: Default::default(),
extrinsics_root: Default::default(),
digest: sp_runtime::generic::Digest {
logs: vec![DigestItem::PreRuntime(AURA_ENGINE_ID, slot.encode())],
},
..default_header()
}),
};
sproof.items.push(s);
Expand Down Expand Up @@ -126,13 +139,11 @@ fn test_author_id_insertion_many_paras() {
u32,
BlakeTwo256,
> {
parent_hash: Default::default(),
number: 1,
state_root: Default::default(),
extrinsics_root: Default::default(),
digest: sp_runtime::generic::Digest {
logs: vec![DigestItem::PreRuntime(AURA_ENGINE_ID, slot.encode())],
},
..default_header()
}),
};
sproof.items.push(s);
Expand All @@ -145,13 +156,11 @@ fn test_author_id_insertion_many_paras() {
u32,
BlakeTwo256,
> {
parent_hash: Default::default(),
number: 2,
state_root: Default::default(),
extrinsics_root: Default::default(),
digest: sp_runtime::generic::Digest {
logs: vec![DigestItem::PreRuntime(AURA_ENGINE_ID, slot.encode())],
},
..default_header()
}),
};
sproof.items.push(s);
Expand All @@ -163,13 +172,11 @@ fn test_author_id_insertion_many_paras() {
u32,
BlakeTwo256,
> {
parent_hash: Default::default(),
number: 1,
state_root: Default::default(),
extrinsics_root: Default::default(),
digest: sp_runtime::generic::Digest {
logs: vec![DigestItem::PreRuntime(AURA_ENGINE_ID, slot.encode())],
},
..default_header()
}),
};
sproof.items.push(s);
Expand Down Expand Up @@ -222,13 +229,11 @@ fn test_should_panic_with_invalid_proof_root() {
u32,
BlakeTwo256,
> {
parent_hash: Default::default(),
number: 1,
state_root: Default::default(),
extrinsics_root: Default::default(),
digest: sp_runtime::generic::Digest {
logs: vec![DigestItem::PreRuntime(AURA_ENGINE_ID, slot.encode())],
},
..default_header()
}),
};
sproof.items.push(s);
Expand Down Expand Up @@ -264,13 +269,11 @@ fn test_should_panic_with_invalid_proof_state() {
u32,
BlakeTwo256,
> {
parent_hash: Default::default(),
number: 1,
state_root: Default::default(),
extrinsics_root: Default::default(),
digest: sp_runtime::generic::Digest {
logs: vec![DigestItem::PreRuntime(AURA_ENGINE_ID, slot.encode())],
},
..default_header()
}),
};
sproof.items.push(s);
Expand Down Expand Up @@ -301,13 +304,10 @@ fn test_should_panic_with_proof_for_not_including_required_para() {
let para_id_1001_item = ParaHeaderSproofBuilderItem {
para_id: 1001.into(),
author_id: HeaderAs::NonEncoded(sp_runtime::generic::Header::<u32, BlakeTwo256> {
parent_hash: Default::default(),
number: Default::default(),
state_root: Default::default(),
extrinsics_root: Default::default(),
digest: sp_runtime::generic::Digest {
logs: vec![DigestItem::PreRuntime(AURA_ENGINE_ID, slot.encode())],
},
..default_header()
}),
};

Expand All @@ -321,13 +321,10 @@ fn test_should_panic_with_proof_for_not_including_required_para() {
let para_id_1002_item = ParaHeaderSproofBuilderItem {
para_id: 1002.into(),
author_id: HeaderAs::NonEncoded(sp_runtime::generic::Header::<u32, BlakeTwo256> {
parent_hash: Default::default(),
number: Default::default(),
state_root: Default::default(),
extrinsics_root: Default::default(),
digest: sp_runtime::generic::Digest {
logs: vec![DigestItem::PreRuntime(AURA_ENGINE_ID, slot.encode())],
},
..default_header()
}),
};
proof_item.items.push(para_id_1002_item.clone());
Expand Down Expand Up @@ -370,13 +367,10 @@ fn test_should_panic_with_empty_proof() {
para_id_1001_item.para_id = 1001.into();
para_id_1001_item.author_id =
HeaderAs::NonEncoded(sp_runtime::generic::Header::<u32, BlakeTwo256> {
parent_hash: Default::default(),
number: Default::default(),
state_root: Default::default(),
extrinsics_root: Default::default(),
digest: sp_runtime::generic::Digest {
logs: vec![DigestItem::PreRuntime(AURA_ENGINE_ID, slot.encode())],
},
..default_header()
});
proof_item.items.push(para_id_1001_item.clone());

Expand Down Expand Up @@ -416,13 +410,10 @@ fn test_not_inserting_inherent() {
u32,
BlakeTwo256,
> {
parent_hash: Default::default(),
number: Default::default(),
state_root: Default::default(),
extrinsics_root: Default::default(),
digest: sp_runtime::generic::Digest {
logs: vec![DigestItem::PreRuntime(AURA_ENGINE_ID, slot.encode())],
},
..default_header()
}),
};
sproof.items.push(s);
Expand All @@ -449,13 +440,10 @@ fn encode_proof_for_benchmarks() {
para_id: para_id.into(),
// TODO: this header can be arbitrarily large, because "digest.logs" is an unbounded vec
author_id: HeaderAs::NonEncoded(dp_core::Header {
parent_hash: Default::default(),
number: Default::default(),
state_root: Default::default(),
extrinsics_root: Default::default(),
digest: sp_runtime::generic::Digest {
logs: vec![DigestItem::PreRuntime(AURA_ENGINE_ID, slot.encode())],
},
..default_header()
}),
};
sproof_builder.items.push(s);
Expand Down Expand Up @@ -487,13 +475,11 @@ fn test_set_author() {
u32,
BlakeTwo256,
> {
parent_hash: Default::default(),
number: 1,
state_root: Default::default(),
extrinsics_root: Default::default(),
digest: sp_runtime::generic::Digest {
logs: vec![DigestItem::PreRuntime(AURA_ENGINE_ID, slot.encode())],
},
..default_header()
}),
};
sproof.items.push(s);
Expand Down Expand Up @@ -547,13 +533,10 @@ fn test_on_initalize_does_not_kill_and_panics() {
u32,
BlakeTwo256,
> {
parent_hash: Default::default(),
number: Default::default(),
state_root: Default::default(),
extrinsics_root: Default::default(),
digest: sp_runtime::generic::Digest {
logs: vec![DigestItem::PreRuntime(AURA_ENGINE_ID, slot.encode())],
},
..default_header()
}),
};

Expand Down Expand Up @@ -595,17 +578,14 @@ fn test_non_aura_digest_does_not_insert_key() {
u32,
BlakeTwo256,
> {
parent_hash: Default::default(),
number: Default::default(),
state_root: Default::default(),
extrinsics_root: Default::default(),
// we inject a non-aura digest
digest: sp_runtime::generic::Digest {
logs: vec![DigestItem::PreRuntime(
[b'a', b'a', b'a', b'a'],
slot.encode(),
)],
},
..default_header()
}),
};
sproof.items.push(s);
Expand All @@ -628,14 +608,11 @@ fn test_non_decodable_slot_does_not_insert_key() {
u32,
BlakeTwo256,
> {
parent_hash: Default::default(),
number: Default::default(),
state_root: Default::default(),
extrinsics_root: Default::default(),
// we inject 1u8 slot, but inherentType is expected so it should not decode
digest: sp_runtime::generic::Digest {
logs: vec![DigestItem::PreRuntime(AURA_ENGINE_ID, 1u8.encode())],
},
..default_header()
}),
};
sproof.items.push(s);
Expand Down Expand Up @@ -702,13 +679,10 @@ fn test_kill_author_data() {
u32,
BlakeTwo256,
> {
parent_hash: Default::default(),
number: 1,
state_root: Default::default(),
extrinsics_root: Default::default(),
digest: sp_runtime::generic::Digest {
logs: vec![DigestItem::PreRuntime(AURA_ENGINE_ID, slot.encode())],
},
..default_header()
}),
};
sproof.items.push(s);
Expand Down Expand Up @@ -749,17 +723,15 @@ fn test_author_id_insertion_not_first_log() {
u32,
BlakeTwo256,
> {
parent_hash: Default::default(),
number: 1,
state_root: Default::default(),
extrinsics_root: Default::default(),
digest: sp_runtime::generic::Digest {
logs: vec![
// Dummy item before aura log
DigestItem::PreRuntime([0; 4], vec![]),
DigestItem::PreRuntime(AURA_ENGINE_ID, slot.encode()),
],
},
..default_header()
}),
};
sproof.items.push(s);
Expand Down
8 changes: 2 additions & 6 deletions pallets/collator-assignment/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ fn invulnerable<T: Config>(c: u32, seed: u32) -> T::AccountId {
}

fn invulnerables<T: Config + frame_system::Config>(count: u32, seed: u32) -> Vec<T::AccountId> {
let invulnerables = (0..count)
.map(|c| invulnerable::<T>(c, seed))
.collect::<Vec<_>>();

invulnerables
(0..count).map(|c| invulnerable::<T>(c, seed)).collect()
}

fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
Expand All @@ -69,7 +65,7 @@ mod benchmarks {
frame_system::Pallet::<T>::set_block_number(0u32.into());

let collators = invulnerables::<T>(x, SEED);
let container_chains: Vec<_> = (0..y).map(|para_id| ParaId::from(para_id)).collect();
let container_chains: Vec<_> = (0..y).map(ParaId::from).collect();
let session_index = 0u32.into();
T::ContainerChains::set_session_container_chains(session_index, &container_chains);
T::RemoveParaIdsWithNoCredits::make_valid_para_ids(&container_chains);
Expand Down
2 changes: 1 addition & 1 deletion pallets/data-preservers/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ mod benchmarks {
#[extrinsic_call]
Pallet::<T>::set_boot_nodes(origin as T::RuntimeOrigin, para_id, boot_nodes.clone());

assert_eq!(Pallet::<T>::boot_nodes(&para_id), boot_nodes);
assert_eq!(Pallet::<T>::boot_nodes(para_id), boot_nodes);
}

impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
Expand Down
Loading

0 comments on commit d6f1c4e

Please sign in to comment.