Skip to content

Commit

Permalink
fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
magecnion committed Dec 18, 2024
1 parent 5e82c0b commit 2c45afc
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 38 deletions.
4 changes: 2 additions & 2 deletions client/cli/src/frontier_db_cmd/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ fn tips_update_works() {
let test_value_path = test_json_file(&tmp, &tips_test_value());
// Test client.
let (client, _) = TestClientBuilder::new().build_with_native_executor::<RuntimeApi, _>(None);
let mut client = Arc::new(client);
let client = Arc::new(client);
// Create a temporary frontier secondary DB.
let backend = open_frontier_backend::<OpaqueBlock, _>(client.clone(), tmp.into_path())
.expect("a temporary db was created");
Expand All @@ -394,7 +394,7 @@ fn tips_delete_works() {
let tmp = tempdir().expect("create a temporary directory");
// Test client.
let (client, _) = TestClientBuilder::new().build_with_native_executor::<RuntimeApi, _>(None);
let mut client = Arc::new(client);
let client = Arc::new(client);
// Create a temporary frontier secondary DB.
let backend = open_frontier_backend::<OpaqueBlock, _>(client.clone(), tmp.into_path())
.expect("a temporary db was created");
Expand Down
5 changes: 3 additions & 2 deletions test-utils/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl<Block: BlockT, ExecutorDispatch, G: GenesisInit>
{
/// Create new `TestClientBuilder` with default backend.
pub fn with_default_backend() -> Self {
let backend = Arc::new(Backend::new_test(std::u32::MAX, std::u64::MAX));
let backend = Arc::new(Backend::new_test(u32::MAX, u64::MAX));
Self::with_backend(backend)
}

Expand Down Expand Up @@ -253,6 +253,7 @@ impl<Block: BlockT, ExecutorDispatch, Backend, G: GenesisInit>
}
}

#[allow(clippy::type_complexity)]
impl<Block: BlockT, H, Backend, G: GenesisInit>
TestClientBuilder<Block, client::LocalCallExecutor<Block, Backend, WasmExecutor<H>>, Backend, G>
{
Expand Down Expand Up @@ -348,7 +349,7 @@ impl RpcHandlersExt for RpcHandlers {
"params": ["0x{}"],
"id": 0
}}"#,
array_bytes::bytes2hex("", &extrinsic.encode())
array_bytes::bytes2hex("", extrinsic.encode())
))
.await
.expect("valid JSON-RPC request object; qed");
Expand Down
12 changes: 6 additions & 6 deletions test-utils/runtime/client/src/trait_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ use sp_runtime::traits::Block as BlockT;
use substrate_test_runtime::Transfer;

/// helper to test the `leaves` implementation for various backends
pub fn test_leaves_for_backend<B: 'static>(backend: Arc<B>)
pub fn test_leaves_for_backend<B>(backend: Arc<B>)
where
B: backend::Backend<substrate_test_runtime::Block>,
B: 'static + backend::Backend<substrate_test_runtime::Block>,
{
// block tree:
// G -> A1 -> A2 -> A3 -> A4 -> A5
Expand Down Expand Up @@ -217,9 +217,9 @@ where
}

/// helper to test the `children` implementation for various backends
pub fn test_children_for_backend<B: 'static>(backend: Arc<B>)
pub fn test_children_for_backend<B>(backend: Arc<B>)
where
B: backend::LocalBackend<substrate_test_runtime::Block>,
B: 'static + backend::LocalBackend<substrate_test_runtime::Block>,
{
// block tree:
// G -> A1 -> A2 -> A3 -> A4 -> A5
Expand Down Expand Up @@ -387,9 +387,9 @@ where
assert_eq!(vec![b3.hash(), c3.hash()], children4);
}

