Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6d11c9d
allow specify schedule dispatch origin
xlc Jun 18, 2020
8aa6ed9
fix tests
xlc Jun 19, 2020
a572232
use caller origin for scheduled
xlc Jun 19, 2020
8eba0a4
fix tests
xlc Jun 19, 2020
d51269a
line width
xlc Jun 19, 2020
5f1ee49
check origin for cancel
xlc Jun 19, 2020
fb5b48d
line width
xlc Jun 19, 2020
b7c9cba
fix some issues for benchmarking
xlc Jun 19, 2020
b2e1067
fix doc test
xlc Jun 19, 2020
f61230b
another way to constraint origin
xlc Jun 20, 2020
061d78f
Merge remote-tracking branch 'origin/master' into update-scheduler
xlc Jun 20, 2020
f43f468
fix build issues
xlc Jun 21, 2020
14b7522
fix cancel
xlc Jun 21, 2020
2c4a7d2
line width
xlc Jun 21, 2020
bc166a7
fix benchmarks
xlc Jun 21, 2020
9fc1fc0
bump version
xlc Jun 21, 2020
97cbaf3
enable runtime upgrade
xlc Jun 22, 2020
9dc582a
add migration code and test
xlc Jun 23, 2020
dd97a5a
Merge remote-tracking branch 'origin/master' into update-scheduler
xlc Jun 23, 2020
ae0231a
Update frame/scheduler/src/lib.rs
xlc Jun 23, 2020
c3f9e55
expose migration method
xlc Jun 23, 2020
5f00a81
Merge remote-tracking branch 'origin/master' into update-scheduler
xlc Jun 23, 2020
39040bc
add notes
xlc Jun 23, 2020
79cde79
Merge remote-tracking branch 'origin/master' into update-scheduler
xlc Jun 24, 2020
4099003
Merge remote-tracking branch 'origin/master' into update-scheduler
xlc Jun 25, 2020
b9000e8
Merge remote-tracking branch 'origin/master' into update-scheduler
xlc Jun 27, 2020
5b65287
bump version
xlc Jun 27, 2020
f19c49f
remove on_runtime_upgrade
xlc Jun 27, 2020
40e99bc
fix test
xlc Jun 27, 2020
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
Prev Previous commit
Next Next commit
fix tests
  • Loading branch information
