Skip to content

Commit

Permalink
chore(gh): fix clippy findings
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey-N-Chernyshov committed Jan 30, 2024
1 parent 1e42ac4 commit 8d5091e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 58 deletions.
13 changes: 4 additions & 9 deletions pallets/beefy-light-client/src/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ impl ValidatorSet {

pub fn proofs(&self) -> Vec<Vec<H256>> {
(0..self.addresses.len())
.into_iter()
.map(|i| self.validator_pubkey_proof(i))
.collect()
}
Expand All @@ -132,10 +131,7 @@ impl ValidatorSet {
}

pub fn root(&self) -> H256 {
let root = beefy_merkle_tree::merkle_root::<sp_runtime::traits::Keccak256, _>(
self.addresses.clone(),
);
root
beefy_merkle_tree::merkle_root::<sp_runtime::traits::Keccak256, _>(self.addresses.clone())
}

fn authority_set(&self) -> sp_beefy::mmr::BeefyAuthoritySet<H256> {
Expand Down Expand Up @@ -235,11 +231,10 @@ enum MMRNode {

impl MMRNode {
fn hash(&self) -> H256 {
let hash = match self {
match self {
MMRNode::Leaf(leaf) => sp_runtime::traits::Keccak256::hash_of(leaf),
MMRNode::Hash(hash) => *hash,
};
hash
}
}
}

Expand Down Expand Up @@ -315,7 +310,7 @@ pub fn generate_fixture(validators: usize, tree_size: u32) -> AnyResult<Fixture>
sp_beefy::known_payloads::MMR_ROOT_ID,
mmr_root.encode(),
),
block_number: tree_size as u32,
block_number: tree_size,
validator_set_id: validator_set.id,
};
let signed_commitment = validator_set.sign_commitment(&mut rng, commitment, None);
Expand Down
7 changes: 3 additions & 4 deletions pallets/beefy-light-client/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,13 @@ fn validator_proof(
public_key_merkle_proofs.push(fixture.validator_set_proofs[i].clone());
}
}
let validator_proof = bridge_common::beefy_types::ValidatorProof {
ValidatorProof {
signatures: proof_signatures,
positions,
public_keys,
public_key_merkle_proofs: public_key_merkle_proofs,
public_key_merkle_proofs,
validator_claims_bitfield: initial_bitfield,
};
validator_proof
}
}

