Skip to content

Fix clippy #594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions auction/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn remove_auction_should_work() {
ExtBuilder::default().build().execute_with(|| {
assert_ok!(AuctionModule::new_auction(10, Some(100)), 0);
assert_eq!(AuctionModule::auctions_index(), 1);
assert_eq!(AuctionModule::auctions(0).is_some(), true);
assert!(AuctionModule::auctions(0).is_some());
assert_eq!(AuctionModule::auction_end_time(100, 0), Some(()));
AuctionModule::remove_auction(0);
assert_eq!(AuctionModule::auctions(0), None);
Expand All @@ -120,23 +120,23 @@ fn cleanup_auction_should_work() {
assert_eq!(AuctionModule::auctions_index(), 1);
assert_ok!(AuctionModule::new_auction(10, Some(50)), 1);
assert_eq!(AuctionModule::auctions_index(), 2);
assert_eq!(AuctionModule::auctions(0).is_some(), true);
assert_eq!(AuctionModule::auctions(1).is_some(), true);
assert!(AuctionModule::auctions(0).is_some());
assert!(AuctionModule::auctions(1).is_some());

assert_eq!(<AuctionEndTime<Runtime>>::iter_prefix(0).count(), 0);
assert_eq!(<AuctionEndTime<Runtime>>::iter_prefix(50).count(), 1);
assert_eq!(<AuctionEndTime<Runtime>>::iter_prefix(100).count(), 1);

AuctionModule::on_finalize(50);
assert_eq!(AuctionModule::auctions(0).is_some(), true);
assert_eq!(AuctionModule::auctions(1).is_some(), false);
assert!(AuctionModule::auctions(0).is_some());
assert!(!AuctionModule::auctions(1).is_some());
assert_eq!(<AuctionEndTime<Runtime>>::iter_prefix(0).count(), 0);
assert_eq!(<AuctionEndTime<Runtime>>::iter_prefix(50).count(), 0);
assert_eq!(<AuctionEndTime<Runtime>>::iter_prefix(100).count(), 1);

AuctionModule::on_finalize(100);
assert_eq!(AuctionModule::auctions(0).is_some(), false);
assert_eq!(AuctionModule::auctions(1).is_some(), false);
assert!(!AuctionModule::auctions(0).is_some());
assert!(!AuctionModule::auctions(1).is_some());
assert_eq!(<AuctionEndTime<Runtime>>::iter_prefix(0).count(), 0);
assert_eq!(<AuctionEndTime<Runtime>>::iter_prefix(50).count(), 0);
assert_eq!(<AuctionEndTime<Runtime>>::iter_prefix(100).count(), 0);
Expand Down
6 changes: 5 additions & 1 deletion authority/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ impl AsOriginId<Origin, OriginCaller> for MockAsOriginId {
MockAsOriginId::Account1 => ensure_signed(origin)? == 1,
MockAsOriginId::Account2 => ensure_signed(origin)? == 2,
};
return if ok { Ok(()) } else { Err(BadOrigin.into()) };
if ok {
Ok(())
} else {
Err(BadOrigin.into())
}
})
}
}
Expand Down
30 changes: 15 additions & 15 deletions authority/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn dispatch_as_work() {
assert_ok!(Authority::dispatch_as(
Origin::root(),
MockAsOriginId::Root,
Box::new(ensure_root_call.clone())
Box::new(ensure_root_call)
));
assert_ok!(Authority::dispatch_as(
Origin::root(),
Expand All @@ -46,7 +46,7 @@ fn dispatch_as_work() {
Authority::dispatch_as(
Origin::signed(1),
MockAsOriginId::Account2,
Box::new(ensure_signed_call.clone())
Box::new(ensure_signed_call)
),
BadOrigin,
);
Expand All @@ -59,7 +59,7 @@ fn schedule_dispatch_at_work() {
let ensure_root_call = Call::System(frame_system::Call::fill_block(Perbill::one()));
let call = Call::Authority(authority::Call::dispatch_as(
MockAsOriginId::Root,
Box::new(ensure_root_call.clone()),
Box::new(ensure_root_call),
));
run_to_block(1);
assert_eq!(
Expand Down Expand Up @@ -95,7 +95,7 @@ fn schedule_dispatch_at_work() {
DispatchTime::At(3),
0,
false,
Box::new(call.clone())
Box::new(call)
));
System::assert_last_event(mock::Event::Authority(Event::Scheduled(
OriginCaller::system(RawOrigin::Root),
Expand All @@ -117,7 +117,7 @@ fn schedule_dispatch_after_work() {
let ensure_root_call = Call::System(frame_system::Call::fill_block(Perbill::one()));
let call = Call::Authority(authority::Call::dispatch_as(
MockAsOriginId::Root,
Box::new(ensure_root_call.clone()),
Box::new(ensure_root_call),
));
run_to_block(1);
assert_eq!(
Expand Down Expand Up @@ -153,7 +153,7 @@ fn schedule_dispatch_after_work() {
DispatchTime::After(0),
0,
false,
Box::new(call.clone())
Box::new(call)
));
System::assert_last_event(mock::Event::Authority(Event::Scheduled(
OriginCaller::system(RawOrigin::Root),
Expand All @@ -176,7 +176,7 @@ fn fast_track_scheduled_dispatch_work() {
let ensure_root_call = Call::System(frame_system::Call::fill_block(Perbill::one()));
let call = Call::Authority(authority::Call::dispatch_as(
MockAsOriginId::Root,
Box::new(ensure_root_call.clone()),
Box::new(ensure_root_call),
));
run_to_block(1);
assert_ok!(Authority::schedule_dispatch(
Expand All @@ -195,7 +195,7 @@ fn fast_track_scheduled_dispatch_work() {
)));

let schedule_origin = {
let origin: <Runtime as Config>::Origin = From::from(Origin::root());
let origin: <Runtime as Config>::Origin = Origin::root();
let origin: <Runtime as Config>::Origin =
From::from(DelayedOrigin::<BlockNumber, <Runtime as Config>::PalletsOrigin> {
delay: 1,
Expand Down Expand Up @@ -225,7 +225,7 @@ fn fast_track_scheduled_dispatch_work() {
DispatchTime::At(2),
0,
false,
Box::new(call.clone())
Box::new(call)
));
System::assert_last_event(mock::Event::Authority(Event::Scheduled(
OriginCaller::system(RawOrigin::Root),
Expand Down Expand Up @@ -253,7 +253,7 @@ fn delay_scheduled_dispatch_work() {
let ensure_root_call = Call::System(frame_system::Call::fill_block(Perbill::one()));
let call = Call::Authority(authority::Call::dispatch_as(
MockAsOriginId::Root,
Box::new(ensure_root_call.clone()),
Box::new(ensure_root_call),
));
run_to_block(1);
assert_ok!(Authority::schedule_dispatch(
Expand All @@ -272,7 +272,7 @@ fn delay_scheduled_dispatch_work() {
)));

let schedule_origin = {
let origin: <Runtime as Config>::Origin = From::from(Origin::root());
let origin: <Runtime as Config>::Origin = Origin::root();
let origin: <Runtime as Config>::Origin =
From::from(DelayedOrigin::<BlockNumber, <Runtime as Config>::PalletsOrigin> {
delay: 1,
Expand Down Expand Up @@ -302,7 +302,7 @@ fn delay_scheduled_dispatch_work() {
DispatchTime::At(2),
0,
false,
Box::new(call.clone())
Box::new(call)
));
System::assert_last_event(mock::Event::Authority(Event::Scheduled(
OriginCaller::system(RawOrigin::Root),
Expand All @@ -329,7 +329,7 @@ fn cancel_scheduled_dispatch_work() {
let ensure_root_call = Call::System(frame_system::Call::fill_block(Perbill::one()));
let call = Call::Authority(authority::Call::dispatch_as(
MockAsOriginId::Root,
Box::new(ensure_root_call.clone()),
Box::new(ensure_root_call),
));
run_to_block(1);
assert_ok!(Authority::schedule_dispatch(
Expand All @@ -348,7 +348,7 @@ fn cancel_scheduled_dispatch_work() {
)));

let schedule_origin = {
let origin: <Runtime as Config>::Origin = From::from(Origin::root());
let origin: <Runtime as Config>::Origin = Origin::root();
let origin: <Runtime as Config>::Origin =
From::from(DelayedOrigin::<BlockNumber, <Runtime as Config>::PalletsOrigin> {
delay: 1,
Expand All @@ -372,7 +372,7 @@ fn cancel_scheduled_dispatch_work() {
DispatchTime::At(2),
0,
false,
Box::new(call.clone())
Box::new(call)
));
System::assert_last_event(mock::Event::Authority(Event::Scheduled(
OriginCaller::system(RawOrigin::Root),
Expand Down
2 changes: 1 addition & 1 deletion bencher/src/build_wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn build() -> std::io::Result<Vec<u8>> {

let (wasm_binary, bloaty) = wasm_project::create_and_compile(
&project_cargo_toml,
&default_rustflags,
default_rustflags,
cargo_cmd,
vec!["bench".to_string()],
None,
Expand Down
4 changes: 2 additions & 2 deletions bencher/src/build_wasm/wasm_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ fn create_project(

fs::create_dir_all(wasm_project_folder.join("src")).expect("Wasm project dir create can not fail; qed");

let mut enabled_features = project_enabled_features(&project_cargo_toml, &crate_metadata);
let mut enabled_features = project_enabled_features(project_cargo_toml, crate_metadata);

if has_runtime_wasm_feature_declared(project_cargo_toml, crate_metadata) {
enabled_features.push("runtime-wasm".into());
Expand All @@ -398,7 +398,7 @@ fn create_project(
&wasm_project_folder,
workspace_root_path,
&crate_name,
&crate_path,
crate_path,
&wasm_binary,
enabled_features.into_iter(),
);
Expand Down
2 changes: 1 addition & 1 deletion bencher/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub fn handle(output: Vec<u8>) {
let stdout = ::std::io::stdout();
let mut handle = stdout.lock();

handle.write_all(&json.as_bytes()).unwrap();
handle.write_all(json.as_bytes()).unwrap();
} else {
eprintln!("Could not write benchdata to JSON");
}
Expand Down
8 changes: 4 additions & 4 deletions benchmarking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ runtime_benchmarks! {
set_value {
let b in 1 .. 1000;
let caller = account::<AccountId>("caller", 0, 0);
}: _ (RawOrigin::Signed(caller), b.into())
}: _ (RawOrigin::Signed(caller), b)
verify {
assert_eq!(Pallet::value(), Some(b));
}

other_name {
let b in 1 .. 1000;
}: dummy (RawOrigin::None, b.into())
}: dummy (RawOrigin::None, b)

sort_vector {
let x in 1 .. 10000;
Expand All @@ -134,15 +134,15 @@ runtime_benchmarks! {
m.push(i);
}
}: {
m.sort();
m.sort_unstable();
} verify {
ensure!(m[0] == 0, "You forgot to sort!")
}

bad_origin {
let b in 1 .. 1000;
let caller = account::<AccountId>("caller", 0, 0);
}: dummy (RawOrigin::Signed(caller), b.into())
}: dummy (RawOrigin::Signed(caller), b)

bad_verify {
let x in 1 .. 10000;
Expand Down
14 changes: 7 additions & 7 deletions gradually-update/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn gradually_update_should_fail() {
per_block: 1u64.encode().try_into().unwrap(),
};
assert_noop!(
GraduallyUpdateModule::gradually_update(Origin::root(), update.clone()),
GraduallyUpdateModule::gradually_update(Origin::root(), update),
Error::<Runtime>::InvalidPerBlockOrTargetValue
);

Expand All @@ -67,12 +67,12 @@ fn gradually_update_should_fail() {
per_block: 1u64.encode().try_into().unwrap(),
};
assert_noop!(
GraduallyUpdateModule::gradually_update(Origin::root(), new_update.clone()),
GraduallyUpdateModule::gradually_update(Origin::root(), new_update),
Error::<Runtime>::InvalidTargetValue
);

assert_noop!(
GraduallyUpdateModule::gradually_update(Origin::root(), update.clone()),
GraduallyUpdateModule::gradually_update(Origin::root(), update),
Error::<Runtime>::GraduallyUpdateHasExisted
);
});
Expand Down Expand Up @@ -100,7 +100,7 @@ fn cancel_gradually_update_should_work() {
update.key.clone()
));
System::assert_last_event(Event::GraduallyUpdateModule(crate::Event::GraduallyUpdateCancelled(
update.key.clone(),
update.key,
)));
});
}
Expand All @@ -122,7 +122,7 @@ fn cancel_gradually_update_should_fail() {

assert_ok!(GraduallyUpdateModule::cancel_gradually_update(
Origin::root(),
update.key.clone()
update.key
));
});
}
Expand Down Expand Up @@ -167,7 +167,7 @@ fn add_on_finalize_should_work() {
assert_eq!(storage_get(&update.key), vec![30]);
System::assert_last_event(Event::GraduallyUpdateModule(crate::Event::Updated(
40,
update.key.clone(),
update.key,
vec![30].try_into().unwrap(),
)));
});
Expand Down Expand Up @@ -214,7 +214,7 @@ fn sub_on_finalize_should_work() {
assert_eq!(storage_get(&update.key), vec![5]);
System::assert_last_event(Event::GraduallyUpdateModule(crate::Event::Updated(
40,
update.key.clone(),
update.key,
vec![5].try_into().unwrap(),
)));
});
Expand Down
2 changes: 1 addition & 1 deletion nft/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub mod module {
let class_id = Pallet::<T>::create_class(&token_class.0, token_class.1.to_vec(), token_class.2.clone())
.expect("Create class cannot fail while building genesis");
for (account_id, token_metadata, token_data) in &token_class.3 {
Pallet::<T>::mint(&account_id, class_id, token_metadata.to_vec(), token_data.clone())
Pallet::<T>::mint(account_id, class_id, token_metadata.to_vec(), token_data.clone())
.expect("Token mint cannot fail during genesis");
}
})
Expand Down
6 changes: 3 additions & 3 deletions nft/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ fn destroy_class_should_work() {
assert_ok!(NonFungibleTokenModule::mint(&BOB, CLASS_ID, vec![1], ()));
assert_ok!(NonFungibleTokenModule::burn(&BOB, (CLASS_ID, TOKEN_ID)));
assert_ok!(NonFungibleTokenModule::destroy_class(&ALICE, CLASS_ID));
assert_eq!(Classes::<Runtime>::contains_key(CLASS_ID), false);
assert_eq!(NextTokenId::<Runtime>::contains_key(CLASS_ID), false);
assert!(!Classes::<Runtime>::contains_key(CLASS_ID));
assert!(!NextTokenId::<Runtime>::contains_key(CLASS_ID));
});
}

Expand All @@ -175,7 +175,7 @@ fn destroy_class_should_fail() {

assert_ok!(NonFungibleTokenModule::burn(&BOB, (CLASS_ID, TOKEN_ID)));
assert_ok!(NonFungibleTokenModule::destroy_class(&ALICE, CLASS_ID));
assert_eq!(Classes::<Runtime>::contains_key(CLASS_ID), false);
assert!(!Classes::<Runtime>::contains_key(CLASS_ID));
});
}

Expand Down
2 changes: 1 addition & 1 deletion oracle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
RawValues::<T, I>::insert(&who, &key, timestamped);
IsUpdated::<T, I>::remove(&key);

T::OnNewData::on_new_data(&who, &key, &value);
T::OnNewData::on_new_data(&who, key, value);
}
Self::deposit_event(Event::NewFeedData(who, values));
Ok(())
Expand Down
12 changes: 6 additions & 6 deletions oracle/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,22 @@ fn should_feed_values_from_root() {
fn should_update_is_updated() {
new_test_ext().execute_with(|| {
let key: u32 = 50;
assert_eq!(ModuleOracle::is_updated(key), false);
assert!(!ModuleOracle::is_updated(key));
assert_ok!(ModuleOracle::feed_values(Origin::signed(1), vec![(key, 1000)]));
assert_ok!(ModuleOracle::feed_values(Origin::signed(2), vec![(key, 1000)]));
assert_ok!(ModuleOracle::feed_values(Origin::signed(3), vec![(key, 1000)]));
assert_eq!(ModuleOracle::is_updated(key), false);
assert!(!ModuleOracle::is_updated(key));
assert_eq!(
ModuleOracle::get(&key).unwrap(),
TimestampedValue {
value: 1000,
timestamp: 12345
}
);
assert_eq!(ModuleOracle::is_updated(key), true);
assert!(ModuleOracle::is_updated(key));
ModuleOracle::on_finalize(1);
assert_ok!(ModuleOracle::feed_values(Origin::signed(1), vec![(key, 1000)]));
assert_eq!(ModuleOracle::is_updated(key), false);
assert!(!ModuleOracle::is_updated(key));
});
}

Expand Down Expand Up @@ -262,11 +262,11 @@ fn should_clear_is_updated_on_change_member() {
timestamp: 12345
}
);
assert_eq!(ModuleOracle::is_updated(50), true);
assert!(ModuleOracle::is_updated(50));

ModuleOracle::change_members_sorted(&[4], &[1], &[2, 3, 4]);

assert_eq!(ModuleOracle::is_updated(50), false);
assert!(!ModuleOracle::is_updated(50));
});
}

Expand Down
Loading