Skip to content

Commit

Permalink
cargo clippy refactoring, no functional changes (#523)
Browse files Browse the repository at this point in the history
* cargo clippy refactoring, no functional changes

* cargo fmt changes
  • Loading branch information
12shivs authored Jul 2, 2024
1 parent 1a6fedd commit c838ec6
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 78 deletions.
8 changes: 4 additions & 4 deletions pallets/automation-price/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ pub mod pallet {
ensure_root(origin)?;

let key = (&chain, &exchange, (&asset1, &asset2));
if let Some(asset_info) = Self::get_asset_registry_info(key) {
if let Some(_asset_info) = Self::get_asset_registry_info(key) {
AssetRegistry::<T>::remove(&key);
PriceRegistry::<T>::remove(&key);
Self::deposit_event(Event::AssetDeleted { chain, exchange, asset1, asset2 });
Expand Down Expand Up @@ -1163,7 +1163,7 @@ pub mod pallet {
return (task_ids, weight_left)
}

let now = current_block_time.unwrap();
let _now = current_block_time.unwrap();

for (owner_id, task_id) in task_ids.iter() {
consumed_task_index.saturating_inc();
Expand All @@ -1188,9 +1188,9 @@ pub mod pallet {
condition: task_condition.unwrap(),
});

let total_task =
let _total_task =
Self::get_task_stat(StatType::TotalTasksOverall).map_or(0, |v| v);
let total_task_per_account = Self::get_account_stat(
let _total_task_per_account = Self::get_account_stat(
&task.owner_id,
StatType::TotalTasksPerAccount,
)
Expand Down
2 changes: 1 addition & 1 deletion pallets/automation-price/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ impl<Test: frame_system::Config> pallet_automation_price::WeightInfo for MockWei
Weight::from_parts(220_000_000_u64 * v as u64, 0u64)
}

fn initialize_asset_extrinsic(v: u32) -> Weight {
fn initialize_asset_extrinsic(_v: u32) -> Weight {
Weight::from_parts(220_000_000_u64, 0u64)
}

Expand Down
2 changes: 1 addition & 1 deletion pallets/automation-price/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ fn test_sweep_expired_task_works() {
fn test_sweep_expired_task_partially() {
new_test_ext(START_BLOCK_TIME).execute_with(|| {
let creator = AccountId32::new(ALICE);
let other_creator = AccountId32::new(BOB);
let _other_creator = AccountId32::new(BOB);
let para_id: u32 = 1000;

setup_assets_and_prices(&creator, START_BLOCK_TIME as u128);
Expand Down
8 changes: 4 additions & 4 deletions pallets/automation-time/src/autocompounding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ mod tests {
fn test_1() {
let principal = 50 * DOLLAR;
let collator_stake = 500_000 * DOLLAR;
let fee = 1 * DOLLAR;
let fee = DOLLAR;

let result = do_calculate_optimal_autostaking(
principal,
Expand All @@ -105,7 +105,7 @@ mod tests {
fn test_2() {
let principal = 250_000 * DOLLAR;
let collator_stake = 500_000 * DOLLAR;
let fee = 1 * DOLLAR;
let fee = DOLLAR;
let result = do_calculate_optimal_autostaking(
principal,
collator_stake,
Expand Down Expand Up @@ -190,7 +190,7 @@ mod tests {
fn test_8() {
let principal = 50 * DOLLAR;
let collator_stake = 250_000 * DOLLAR;
let fee = 1 * DOLLAR;
let fee = DOLLAR;
let daily_collator_awards = 500_000 / 365 * DOLLAR;
let result = do_calculate_optimal_autostaking(
principal,
Expand All @@ -209,7 +209,7 @@ mod tests {

let principal = 5_000 * DOLLAR;
let collator_stake = 20_000_000_000_000_000;
let fee = 1 * DOLLAR;
let fee = DOLLAR;
let daily_collator_awards = (money_supply as f64 * 0.025) as i128 / 24 / 365;
let result = do_calculate_optimal_autostaking(
principal,
Expand Down
12 changes: 6 additions & 6 deletions pallets/automation-time/src/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ mod tests {
},
);
assert_eq!(result.expect("success"), "called");
assert_eq!(has_callback_run, true);
assert!(has_callback_run);
assert!(starting_funds > Balances::free_balance(alice))
})
}
Expand Down Expand Up @@ -301,7 +301,7 @@ mod tests {
},
);
assert_eq!(result.expect("success"), "called");
assert_eq!(has_callback_run, true);
assert!(has_callback_run);
})
}

Expand All @@ -321,7 +321,7 @@ mod tests {

let action = Action::XCMP {
destination,
schedule_fee: destination.into(),
schedule_fee: destination,
execution_fee: AssetPayment { asset_location: NATIVE_LOCATION.into(), amount: 10 },
encoded_call: vec![3, 4, 5],
encoded_call_weight: Weight::from_parts(100_000, 0),
Expand All @@ -340,7 +340,7 @@ mod tests {
},
);
assert_eq!(result.expect("success"), "called");
assert_eq!(has_callback_run, true);
assert!(has_callback_run);
})
}

Expand All @@ -354,7 +354,7 @@ mod tests {

let action = Action::XCMP {
destination,
schedule_fee: destination.clone().into(),
schedule_fee: destination,
execution_fee: AssetPayment { asset_location: NATIVE_LOCATION.into(), amount: 10 },
encoded_call: vec![3, 4, 5],
encoded_call_weight: Weight::from_parts(100_000, 0),
Expand Down Expand Up @@ -430,7 +430,7 @@ mod tests {
},
);
assert_eq!(result.expect("success"), "called");
assert_eq!(has_callback_run, true);
assert!(has_callback_run);
})
}

Expand Down
13 changes: 6 additions & 7 deletions pallets/automation-time/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,10 @@ pub mod pallet {
schedule_fee: schedule_fee_location,
execution_fee: execution_fee_payment,
encoded_call: encoded_call.clone(),
encoded_call_weight: encoded_call_weight.clone(),
overall_weight: overall_weight.clone(),
encoded_call_weight,
overall_weight,
schedule_as: schedule_as.clone(),
instruction_sequence: instruction_sequence.clone(),
instruction_sequence,
};

// Convert the call into a runtime call
Expand Down Expand Up @@ -606,8 +606,7 @@ pub mod pallet {
let task = AccountTasks::<T>::get(owner_id, task_id.clone())
.ok_or(Error::<T>::TaskDoesNotExist)?;

if !matches!(task.clone().action, Action::XCMP { schedule_as: Some(ref s), .. } if s == &who)
{
if !matches!(task.action, Action::XCMP { schedule_as: Some(ref s), .. } if s == &who) {
return Err(Error::<T>::TaskScheduleAsNotMatch.into())
}

Expand Down Expand Up @@ -1347,7 +1346,7 @@ pub mod pallet {
let asset_location = MultiLocation::try_from(execution_fee.asset_location)
.map_err(|()| Error::<T>::BadVersion)?;
let _asset_location = asset_location
.reanchored(&T::SelfLocation::get().into(), T::UniversalLocation::get())
.reanchored(&T::SelfLocation::get(), T::UniversalLocation::get())
.map_err(|_| Error::<T>::CannotReanchor)?;
},
_ => (),
Expand Down Expand Up @@ -1532,7 +1531,7 @@ pub mod pallet {

let schedule_fee_location = action.schedule_fee_location::<T>();
let schedule_fee_location = schedule_fee_location
.reanchored(&T::SelfLocation::get().into(), T::UniversalLocation::get())
.reanchored(&T::SelfLocation::get(), T::UniversalLocation::get())
.map_err(|_| Error::<T>::CannotReanchor)?;

let fee = if schedule_fee_location == MultiLocation::default() {
Expand Down
78 changes: 34 additions & 44 deletions pallets/automation-time/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ fn schedule_transfer_with_dynamic_dispatch() {
assert_ok!(AutomationTime::schedule_dynamic_dispatch_task(
RuntimeOrigin::signed(account_id.clone()),
ScheduleParam::Fixed { execution_times: vec![SCHEDULED_TIME] },
Box::new(call.clone()),
Box::new(call),
));

Timestamp::set_timestamp(SCHEDULED_TIME * 1_000);
Expand Down Expand Up @@ -539,12 +539,11 @@ fn will_remove_task_from_account_tasks_when_task_canceled_with_schedule_as() {

// Check if the task's schedule_as is correct
let task = AccountTasks::<Test>::get(task_owner.clone(), task_id.clone());
assert_eq!(task.is_some(), true);
assert!(task.is_some());

let task = task.unwrap();
assert_eq!(
matches!(task.clone().action, Action::XCMP { schedule_as: Some(ref s), .. } if s == &schedule_as),
true
assert!(
matches!(task.action, Action::XCMP { schedule_as: Some(ref s), .. } if s == &schedule_as)
);

// Cancel task with schedule_as
Expand Down Expand Up @@ -592,29 +591,27 @@ fn cancel_task_with_incorrect_schedule_as_will_fail() {

// Check if the task's schedule_as is correct
let task = AccountTasks::<Test>::get(task_owner.clone(), task_id.clone());
assert_eq!(task.is_some(), true);
assert!(task.is_some());

let task = task.unwrap();
assert_eq!(
matches!(task.clone().action, Action::XCMP { schedule_as: Some(ref s), .. } if s == &schedule_as),
true
assert!(
matches!(task.action, Action::XCMP { schedule_as: Some(ref s), .. } if s == &schedule_as)
);

// Cancel task with incorrect schedule_as
// It will throw TaskScheduleAsNotMatch error
assert_noop!(
AutomationTime::cancel_task_with_schedule_as(
RuntimeOrigin::signed(AccountId32::new(ALICE)),
task_owner.clone(),
task_id.clone(),
task_owner,
task_id,
),
Error::<Test>::TaskScheduleAsNotMatch
);

// Assert that the task is still present in accountTasks.
assert_eq!(
matches!(task.clone().action, Action::XCMP { schedule_as: Some(ref s), .. } if s == &schedule_as),
true
assert!(
matches!(task.action, Action::XCMP { schedule_as: Some(ref s), .. } if s == &schedule_as)
);
})
}
Expand All @@ -634,8 +631,8 @@ fn cancel_with_schedule_as_and_non_existent_taskid_will_fail() {
assert_noop!(
AutomationTime::cancel_task_with_schedule_as(
RuntimeOrigin::signed(schedule_as),
task_owner.clone(),
task_id.clone(),
task_owner,
task_id,
),
Error::<Test>::TaskDoesNotExist
);
Expand Down Expand Up @@ -674,13 +671,12 @@ fn cancel_with_schedule_as_and_incorrect_owner_will_fail() {
));

// Check if the task's schedule_as is correct
let task = AccountTasks::<Test>::get(task_owner.clone(), task_id.clone());
assert_eq!(task.is_some(), true);
let task = AccountTasks::<Test>::get(task_owner, task_id.clone());
assert!(task.is_some());

let task = task.unwrap();
assert_eq!(
matches!(task.clone().action, Action::XCMP { schedule_as: Some(ref s), .. } if s == &schedule_as),
true
assert!(
matches!(task.action, Action::XCMP { schedule_as: Some(ref s), .. } if s == &schedule_as)
);

// Cancel task with incorrect owner
Expand All @@ -689,15 +685,14 @@ fn cancel_with_schedule_as_and_incorrect_owner_will_fail() {
AutomationTime::cancel_task_with_schedule_as(
RuntimeOrigin::signed(schedule_as.clone()),
AccountId32::new(ALICE),
task_id.clone(),
task_id,
),
Error::<Test>::TaskDoesNotExist
);

// Assert that the task is still present in accountTasks.
assert_eq!(
matches!(task.clone().action, Action::XCMP { schedule_as: Some(ref s), .. } if s == &schedule_as),
true
assert!(
matches!(task.action, Action::XCMP { schedule_as: Some(ref s), .. } if s == &schedule_as)
);
})
}
Expand All @@ -724,7 +719,7 @@ fn will_emit_task_completed_event_when_task_failed() {
assert_ok!(AutomationTime::schedule_dynamic_dispatch_task(
RuntimeOrigin::signed(account_id.clone()),
ScheduleParam::Fixed { execution_times: vec![SCHEDULED_TIME, next_execution_time] },
Box::new(call.clone()),
Box::new(call),
));

// First execution
Expand Down Expand Up @@ -1058,15 +1053,15 @@ fn schedule_xcmp_task_and_check_encoded_call_success() {

// Call the schedule_xcmp_task function
assert_ok!(AutomationTime::schedule_xcmp_task(
origin.clone(),
origin,
schedule.clone(),
destination.clone(),
schedule_fee.clone(),
execution_fee.clone(),
remote_encoded_call.clone(),
encoded_call_weight.clone(),
overall_weight.clone(),
instruction_sequence.clone(),
encoded_call_weight,
overall_weight,
instruction_sequence,
schedule_as.clone(),
));

Expand Down Expand Up @@ -1651,10 +1646,8 @@ fn taskid_adjusted_on_extrinsicid_on_same_block() {

// Calculate the expected encoded call
let expected_encoded_call =
Into::<RuntimeCall>::into(frame_system::Call::remark_with_event {
remark: message.clone(),
})
.encode();
Into::<RuntimeCall>::into(frame_system::Call::remark_with_event { remark: message })
.encode();

// Find the TaskScheduled event in the event list and verify if the encoded_call within it is correct.
assert_has_event(RuntimeEvent::AutomationTime(crate::Event::TaskScheduled {
Expand Down Expand Up @@ -1710,10 +1703,8 @@ fn taskid_adjusted_on_eventindex_on_same_block_from_same_caller() {

// Calculate the expected encoded call
let expected_encoded_call =
Into::<RuntimeCall>::into(frame_system::Call::remark_with_event {
remark: message.clone(),
})
.encode();
Into::<RuntimeCall>::into(frame_system::Call::remark_with_event { remark: message })
.encode();

// Find the TaskScheduled event in the event list and verify if the encoded_call within it is correct.
assert_has_event(RuntimeEvent::AutomationTime(crate::Event::TaskScheduled {
Expand Down Expand Up @@ -1924,7 +1915,7 @@ fn cancel_works_for_an_executed_task() {
let task_id1 = schedule_dynamic_dispatch_task(
ALICE,
vec![SCHEDULED_TIME, SCHEDULED_TIME + SLOT_SIZE_SECONDS],
call.clone(),
call,
);
Timestamp::set_timestamp(SCHEDULED_TIME * 1_000);
LastTimeSlot::<Test>::put((
Expand Down Expand Up @@ -2193,7 +2184,7 @@ mod extrinsics {
assert_ok!(fund_account_dynamic_dispatch(
&account_id,
execution_times.len(),
call.clone().encode()
call.encode()
));

assert_ok!(AutomationTime::schedule_dynamic_dispatch_task(
Expand Down Expand Up @@ -2380,8 +2371,7 @@ fn trigger_tasks_handles_missed_slots() {
let remark_message = vec![50];
let call: <Test as frame_system::Config>::RuntimeCall =
frame_system::Call::remark_with_event { remark: remark_message.clone() }.into();
let task_will_be_run_id =
schedule_dynamic_dispatch_task(ALICE, vec![SCHEDULED_TIME], call.clone());
let task_will_be_run_id = schedule_dynamic_dispatch_task(ALICE, vec![SCHEDULED_TIME], call);
let scheduled_task_id = schedule_task(ALICE, vec![SCHEDULED_TIME], vec![50]);

Timestamp::set_timestamp(SCHEDULED_TIME * 1_000);
Expand Down Expand Up @@ -2475,7 +2465,7 @@ fn trigger_tasks_limits_missed_slots() {
let remark_message = vec![50];
let call: <Test as frame_system::Config>::RuntimeCall =
frame_system::Call::remark_with_event { remark: remark_message.clone() }.into();
let task_id = schedule_dynamic_dispatch_task(ALICE, vec![SCHEDULED_TIME], call.clone());
let task_id = schedule_dynamic_dispatch_task(ALICE, vec![SCHEDULED_TIME], call);

Timestamp::set_timestamp(SCHEDULED_TIME * 1_000);
LastTimeSlot::<Test>::put((
Expand Down Expand Up @@ -2961,7 +2951,7 @@ fn trigger_tasks_completes_some_xcmp_tasks() {
asset_location: MultiLocation::new(0, Here).into(),
amount: 10,
},
encoded_call: encoded_call.clone(),
encoded_call,
encoded_call_weight: Weight::from_parts(100_000, 0),
overall_weight: Weight::from_parts(200_000, 0),
schedule_as: None,
Expand Down
Loading

0 comments on commit c838ec6

Please sign in to comment.