Skip to content

Commit

Permalink
fix more test
Browse files Browse the repository at this point in the history
  • Loading branch information
v9n committed Jun 21, 2023
1 parent 88770e3 commit 25826ed
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
17 changes: 15 additions & 2 deletions pallets/automation-time/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -920,11 +920,14 @@ fn trigger_tasks_handles_missed_slots() {
#[test]
fn trigger_tasks_limits_missed_slots() {
new_test_ext(START_BLOCK_TIME).execute_with(|| {
let call: <Test as frame_system::Config>::RuntimeCall = frame_system::Call::remark_with_event { remark: vec![50], }.into();

let missing_task_id0 = add_task_to_task_queue(
ALICE,
vec![40],
vec![SCHEDULED_TIME],
Action::Notify { message: vec![40] },
//Action::Notify { message: vec![40] },
Action::DynamicDispatch { encoded_call: call.encode() },
);
assert_eq!(AutomationTime::get_missed_queue().len(), 0);
Timestamp::set_timestamp((SCHEDULED_TIME - 25200) * 1_000);
Expand All @@ -943,6 +946,11 @@ fn trigger_tasks_limits_missed_slots() {
LastTimeSlot::<Test>::put((SCHEDULED_TIME - 25200, SCHEDULED_TIME - 25200));
System::reset_events();


// this is same call we mock in create_event_tasks
//AutomationTime::trigger_tasks(Weight::from_ref_time(200_000 + call.get_dispatch_info().weight.ref_time() as u128));
// the 200_000_000 number make it big enough so we attempt to run those tasks to generate
// missing event for test
AutomationTime::trigger_tasks(Weight::from_ref_time(200_000));

if let Some((updated_last_time_slot, updated_last_missed_slot)) =
Expand All @@ -953,7 +961,12 @@ fn trigger_tasks_limits_missed_slots() {
assert_eq!(
events(),
[
RuntimeEvent::AutomationTime(crate::Event::Notify { message: vec![50] }),
//RuntimeEvent::AutomationTime(crate::Event::Notify { message: vec![50] }),
RuntimeEvent::System(frame_system::pallet::Event::Remarked {
sender: AccountId32::new(ALICE),
hash: BlakeTwo256::hash(&vec![50]),
}),

RuntimeEvent::AutomationTime(crate::Event::TaskMissed {
who: AccountId32::new(ALICE),
task_id: missing_task_id0,
Expand Down
12 changes: 8 additions & 4 deletions pallets/automation-time/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ impl<AccountId: Ord, Balance: Ord, CurrencyId: Ord> PartialEq

impl<AccountId: Ord, Balance: Ord, CurrencyId: Ord> Eq for Task<AccountId, Balance, CurrencyId> {}

use sp_runtime::print;

impl<AccountId: Clone, Balance, CurrencyId> Task<AccountId, Balance, CurrencyId> {
pub fn new(
owner_id: AccountId,
Expand All @@ -241,7 +243,6 @@ impl<AccountId: Clone, Balance, CurrencyId> Task<AccountId, Balance, CurrencyId>
) -> Result<Self, DispatchError> {
let call: <T as frame_system::Config>::RuntimeCall = frame_system::Call::remark_with_event { remark: message }.into();
let action = Action::DynamicDispatch { encoded_call: call.encode() };

let schedule = Schedule::new_fixed_schedule::<T>(execution_times)?;
Ok(Self::new(owner_id, provided_id, schedule, action))
}
Expand Down Expand Up @@ -354,8 +355,6 @@ impl<AccountId, TaskId> ScheduledTasks<AccountId, TaskId> {
AccountId: Clone,
{
let action_weight = task.action.execution_weight::<T>()?;


let weight =
self.weight.checked_add(action_weight as u128).ok_or(Error::<T>::TimeSlotFull)?;
// A hard limit on tasks/slot prevents unforseen performance consequences
Expand Down Expand Up @@ -449,8 +448,13 @@ mod tests {
scheduled_tasks
.try_push::<Test, BalanceOf<Test>>(task_id, &task)
.expect("slot is not full");

assert_eq!(scheduled_tasks.tasks, vec![(task.owner_id, task_id)]);
assert_eq!(scheduled_tasks.weight, 20_000);

// this is same call we mock in create_event_tasks
let call: <Test as frame_system::Config>::RuntimeCall = frame_system::Call::remark_with_event { remark: vec![0] }.into();
// weight will be equal = weight of the dynamic dispatch + the call itself
assert_eq!(scheduled_tasks.weight, 20_000 + call.get_dispatch_info().weight.ref_time() as u128);
})
}
}
Expand Down

0 comments on commit 25826ed

Please sign in to comment.