pub fn test_blockchain_query_by_number_gets_canonical<B: 'static>(backend: Arc<B>)
pub fn test_blockchain_query_by_number_gets_canonical<B>(backend: Arc<B>)
where
B: backend::LocalBackend<substrate_test_runtime::Block>,
B: 'static + backend::LocalBackend<substrate_test_runtime::Block>,
{
// block tree:
// G -> A1 -> A2 -> A3 -> A4 -> A5
Expand Down
9 changes: 3 additions & 6 deletions test-utils/runtime/src/genesismap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ impl Default for GenesisStorageBuilder {
Sr25519Keyring::Charlie.into(),
],
(0..16_usize)
.into_iter()
.map(|i| AccountKeyring::numeric(i).public())
.chain(vec![
AccountKeyring::Alice.into(),
Expand Down Expand Up @@ -93,7 +92,7 @@ impl GenesisStorageBuilder {

/// Override default wasm code to be placed into RuntimeGenesisConfig.
pub fn with_wasm_code(mut self, wasm_code: &Option<Vec<u8>>) -> Self {
self.wasm_code = wasm_code.clone();
self.wasm_code.clone_from(wasm_code);
self
}

Expand All @@ -113,7 +112,7 @@ impl GenesisStorageBuilder {
.authorities
.clone()
.into_iter()
.map(|id| sr25519::Public::from(id))
.map(sr25519::Public::from)
.collect();

RuntimeGenesisConfig {
Expand Down Expand Up @@ -181,7 +180,5 @@ pub fn insert_genesis_block(storage: &mut Storage) -> sp_core::hash::H256 {
sp_runtime::StateVersion::V1,
);
let block: crate::Block = construct_genesis_block(state_root, StateVersion::V1);
let genesis_hash = block.header.hash();

genesis_hash
block.header.hash()
}
31 changes: 14 additions & 17 deletions test-utils/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ decl_runtime_apis! {
fn benchmark_add_one(val: &u64) -> u64;
/// A benchmark function that adds one to each value in the given vector and returns the
/// result.
#[allow(clippy::ptr_arg)]
fn benchmark_vector_add_one(vec: &Vec<u64>) -> Vec<u64>;
/// A function for that the signature changed in version `2`.
#[changed_in(2)]
Expand Down Expand Up @@ -372,7 +373,7 @@ pub mod currency {
}

parameter_types! {
pub const ExistentialDeposit: Balance = 1 * currency::DOLLARS;
pub const ExistentialDeposit: Balance = currency::DOLLARS;
// For weight estimation, we assume that the most locks on an individual account will be 50.
// This number may need to be adjusted in the future if this assumption no longer holds true.
pub const MaxLocks: u32 = 50;
Expand Down Expand Up @@ -627,7 +628,7 @@ impl_runtime_apis! {
}

fn authorities() -> Vec<AuraId> {
SubstrateTest::authorities().into_iter().map(|auth| AuraId::from(auth)).collect()
SubstrateTest::authorities().into_iter().map(AuraId::from).collect()
}
}

Expand Down Expand Up @@ -734,8 +735,8 @@ impl_runtime_apis! {
let patch = match name.try_into() {
Ok("staging") => {
let endowed_accounts: Vec<AccountId> = vec![
AccountKeyring::Bob.public().into(),
AccountKeyring::Charlie.public().into(),
AccountKeyring::Bob.public(),
AccountKeyring::Charlie.public(),
];

json!({
Expand Down Expand Up @@ -881,6 +882,7 @@ pub mod storage_key_generator {
x.hex(Default::default())
}

#[allow(clippy::ptr_arg)]
fn concat_hashes(input: &Vec<&[u8]>) -> String {
input
.iter()
Expand Down Expand Up @@ -927,7 +929,6 @@ pub mod storage_key_generator {
expected_keys.extend(literals.into_iter().map(hex));

let balances_map_keys = (0..16_usize)
.into_iter()
.map(|i| AccountKeyring::numeric(i).public().to_vec())
.chain(vec![
AccountKeyring::Alice.public().to_vec(),
Expand Down Expand Up @@ -1156,10 +1157,7 @@ mod tests {

pub fn new_test_ext() -> sp_io::TestExternalities {
genesismap::GenesisStorageBuilder::new(
vec![
AccountKeyring::One.public().into(),
AccountKeyring::Two.public().into(),
],
vec![AccountKeyring::One.public(), AccountKeyring::Two.public()],
vec![AccountKeyring::One.into(), AccountKeyring::Two.into()],
1000 * currency::DOLLARS,
)
Expand Down Expand Up @@ -1253,8 +1251,8 @@ mod tests {
16
);

assert_eq!(
CheckSubstrateCall {}
assert!(
!CheckSubstrateCall {}
.validate(
&x,
&ExtrinsicBuilder::new_call_do_not_propagate()
Expand All @@ -1264,8 +1262,7 @@ mod tests {
len
)
.unwrap()
.propagate,
false
.propagate
);
})
}
Expand Down Expand Up @@ -1371,7 +1368,7 @@ mod tests {
let r = Option::<Vec<u8>>::decode(&mut &r[..])
.unwrap()
.expect("default config is there");
let json = String::from_utf8(r.into()).expect("returned value is json. qed.");
let json = String::from_utf8(r).expect("returned value is json. qed.");

let expected = r#"{"system":{},"babe":{"authorities":[],"epochConfig":{"c":[1,4],"allowed_slots":"PrimaryAndSecondaryVRFSlots"}},"substrateTest":{"authorities":[]},"balances":{"balances":[]}}"#;
assert_eq!(expected.to_string(), json);
Expand All @@ -1381,7 +1378,7 @@ mod tests {
fn preset_names_listing_works() {
sp_tracing::try_init_simple();
let mut t = BasicExternalities::new_empty();
let r = executor_call(&mut t, "GenesisBuilder_preset_names", &vec![]).unwrap();
let r = executor_call(&mut t, "GenesisBuilder_preset_names", &[]).unwrap();
let r = Vec::<PresetId>::decode(&mut &r[..]).unwrap();
assert_eq!(
r,
Expand All @@ -1403,8 +1400,7 @@ mod tests {
)
.unwrap();
let r = Option::<Vec<u8>>::decode(&mut &r[..]).unwrap();
let json =
String::from_utf8(r.unwrap().into()).expect("returned value is json. qed.");
let json = String::from_utf8(r.unwrap()).expect("returned value is json. qed.");
log::info!("json: {:#?}", json);
assert_eq!(expected.to_string(), json);
};
Expand Down Expand Up @@ -1498,6 +1494,7 @@ mod tests {
sp_tracing::try_init_simple();
let mut file = fs::OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open("/tmp/default_genesis_config.json")
.unwrap();
Expand Down
8 changes: 3 additions & 5 deletions test-utils/runtime/src/substrate_test_pallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,10 @@ pub mod pallet {
sp_io::storage::get(&next);

next_key = next;
} else if panic_at_end {
return Ok(());
} else {
if panic_at_end {
return Ok(());
} else {
panic!("Could not read {read} times from the state");
}
panic!("Could not read {read} times from the state");
}
}

Expand Down

0 comments on commit 2c45afc

Please sign in to comment.