#[test_case(3, 5; "3 validators, 5 leaves")]
Expand Down
29 changes: 13 additions & 16 deletions pallets/data-signer/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ fn it_works_finish_add_peer() {
assert_ok!(DataSigner::register_network(
RuntimeOrigin::root(),
network_id,
peers.clone(),
peers,
));

let new_peer = test_signer().public();
Expand Down Expand Up @@ -533,7 +533,7 @@ fn it_fails_add_peer_no_pending_update() {
assert_ok!(DataSigner::register_network(
RuntimeOrigin::root(),
network_id,
peers.clone(),
peers,
));

let new_peer = test_signer().public();
Expand Down Expand Up @@ -569,7 +569,7 @@ fn it_works_validate_unsigned() {
assert_eq!(
<DataSigner as sp_runtime::traits::ValidateUnsigned>::validate_unsigned(
TransactionSource::External,
&call.into(),
&call,
),
TransactionValidity::Ok(
ValidTransaction::with_tag_prefix("DataSignerApprove")
Expand All @@ -594,7 +594,7 @@ fn it_fails_validate_unsigned_no_network() {
assert_ok!(DataSigner::register_network(
RuntimeOrigin::root(),
network_id,
peers.clone(),
peers,
));

let different_network_id = bridge_types::GenericNetworkId::Sub(SubNetworkId::Kusama);
Expand All @@ -611,7 +611,7 @@ fn it_fails_validate_unsigned_no_network() {
assert_eq!(
<DataSigner as sp_runtime::traits::ValidateUnsigned>::validate_unsigned(
TransactionSource::External,
&call.into(),
&call,
),
InvalidTransaction::BadSigner.into()
);
Expand All @@ -628,7 +628,7 @@ fn it_fails_validate_unsigned_bad_proof() {
assert_ok!(DataSigner::register_network(
RuntimeOrigin::root(),
network_id,
peers.clone(),
peers,
));

let data = [1u8; 32];
Expand All @@ -643,7 +643,7 @@ fn it_fails_validate_unsigned_bad_proof() {
assert_eq!(
<DataSigner as sp_runtime::traits::ValidateUnsigned>::validate_unsigned(
TransactionSource::External,
&call.into(),
&call,
),
InvalidTransaction::BadProof.into()
);
Expand All @@ -660,7 +660,7 @@ fn it_fails_validate_unsigned_bad_signer() {
assert_ok!(DataSigner::register_network(
RuntimeOrigin::root(),
network_id,
peers.clone(),
peers,
));

let data = [1u8; 32];
Expand All @@ -675,7 +675,7 @@ fn it_fails_validate_unsigned_bad_signer() {
assert_eq!(
<DataSigner as sp_runtime::traits::ValidateUnsigned>::validate_unsigned(
TransactionSource::External,
&call.into(),
&call,
),
InvalidTransaction::BadSigner.into()
);
Expand All @@ -692,7 +692,7 @@ fn it_fails_validate_unsigned_transaction_stale() {
assert_ok!(DataSigner::register_network(
RuntimeOrigin::root(),
network_id,
peers.clone(),
peers,
));

let data = [1u8; 32];
Expand All @@ -716,7 +716,7 @@ fn it_fails_validate_unsigned_transaction_stale() {
assert_eq!(
<DataSigner as sp_runtime::traits::ValidateUnsigned>::validate_unsigned(
TransactionSource::InBlock,
&call.into(),
&call,
),
InvalidTransaction::Stale.into()
);
Expand All @@ -736,15 +736,12 @@ fn it_fails_validate_unsigned_invalid_call() {
peers.clone(),
));

let call = Call::register_network {
network_id,
peers: peers.clone(),
};
let call = Call::register_network { network_id, peers };

assert_eq!(
<DataSigner as sp_runtime::traits::ValidateUnsigned>::validate_unsigned(
TransactionSource::External,
&call.into(),
&call,
),
InvalidTransaction::Call.into()
);
Expand Down
34 changes: 8 additions & 26 deletions pallets/parachain-app/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fn it_fails_mint_wrong_amount() {
let amount = 0;

assert_noop!(
ParachainApp::mint(origin_kusama, asset_id, sender, recipient.clone(), amount),
ParachainApp::mint(origin_kusama, asset_id, sender, recipient, amount),
Error::<Test>::WrongAmount
);
});
Expand Down Expand Up @@ -264,7 +264,7 @@ fn it_fails_burn_invalid_destination_params() {
// XCM destination > X2 not supported
assert_noop!(
ParachainApp::burn(
origin.clone().into(),
origin.into(),
network_id,
asset_id,
VersionedMultiLocation::V3(MultiLocation::new(
Expand Down Expand Up @@ -320,7 +320,7 @@ fn it_fails_burn_relaychain_asset_not_registered() {
)
.expect("XOR registration failed");
ParachainApp::finalize_asset_registration(
origin_kusama.clone(),
origin_kusama,
AssetId::XOR,
AssetKind::Thischain,
)
Expand Down Expand Up @@ -382,7 +382,7 @@ fn it_fails_not_relay_transferable_asset() {

assert_noop!(
ParachainApp::burn(
origin.clone().into(),
origin.into(),
network_id,
asset_id,
VersionedMultiLocation::V3(MultiLocation::new(
Expand All @@ -409,7 +409,7 @@ fn it_fails_burn_invalid_destination_parachain() {

assert_noop!(
ParachainApp::burn(
origin.clone().into(),
origin.into(),
network_id,
asset_id,
VersionedMultiLocation::V3(MultiLocation::new(
Expand Down Expand Up @@ -448,13 +448,7 @@ fn it_fails_burn_token_not_registered() {
let amount = 1_000_000;

assert_noop!(
ParachainApp::burn(
origin.clone().into(),
network_id,
AssetId::ETH,
recipient,
amount
),
ParachainApp::burn(origin.into(), network_id, AssetId::ETH, recipient, amount),
Error::<Test>::TokenIsNotRegistered
);
});
Expand Down Expand Up @@ -483,13 +477,7 @@ fn it_fails_burn_unknown_presicion() {
crate::AssetKinds::<Test>::insert(SubNetworkId::Kusama, asset_id, AssetKind::Thischain);

assert_noop!(
ParachainApp::burn(
origin.clone().into(),
network_id,
asset_id,
recipient,
amount
),
ParachainApp::burn(origin.into(), network_id, asset_id, recipient, amount),
Error::<Test>::UnknownPrecision
);
});
Expand Down Expand Up @@ -563,13 +551,7 @@ fn it_fails_burn_outbound_channel_submit() {
amount
));
assert_noop!(
ParachainApp::burn(
origin.clone().into(),
network_id,
AssetId::XOR,
recipient,
amount
),
ParachainApp::burn(origin.into(), network_id, AssetId::XOR, recipient, amount),
substrate_bridge_channel::outbound::Error::<Test>::QueueSizeLimitReached
);
});
Expand Down
6 changes: 3 additions & 3 deletions pallets/types/src/difficulty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ mod tests {
if s.starts_with("0x") {
u128::from_str_radix(s.trim_start_matches("0x"), 16)
} else {
u128::from_str_radix(&s, 10)
str::parse(&s)
}
};
match maybe_uint {
Expand Down Expand Up @@ -316,7 +316,7 @@ mod tests {
let path: PathBuf = [env!("CARGO_MANIFEST_DIR"), "tests", "fixtures", fixture]
.iter()
.collect();
serde_json::from_reader(File::open(&path).unwrap()).unwrap()
serde_json::from_reader(File::open(path).unwrap()).unwrap()
}
}

Expand Down Expand Up @@ -391,7 +391,7 @@ mod tests {
let path: PathBuf = [env!("CARGO_MANIFEST_DIR"), "tests", "fixtures", fixture]
.iter()
.collect();
serde_json::from_reader(File::open(&path).unwrap()).unwrap()
serde_json::from_reader(File::open(path).unwrap()).unwrap()
}
}

Expand Down

0 comments on commit 8d5091e

Please sign in to comment.