xlc committed Jun 19, 2020
commit 8aa6ed995a88efd7c90a1351bad62e47a75e69db
2 changes: 2 additions & 0 deletions frame/democracy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ parameter_types! {
impl pallet_scheduler::Trait for Test {
type Event = Event;
type Origin = Origin;
type PalletsOrigin = OriginCaller;
type Call = Call;
type MaximumWeight = MaximumSchedulerWeight;
}
Expand Down Expand Up @@ -188,6 +189,7 @@ impl super::Trait for Test {
type Scheduler = Scheduler;
type MaxVotes = MaxVotes;
type OperationalPreimageOrigin = EnsureSignedBy<Six, u64>;
type PalletsOrigin = OriginCaller;
}

pub fn new_test_ext() -> sp_io::TestExternalities {
Expand Down
81 changes: 61 additions & 20 deletions frame/scheduler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ mod tests {
impl Trait for Test {
type Event = ();
type Origin = Origin;
type PalletsOrigin = OriginCaller;
type Call = Call;
type MaximumWeight = MaximumSchedulerWeight;
}
Expand All @@ -574,7 +575,9 @@ mod tests {
#[test]
fn basic_scheduling_works() {
new_test_ext().execute_with(|| {
Scheduler::do_schedule(4, None, 127, Call::Logger(logger::Call::log(42, 1000)));
Scheduler::do_schedule(
4, None, 127, system::RawOrigin::Root.into(), Call::Logger(logger::Call::log(42, 1000))
);
run_to_block(3);
assert!(logger::log().is_empty());
run_to_block(4);
Expand All @@ -588,7 +591,9 @@ mod tests {
fn periodic_scheduling_works() {
new_test_ext().execute_with(|| {
// at #4, every 3 blocks, 3 times.
Scheduler::do_schedule(4, Some((3, 3)), 127, Call::Logger(logger::Call::log(42, 1000)));
Scheduler::do_schedule(
4, Some((3, 3)), 127, system::RawOrigin::Root.into(), Call::Logger(logger::Call::log(42, 1000))
);
run_to_block(3);
assert!(logger::log().is_empty());
run_to_block(4);
Expand All @@ -610,8 +615,12 @@ mod tests {
fn cancel_named_scheduling_works_with_normal_cancel() {
new_test_ext().execute_with(|| {
// at #4.
Scheduler::do_schedule_named(1u32.encode(), 4, None, 127, Call::Logger(logger::Call::log(69, 1000))).unwrap();
let i = Scheduler::do_schedule(4, None, 127, Call::Logger(logger::Call::log(42, 1000)));
Scheduler::do_schedule_named(
1u32.encode(), 4, None, 127, system::RawOrigin::Root.into(), Call::Logger(logger::Call::log(69, 1000))
).unwrap();
let i = Scheduler::do_schedule(
4, None, 127, system::RawOrigin::Root.into(), Call::Logger(logger::Call::log(42, 1000))
);
run_to_block(3);
assert!(logger::log().is_empty());
assert_ok!(Scheduler::do_cancel_named(1u32.encode()));
Expand All @@ -625,11 +634,17 @@ mod tests {
fn cancel_named_periodic_scheduling_works() {
new_test_ext().execute_with(|| {
// at #4, every 3 blocks, 3 times.
Scheduler::do_schedule_named(1u32.encode(), 4, Some((3, 3)), 127, Call::Logger(logger::Call::log(42, 1000))).unwrap();
Scheduler::do_schedule_named(
1u32.encode(), 4, Some((3, 3)), 127, system::RawOrigin::Root.into(), Call::Logger(logger::Call::log(42, 1000))
).unwrap();
// same id results in error.
assert!(Scheduler::do_schedule_named(1u32.encode(), 4, None, 127, Call::Logger(logger::Call::log(69, 1000))).is_err());
assert!(Scheduler::do_schedule_named(
1u32.encode(), 4, None, 127, system::RawOrigin::Root.into(), Call::Logger(logger::Call::log(69, 1000))
).is_err());
// different id is ok.
Scheduler::do_schedule_named(2u32.encode(), 8, None, 127, Call::Logger(logger::Call::log(69, 1000))).unwrap();
Scheduler::do_schedule_named(
2u32.encode(), 8, None, 127, system::RawOrigin::Root.into(), Call::Logger(logger::Call::log(69, 1000))
).unwrap();
run_to_block(3);
assert!(logger::log().is_empty());
run_to_block(4);
Expand All @@ -644,8 +659,12 @@ mod tests {
#[test]
fn scheduler_respects_weight_limits() {
new_test_ext().execute_with(|| {
Scheduler::do_schedule(4, None, 127, Call::Logger(logger::Call::log(42, MaximumSchedulerWeight::get() / 2)));
Scheduler::do_schedule(4, None, 127, Call::Logger(logger::Call::log(69, MaximumSchedulerWeight::get() / 2)));
Scheduler::do_schedule(
4, None, 127, system::RawOrigin::Root.into(), Call::Logger(logger::Call::log(42, MaximumSchedulerWeight::get() / 2))
);
Scheduler::do_schedule(
4, None, 127, system::RawOrigin::Root.into(), Call::Logger(logger::Call::log(69, MaximumSchedulerWeight::get() / 2))
);
// 69 and 42 do not fit together
run_to_block(4);
assert_eq!(logger::log(), vec![42u32]);
Expand All @@ -657,8 +676,12 @@ mod tests {
#[test]
fn scheduler_respects_hard_deadlines_more() {
new_test_ext().execute_with(|| {
Scheduler::do_schedule(4, None, 0, Call::Logger(logger::Call::log(42, MaximumSchedulerWeight::get() / 2)));
Scheduler::do_schedule(4, None, 0, Call::Logger(logger::Call::log(69, MaximumSchedulerWeight::get() / 2)));
Scheduler::do_schedule(
4, None, 0, system::RawOrigin::Root.into(), Call::Logger(logger::Call::log(42, MaximumSchedulerWeight::get() / 2))
);
Scheduler::do_schedule(
4, None, 0, system::RawOrigin::Root.into(), Call::Logger(logger::Call::log(69, MaximumSchedulerWeight::get() / 2))
);
// With base weights, 69 and 42 should not fit together, but do because of hard deadlines
run_to_block(4);
assert_eq!(logger::log(), vec![42u32, 69u32]);
Expand All @@ -668,8 +691,12 @@ mod tests {
#[test]
fn scheduler_respects_priority_ordering() {
new_test_ext().execute_with(|| {
Scheduler::do_schedule(4, None, 1, Call::Logger(logger::Call::log(42, MaximumSchedulerWeight::get() / 2)));
Scheduler::do_schedule(4, None, 0, Call::Logger(logger::Call::log(69, MaximumSchedulerWeight::get() / 2)));
Scheduler::do_schedule(
4, None, 1, system::RawOrigin::Root.into(), Call::Logger(logger::Call::log(42, MaximumSchedulerWeight::get() / 2))
);
Scheduler::do_schedule(
4, None, 0, system::RawOrigin::Root.into(), Call::Logger(logger::Call::log(69, MaximumSchedulerWeight::get() / 2))
);
run_to_block(4);
assert_eq!(logger::log(), vec![69u32, 42u32]);
});
Expand All @@ -678,9 +705,15 @@ mod tests {
#[test]
fn scheduler_respects_priority_ordering_with_soft_deadlines() {
new_test_ext().execute_with(|| {
Scheduler::do_schedule(4, None, 255, Call::Logger(logger::Call::log(42, MaximumSchedulerWeight::get() / 3)));
Scheduler::do_schedule(4, None, 127, Call::Logger(logger::Call::log(69, MaximumSchedulerWeight::get() / 2)));
Scheduler::do_schedule(4, None, 126, Call::Logger(logger::Call::log(2600, MaximumSchedulerWeight::get() / 2)));
Scheduler::do_schedule(
4, None, 255, system::RawOrigin::Root.into(), Call::Logger(logger::Call::log(42, MaximumSchedulerWeight::get() / 3))
);
Scheduler::do_schedule(
4, None, 127, system::RawOrigin::Root.into(), Call::Logger(logger::Call::log(69, MaximumSchedulerWeight::get() / 2))
);
Scheduler::do_schedule(
4, None, 126, system::RawOrigin::Root.into(), Call::Logger(logger::Call::log(2600, MaximumSchedulerWeight::get() / 2))
);

// 2600 does not fit with 69 or 42, but has higher priority, so will go through
run_to_block(4);
Expand All @@ -700,13 +733,21 @@ mod tests {
let periodic_multiplier = <Test as frame_system::Trait>::DbWeight::get().reads_writes(1, 1);

// Named
assert_ok!(Scheduler::do_schedule_named(1u32.encode(), 1, None, 255, Call::Logger(logger::Call::log(3, MaximumSchedulerWeight::get() / 3))));
assert_ok!(Scheduler::do_schedule_named(
1u32.encode(), 1, None, 255, system::RawOrigin::Root.into(), Call::Logger(logger::Call::log(3, MaximumSchedulerWeight::get() / 3)))
);
// Anon Periodic
Scheduler::do_schedule(1, Some((1000, 3)), 128, Call::Logger(logger::Call::log(42, MaximumSchedulerWeight::get() / 3)));
Scheduler::do_schedule(
1, Some((1000, 3)), 128, system::RawOrigin::Root.into(), Call::Logger(logger::Call::log(42, MaximumSchedulerWeight::get() / 3))
);
// Anon
Scheduler::do_schedule(1, None, 127, Call::Logger(logger::Call::log(69, MaximumSchedulerWeight::get() / 2)));
Scheduler::do_schedule(
1, None, 127, system::RawOrigin::Root.into(), Call::Logger(logger::Call::log(69, MaximumSchedulerWeight::get() / 2))
);
// Named Periodic
assert_ok!(Scheduler::do_schedule_named(2u32.encode(), 1, Some((1000, 3)), 126, Call::Logger(logger::Call::log(2600, MaximumSchedulerWeight::get() / 2))));
assert_ok!(Scheduler::do_schedule_named(
2u32.encode(), 1, Some((1000, 3)), 126, system::RawOrigin::Root.into(), Call::Logger(logger::Call::log(2600, MaximumSchedulerWeight::get() / 2)))
);

// Will include the named periodic only
let actual_weight = Scheduler::on_initialize(1);
Expand Down
4 changes: 3 additions & 1 deletion frame/support/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2171,14 +2171,16 @@ mod tests {
}

pub mod system {
use codec::{Encode, Decode};

pub trait Trait {
type AccountId;
type Call;
type BaseCallFilter;
type Origin: crate::traits::OriginTrait<Call = Self::Call>;
}

#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode)]
pub enum RawOrigin<AccountId> {
Root,
Signed(AccountId),
Expand Down
2 changes: 1 addition & 1 deletion frame/support/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ mod tests {
}
);

#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode)]
pub enum RawOrigin<AccountId> {
Root,
Signed(AccountId),
Expand Down
15 changes: 11 additions & 4 deletions frame/support/src/origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,18 @@ macro_rules! impl_outer_origin {

#[cfg(test)]
mod tests {
use codec::{Encode, Decode};
use crate::traits::{Filter, OriginTrait};
mod system {
use super::*;

pub trait Trait {
type AccountId;
type Call;
type BaseCallFilter;
}

#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode)]
pub enum RawOrigin<AccountId> {
Root,
Signed(AccountId),
Expand All @@ -360,18 +363,22 @@ mod tests {
}

mod origin_without_generic {
#[derive(Clone, PartialEq, Eq, Debug)]
use super::*;

#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode)]
pub struct Origin;
}

mod origin_with_generic {
#[derive(Clone, PartialEq, Eq, Debug)]
use super::*;

#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode)]
pub struct Origin<T> {
t: T
}
}

#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode)]
pub struct TestRuntime;

pub struct BaseCallFilter;
Expand Down
7 changes: 4 additions & 3 deletions frame/support/test/tests/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#![recursion_limit="128"]

use codec::{Codec, EncodeLike, Encode, Decode};
use sp_runtime::{generic, BuildStorage, traits::{BlakeTwo256, Block as _, Verify}};
use frame_support::{
Parameter, traits::Get, parameter_types,
Expand Down Expand Up @@ -44,7 +45,7 @@ mod module1 {
type Event: From<Event<Self, I>> + Into<<Self as system::Trait>::Event>;
type Origin: From<Origin<Self, I>>;
type SomeParameter: Get<u32>;
type GenericType: Default + Clone + codec::Codec + codec::EncodeLike;
type GenericType: Default + Clone + Codec + EncodeLike;
}

frame_support::decl_module! {
Expand Down Expand Up @@ -87,7 +88,7 @@ mod module1 {
}
}

#[derive(PartialEq, Eq, Clone, sp_runtime::RuntimeDebug)]
#[derive(PartialEq, Eq, Clone, sp_runtime::RuntimeDebug, Encode, Decode)]
pub enum Origin<T: Trait<I>, I> where T::BlockNumber: From<u32> {
Members(u32),
_Phantom(std::marker::PhantomData<(T, I)>),
Expand Down Expand Up @@ -148,7 +149,7 @@ mod module2 {
}
}

#[derive(PartialEq, Eq, Clone, sp_runtime::RuntimeDebug)]
#[derive(PartialEq, Eq, Clone, sp_runtime::RuntimeDebug, Encode, Decode)]
pub enum Origin<T: Trait<I>, I=DefaultInstance> {
Members(u32),
_Phantom(std::marker::PhantomData<(T, I)>),
Expand Down
2 changes: 1 addition & 1 deletion frame/support/test/tests/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ frame_support::decl_error! {
}

/// Origin for the system module.
#[derive(PartialEq, Eq, Clone, sp_runtime::RuntimeDebug)]
#[derive(PartialEq, Eq, Clone, sp_runtime::RuntimeDebug, Encode, Decode)]
pub enum RawOrigin<AccountId> {
Root,
Signed(AccountId),
Expand Down