BREAKING: Rename Call & Event (#11981)

* rename Event to RuntimeEvent

* rename Call

* rename in runtimes

* small fix

* rename Event

* small fix & rename RuntimeCall back to Call for now

* small fixes

* more renaming

* a bit more renaming

* fmt

* small fix

* commit

* prep for renaming associated types

* fix

* rename associated Event type

* rename to RuntimeEvent

* commit

* merge conflict fixes & fmt

* additional renaming

* fix.

* fix decl_event

* rename in tests

* remove warnings

* remove accidental rename

* .

* commit

* update .stderr

* fix in test

* update .stderr

* TRYBUILD=overwrite

* docs

* fmt

* small change in docs

* rename PalletEvent to Event

* rename Call to RuntimeCall

* renamed at wrong places :P

* rename Call

* rename

* rename associated type

* fix

* fix & fmt

* commit

* frame-support-test

* passing tests

* update docs

* rustdoc fix

* update .stderr

* wrong code in docs

* merge fix

* fix in error message

* update .stderr

* docs & error message

* .

* merge fix

* merge fix

* fmt

* fmt

* merge fix

* more fixing

* fmt

* remove unused

* fmt

* fix

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Sergej Sakac
2022-09-13 00:03:31 +02:00
committed by GitHub
parent 472b5746e5
commit 6e8795afe6
228 changed files with 1791 additions and 1672 deletions
+118 -65
View File
@@ -18,7 +18,9 @@
//! # Scheduler tests.
use super::*;
use crate::mock::{logger, new_test_ext, root, run_to_block, Call, LoggerCall, Scheduler, Test, *};
use crate::mock::{
logger, new_test_ext, root, run_to_block, LoggerCall, RuntimeCall, Scheduler, Test, *,
};
use frame_support::{
assert_err, assert_noop, assert_ok,
traits::{Contains, GetStorageVersion, OnInitialize, PreimageProvider},
@@ -30,7 +32,8 @@ use substrate_test_utils::assert_eq_uvec;
#[test]
fn basic_scheduling_works() {
new_test_ext().execute_with(|| {
let call = Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) });
let call =
RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) });
assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
assert_ok!(Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), call.into()));
run_to_block(3);
@@ -45,7 +48,8 @@ fn basic_scheduling_works() {
#[test]
fn scheduling_with_preimages_works() {
new_test_ext().execute_with(|| {
let call = Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) });
let call =
RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) });
let hash = <Test as frame_system::Config>::Hashing::hash_of(&call);
let hashed = MaybeHashed::Hash(hash);
assert_ok!(Preimage::note_preimage(Origin::signed(0), call.encode()));
@@ -65,7 +69,8 @@ fn scheduling_with_preimages_works() {
#[test]
fn scheduling_with_preimage_postpones_correctly() {
new_test_ext().execute_with(|| {
let call = Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) });
let call =
RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) });
let hash = <Test as frame_system::Config>::Hashing::hash_of(&call);
let hashed = MaybeHashed::Hash(hash);
@@ -98,7 +103,8 @@ fn scheduling_with_preimage_postpones_correctly() {
fn schedule_after_works() {
new_test_ext().execute_with(|| {
run_to_block(2);
let call = Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) });
let call =
RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) });
assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
// This will schedule the call 3 blocks after the next block... so block 3 + 3 = 6
assert_ok!(Scheduler::do_schedule(DispatchTime::After(3), None, 127, root(), call.into()));
@@ -115,7 +121,8 @@ fn schedule_after_works() {
fn schedule_after_zero_works() {
new_test_ext().execute_with(|| {
run_to_block(2);
let call = Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) });
let call =
RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) });
assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
assert_ok!(Scheduler::do_schedule(DispatchTime::After(0), None, 127, root(), call.into()));
// Will trigger on the next block.
@@ -135,7 +142,8 @@ fn periodic_scheduling_works() {
Some((3, 3)),
127,
root(),
Call::Logger(logger::Call::log { i: 42, weight: Weight::from_ref_time(1000) }).into()
RuntimeCall::Logger(logger::Call::log { i: 42, weight: Weight::from_ref_time(1000) })
.into()
));
run_to_block(3);
assert!(logger::log().is_empty());
@@ -157,7 +165,8 @@ fn periodic_scheduling_works() {
#[test]
fn reschedule_works() {
new_test_ext().execute_with(|| {
let call = Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) });
let call =
RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) });
assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
assert_eq!(
Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), call.into()).unwrap(),
@@ -188,7 +197,8 @@ fn reschedule_works() {
#[test]
fn reschedule_named_works() {
new_test_ext().execute_with(|| {
let call = Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) });
let call =
RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) });
assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
assert_eq!(
Scheduler::do_schedule_named(
@@ -230,7 +240,8 @@ fn reschedule_named_works() {
#[test]
fn reschedule_named_perodic_works() {
new_test_ext().execute_with(|| {
let call = Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) });
let call =
RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) });
assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
assert_eq!(
Scheduler::do_schedule_named(
@@ -292,7 +303,8 @@ fn cancel_named_scheduling_works_with_normal_cancel() {
None,
127,
root(),
Call::Logger(LoggerCall::log { i: 69, weight: Weight::from_ref_time(1000) }).into(),
RuntimeCall::Logger(LoggerCall::log { i: 69, weight: Weight::from_ref_time(1000) })
.into(),
)
.unwrap();
let i = Scheduler::do_schedule(
@@ -300,7 +312,8 @@ fn cancel_named_scheduling_works_with_normal_cancel() {
None,
127,
root(),
Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) }).into(),
RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) })
.into(),
)
.unwrap();
run_to_block(3);
@@ -322,7 +335,8 @@ fn cancel_named_periodic_scheduling_works() {
Some((3, 3)),
127,
root(),
Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) }).into(),
RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) })
.into(),
)
.unwrap();
// same id results in error.
@@ -332,7 +346,8 @@ fn cancel_named_periodic_scheduling_works() {
None,
127,
root(),
Call::Logger(LoggerCall::log { i: 69, weight: Weight::from_ref_time(1000) }).into(),
RuntimeCall::Logger(LoggerCall::log { i: 69, weight: Weight::from_ref_time(1000) })
.into(),
)
.is_err());
// different id is ok.
@@ -342,7 +357,8 @@ fn cancel_named_periodic_scheduling_works() {
None,
127,
root(),
Call::Logger(LoggerCall::log { i: 69, weight: Weight::from_ref_time(1000) }).into(),
RuntimeCall::Logger(LoggerCall::log { i: 69, weight: Weight::from_ref_time(1000) })
.into(),
)
.unwrap();
run_to_block(3);
@@ -364,16 +380,22 @@ fn scheduler_respects_weight_limits() {
None,
127,
root(),
Call::Logger(LoggerCall::log { i: 42, weight: MaximumSchedulerWeight::get() / 2 })
.into(),
RuntimeCall::Logger(LoggerCall::log {
i: 42,
weight: MaximumSchedulerWeight::get() / 2
})
.into(),
));
assert_ok!(Scheduler::do_schedule(
DispatchTime::At(4),
None,
127,
root(),
Call::Logger(LoggerCall::log { i: 69, weight: MaximumSchedulerWeight::get() / 2 })
.into(),
RuntimeCall::Logger(LoggerCall::log {
i: 69,
weight: MaximumSchedulerWeight::get() / 2
})
.into(),
));
// 69 and 42 do not fit together
run_to_block(4);
@@ -391,16 +413,22 @@ fn scheduler_respects_hard_deadlines_more() {
None,
0,
root(),
Call::Logger(LoggerCall::log { i: 42, weight: MaximumSchedulerWeight::get() / 2 })
.into(),
RuntimeCall::Logger(LoggerCall::log {
i: 42,
weight: MaximumSchedulerWeight::get() / 2
})
.into(),
));
assert_ok!(Scheduler::do_schedule(
DispatchTime::At(4),
None,
0,
root(),
Call::Logger(LoggerCall::log { i: 69, weight: MaximumSchedulerWeight::get() / 2 })
.into(),
RuntimeCall::Logger(LoggerCall::log {
i: 69,
weight: MaximumSchedulerWeight::get() / 2
})
.into(),
));
// With base weights, 69 and 42 should not fit together, but do because of hard
// deadlines
@@ -417,16 +445,22 @@ fn scheduler_respects_priority_ordering() {
None,
1,
root(),
Call::Logger(LoggerCall::log { i: 42, weight: MaximumSchedulerWeight::get() / 2 })
.into(),
RuntimeCall::Logger(LoggerCall::log {
i: 42,
weight: MaximumSchedulerWeight::get() / 2
})
.into(),
));
assert_ok!(Scheduler::do_schedule(
DispatchTime::At(4),
None,
0,
root(),
Call::Logger(LoggerCall::log { i: 69, weight: MaximumSchedulerWeight::get() / 2 })
.into(),
RuntimeCall::Logger(LoggerCall::log {
i: 69,
weight: MaximumSchedulerWeight::get() / 2
})
.into(),
));
run_to_block(4);
assert_eq!(logger::log(), vec![(root(), 69u32), (root(), 42u32)]);
@@ -444,21 +478,23 @@ fn scheduler_respects_priority_ordering_with_soft_deadlines() {
None,
255,
root(),
Call::Logger(LoggerCall::log { i: 42, weight: max_weight / 2 - item_weight }).into(),
RuntimeCall::Logger(LoggerCall::log { i: 42, weight: max_weight / 2 - item_weight })
.into(),
));
assert_ok!(Scheduler::do_schedule(
DispatchTime::At(4),
None,
127,
root(),
Call::Logger(LoggerCall::log { i: 69, weight: max_weight / 2 - item_weight }).into(),
RuntimeCall::Logger(LoggerCall::log { i: 69, weight: max_weight / 2 - item_weight })
.into(),
));
assert_ok!(Scheduler::do_schedule(
DispatchTime::At(4),
None,
126,
root(),
Call::Logger(LoggerCall::log {
RuntimeCall::Logger(LoggerCall::log {
i: 2600,
weight: max_weight / 2 - item_weight + Weight::from_ref_time(1)
})
@@ -487,8 +523,11 @@ fn on_initialize_weight_is_correct() {
None,
255,
root(),
Call::Logger(LoggerCall::log { i: 3, weight: call_weight + Weight::from_ref_time(1) })
.into(),
RuntimeCall::Logger(LoggerCall::log {
i: 3,
weight: call_weight + Weight::from_ref_time(1)
})
.into(),
));
// Anon Periodic
assert_ok!(Scheduler::do_schedule(
@@ -496,8 +535,11 @@ fn on_initialize_weight_is_correct() {
Some((1000, 3)),
128,
root(),
Call::Logger(LoggerCall::log { i: 42, weight: call_weight + Weight::from_ref_time(2) })
.into(),
RuntimeCall::Logger(LoggerCall::log {
i: 42,
weight: call_weight + Weight::from_ref_time(2)
})
.into(),
));
// Anon
assert_ok!(Scheduler::do_schedule(
@@ -505,8 +547,11 @@ fn on_initialize_weight_is_correct() {
None,
127,
root(),
Call::Logger(LoggerCall::log { i: 69, weight: call_weight + Weight::from_ref_time(3) })
.into(),
RuntimeCall::Logger(LoggerCall::log {
i: 69,
weight: call_weight + Weight::from_ref_time(3)
})
.into(),
));
// Named Periodic
assert_ok!(Scheduler::do_schedule_named(
@@ -515,7 +560,7 @@ fn on_initialize_weight_is_correct() {
Some((1000, 3)),
126,
root(),
Call::Logger(LoggerCall::log {
RuntimeCall::Logger(LoggerCall::log {
i: 2600,
weight: call_weight + Weight::from_ref_time(4)
})
@@ -567,10 +612,12 @@ fn on_initialize_weight_is_correct() {
fn root_calls_works() {
new_test_ext().execute_with(|| {
let call = Box::new(
Call::Logger(LoggerCall::log { i: 69, weight: Weight::from_ref_time(1000) }).into(),
RuntimeCall::Logger(LoggerCall::log { i: 69, weight: Weight::from_ref_time(1000) })
.into(),
);
let call2 = Box::new(
Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) }).into(),
RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) })
.into(),
);
assert_ok!(Scheduler::schedule_named(Origin::root(), 1u32.encode(), 4, None, 127, call,));
assert_ok!(Scheduler::schedule(Origin::root(), 4, None, 127, call2));
@@ -592,15 +639,17 @@ fn fails_to_schedule_task_in_the_past() {
run_to_block(3);
let call1 = Box::new(
Call::Logger(LoggerCall::log { i: 69, weight: Weight::from_ref_time(1000) }).into(),
RuntimeCall::Logger(LoggerCall::log { i: 69, weight: Weight::from_ref_time(1000) })
.into(),
);
let call2 = Box::new(
Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) }).into(),
RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) })
.into(),
);
let call3 = Box::new(
Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) }).into(),
RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) })
.into(),
);
assert_err!(
Scheduler::schedule_named(Origin::root(), 1u32.encode(), 2, None, 127, call1),
Error::<Test>::TargetBlockNumberInPast,
@@ -622,10 +671,12 @@ fn fails_to_schedule_task_in_the_past() {
fn should_use_orign() {
new_test_ext().execute_with(|| {
let call = Box::new(
Call::Logger(LoggerCall::log { i: 69, weight: Weight::from_ref_time(1000) }).into(),
RuntimeCall::Logger(LoggerCall::log { i: 69, weight: Weight::from_ref_time(1000) })
.into(),
);
let call2 = Box::new(
Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) }).into(),
RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) })
.into(),
);
assert_ok!(Scheduler::schedule_named(
system::RawOrigin::Signed(1).into(),
@@ -652,10 +703,12 @@ fn should_use_orign() {
fn should_check_orign() {
new_test_ext().execute_with(|| {
let call = Box::new(
Call::Logger(LoggerCall::log { i: 69, weight: Weight::from_ref_time(1000) }).into(),
RuntimeCall::Logger(LoggerCall::log { i: 69, weight: Weight::from_ref_time(1000) })
.into(),
);
let call2 = Box::new(
Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) }).into(),
RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) })
.into(),
);
assert_noop!(
Scheduler::schedule_named(
@@ -679,14 +732,14 @@ fn should_check_orign() {
fn should_check_orign_for_cancel() {
new_test_ext().execute_with(|| {
let call = Box::new(
Call::Logger(LoggerCall::log_without_filter {
RuntimeCall::Logger(LoggerCall::log_without_filter {
i: 69,
weight: Weight::from_ref_time(1000),
})
.into(),
);
let call2 = Box::new(
Call::Logger(LoggerCall::log_without_filter {
RuntimeCall::Logger(LoggerCall::log_without_filter {
i: 42,
weight: Weight::from_ref_time(1000),
})
@@ -735,7 +788,7 @@ fn migration_to_v3_works() {
Some(ScheduledV1 {
maybe_id: None,
priority: i as u8 + 10,
call: Call::Logger(LoggerCall::log {
call: RuntimeCall::Logger(LoggerCall::log {
i: 96,
weight: Weight::from_ref_time(100),
}),
@@ -745,7 +798,7 @@ fn migration_to_v3_works() {
Some(ScheduledV1 {
maybe_id: Some(b"test".to_vec()),
priority: 123,
call: Call::Logger(LoggerCall::log {
call: RuntimeCall::Logger(LoggerCall::log {
i: 69,
weight: Weight::from_ref_time(1000),
}),
@@ -766,7 +819,7 @@ fn migration_to_v3_works() {
Some(ScheduledV3Of::<Test> {
maybe_id: None,
priority: 10,
call: Call::Logger(LoggerCall::log {
call: RuntimeCall::Logger(LoggerCall::log {
i: 96,
weight: Weight::from_ref_time(100)
})
@@ -779,7 +832,7 @@ fn migration_to_v3_works() {
Some(ScheduledV3Of::<Test> {
maybe_id: Some(b"test".to_vec()),
priority: 123,
call: Call::Logger(LoggerCall::log {
call: RuntimeCall::Logger(LoggerCall::log {
i: 69,
weight: Weight::from_ref_time(1000)
})
@@ -796,7 +849,7 @@ fn migration_to_v3_works() {
Some(ScheduledV3Of::<Test> {
maybe_id: None,
priority: 11,
call: Call::Logger(LoggerCall::log {
call: RuntimeCall::Logger(LoggerCall::log {
i: 96,
weight: Weight::from_ref_time(100)
})
@@ -809,7 +862,7 @@ fn migration_to_v3_works() {
Some(ScheduledV3Of::<Test> {
maybe_id: Some(b"test".to_vec()),
priority: 123,
call: Call::Logger(LoggerCall::log {
call: RuntimeCall::Logger(LoggerCall::log {
i: 69,
weight: Weight::from_ref_time(1000)
})
@@ -826,7 +879,7 @@ fn migration_to_v3_works() {
Some(ScheduledV3Of::<Test> {
maybe_id: None,
priority: 12,
call: Call::Logger(LoggerCall::log {
call: RuntimeCall::Logger(LoggerCall::log {
i: 96,
weight: Weight::from_ref_time(100)
})
@@ -839,7 +892,7 @@ fn migration_to_v3_works() {
Some(ScheduledV3Of::<Test> {
maybe_id: Some(b"test".to_vec()),
priority: 123,
call: Call::Logger(LoggerCall::log {
call: RuntimeCall::Logger(LoggerCall::log {
i: 69,
weight: Weight::from_ref_time(1000)
})
@@ -866,7 +919,7 @@ fn test_migrate_origin() {
Some(Scheduled {
maybe_id: None,
priority: i as u8 + 10,
call: Call::Logger(LoggerCall::log {
call: RuntimeCall::Logger(LoggerCall::log {
i: 96,
weight: Weight::from_ref_time(100),
})
@@ -880,7 +933,7 @@ fn test_migrate_origin() {
maybe_id: Some(b"test".to_vec()),
priority: 123,
origin: 2u32,
call: Call::Logger(LoggerCall::log {
call: RuntimeCall::Logger(LoggerCall::log {
i: 69,
weight: Weight::from_ref_time(1000),
})
@@ -913,7 +966,7 @@ fn test_migrate_origin() {
Some(ScheduledV2::<CallOrHashOf<Test>, u64, OriginCaller, u64> {
maybe_id: None,
priority: 10,
call: Call::Logger(LoggerCall::log {
call: RuntimeCall::Logger(LoggerCall::log {
i: 96,
weight: Weight::from_ref_time(100)
})
@@ -926,7 +979,7 @@ fn test_migrate_origin() {
Some(ScheduledV2 {
maybe_id: Some(b"test".to_vec()),
priority: 123,
call: Call::Logger(LoggerCall::log {
call: RuntimeCall::Logger(LoggerCall::log {
i: 69,
weight: Weight::from_ref_time(1000)
})
@@ -943,7 +996,7 @@ fn test_migrate_origin() {
Some(ScheduledV2 {
maybe_id: None,
priority: 11,
call: Call::Logger(LoggerCall::log {
call: RuntimeCall::Logger(LoggerCall::log {
i: 96,
weight: Weight::from_ref_time(100)
})
@@ -956,7 +1009,7 @@ fn test_migrate_origin() {
Some(ScheduledV2 {
maybe_id: Some(b"test".to_vec()),
priority: 123,
call: Call::Logger(LoggerCall::log {
call: RuntimeCall::Logger(LoggerCall::log {
i: 69,
weight: Weight::from_ref_time(1000)
})
@@ -973,7 +1026,7 @@ fn test_migrate_origin() {
Some(ScheduledV2 {
maybe_id: None,
priority: 12,
call: Call::Logger(LoggerCall::log {
call: RuntimeCall::Logger(LoggerCall::log {
i: 96,
weight: Weight::from_ref_time(100)
})
@@ -986,7 +1039,7 @@ fn test_migrate_origin() {
Some(ScheduledV2 {
maybe_id: Some(b"test".to_vec()),
priority: 123,
call: Call::Logger(LoggerCall::log {
call: RuntimeCall::Logger(LoggerCall::log {
i: 69,
weight: Weight::from_ref_time(1000)
})