Rename pallet trait Trait to Config (#7599)

* rename Trait to Config

* add test asserting using Trait is still valid.

* fix ui tests
This commit is contained in:
Guillaume Thiolliere
2020-11-30 15:34:54 +01:00
committed by GitHub
parent dd3c84c362
commit 1cbfc9257f
200 changed files with 1767 additions and 1607 deletions
@@ -37,11 +37,11 @@ thread_local! {
mod module1 {
use super::*;
pub trait Trait<I>: system::Trait {}
pub trait Config<I>: system::Config {}
frame_support::decl_module! {
pub struct Module<T: Trait<I>, I: Instance = DefaultInstance> for enum Call
where origin: <T as system::Trait>::Origin, system=system
pub struct Module<T: Config<I>, I: Instance = DefaultInstance> for enum Call
where origin: <T as system::Config>::Origin, system=system
{
#[weight = 0]
pub fn fail(_origin) -> frame_support::dispatch::DispatchResult {
@@ -55,31 +55,31 @@ mod module1 {
frame_support::decl_event! {
pub enum Event<T, I: Instance = DefaultInstance> where
<T as system::Trait>::AccountId
<T as system::Config>::AccountId
{
A(AccountId),
}
}
frame_support::decl_error! {
pub enum Error for Module<T: Trait<I>, I: Instance> {
pub enum Error for Module<T: Config<I>, I: Instance> {
Something
}
}
frame_support::decl_storage! {
trait Store for Module<T: Trait<I>, I: Instance=DefaultInstance> as Module {}
trait Store for Module<T: Config<I>, I: Instance=DefaultInstance> as Module {}
}
}
mod module2 {
use super::*;
pub trait Trait: system::Trait {}
pub trait Config: system::Config {}
frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call
where origin: <T as system::Trait>::Origin, system=system
pub struct Module<T: Config> for enum Call
where origin: <T as system::Config>::Origin, system=system
{
#[weight = 0]
pub fn fail(_origin) -> frame_support::dispatch::DispatchResult {
@@ -102,25 +102,25 @@ mod module2 {
}
frame_support::decl_error! {
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
Something
}
}
frame_support::decl_storage! {
trait Store for Module<T: Trait> as Module {}
trait Store for Module<T: Config> as Module {}
}
}
impl<I> module1::Trait<I> for Runtime {}
impl module2::Trait for Runtime {}
impl<I> module1::Config<I> for Runtime {}
impl module2::Config for Runtime {}
pub type Signature = sr25519::Signature;
pub type AccountId = <Signature as Verify>::Signer;
pub type BlockNumber = u64;
pub type Index = u64;
impl system::Trait for Runtime {
impl system::Config for Runtime {
type BaseCallFilter = ();
type Hash = H256;
type Origin = Origin;
@@ -1,5 +1,5 @@
frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {
fn integrity_test() {}
fn integrity_test() {}
@@ -2,7 +2,7 @@ error: `integrity_test` can only be passed once as input.
--> $DIR/reserved_keyword_two_times_integrity_test.rs:1:1
|
1 | / frame_support::decl_module! {
2 | | pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {
2 | | pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {
3 | | fn integrity_test() {}
4 | |
5 | | fn integrity_test() {}
@@ -16,7 +16,7 @@ error[E0601]: `main` function not found in crate `$CRATE`
--> $DIR/reserved_keyword_two_times_integrity_test.rs:1:1
|
1 | / frame_support::decl_module! {
2 | | pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {
2 | | pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {
3 | | fn integrity_test() {}
4 | |
5 | | fn integrity_test() {}
@@ -1,5 +1,5 @@
frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {
fn on_initialize() -> Weight {
0
}
@@ -2,7 +2,7 @@ error: `on_initialize` can only be passed once as input.
--> $DIR/reserved_keyword_two_times_on_initialize.rs:1:1
|
1 | / frame_support::decl_module! {
2 | | pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {
2 | | pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {
3 | | fn on_initialize() -> Weight {
4 | | 0
... |
@@ -16,7 +16,7 @@ error[E0601]: `main` function not found in crate `$CRATE`
--> $DIR/reserved_keyword_two_times_on_initialize.rs:1:1
|
1 | / frame_support::decl_module! {
2 | | pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {
2 | | pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {
3 | | fn on_initialize() -> Weight {
4 | | 0
... |
@@ -24,13 +24,13 @@ mod tests {
use std::marker::PhantomData;
frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=frame_support_test {}
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=frame_support_test {}
}
pub trait Trait: frame_support_test::Trait {}
pub trait Config: frame_support_test::Config {}
frame_support::decl_storage! {
trait Store for Module<T: Trait> as TestStorage {
trait Store for Module<T: Config> as TestStorage {
// non-getters: pub / $default
/// Hello, this is doc!
@@ -81,14 +81,14 @@ mod tests {
struct TraitImpl {}
impl frame_support_test::Trait for TraitImpl {
impl frame_support_test::Config for TraitImpl {
type Origin = u32;
type BlockNumber = u32;
type PalletInfo = ();
type DbWeight = ();
}
impl Trait for TraitImpl {}
impl Config for TraitImpl {}
const EXPECTED_METADATA: StorageMetadata = StorageMetadata {
prefix: DecodeDifferent::Encode("TestStorage"),
@@ -414,16 +414,16 @@ mod tests {
#[cfg(test)]
#[allow(dead_code)]
mod test2 {
pub trait Trait: frame_support_test::Trait {}
pub trait Config: frame_support_test::Config {}
frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=frame_support_test {}
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=frame_support_test {}
}
type PairOf<T> = (T, T);
frame_support::decl_storage! {
trait Store for Module<T: Trait> as TestStorage {
trait Store for Module<T: Config> as TestStorage {
SingleDef : u32;
PairDef : PairOf<u32>;
Single : Option<u32>;
@@ -438,26 +438,26 @@ mod test2 {
struct TraitImpl {}
impl frame_support_test::Trait for TraitImpl {
impl frame_support_test::Config for TraitImpl {
type Origin = u32;
type BlockNumber = u32;
type PalletInfo = ();
type DbWeight = ();
}
impl Trait for TraitImpl {}
impl Config for TraitImpl {}
}
#[cfg(test)]
#[allow(dead_code)]
mod test3 {
pub trait Trait: frame_support_test::Trait {}
pub trait Config: frame_support_test::Config {}
frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=frame_support_test {}
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=frame_support_test {}
}
frame_support::decl_storage! {
trait Store for Module<T: Trait> as Test {
trait Store for Module<T: Config> as Test {
Foo get(fn foo) config(initial_foo): u32;
}
}
@@ -466,14 +466,14 @@ mod test3 {
struct TraitImpl {}
impl frame_support_test::Trait for TraitImpl {
impl frame_support_test::Config for TraitImpl {
type Origin = u32;
type BlockNumber = u32;
type PalletInfo = ();
type DbWeight = ();
}
impl Trait for TraitImpl {}
impl Config for TraitImpl {}
}
#[cfg(test)]
@@ -482,17 +482,17 @@ mod test_append_and_len {
use sp_io::TestExternalities;
use codec::{Encode, Decode};
pub trait Trait: frame_support_test::Trait {}
pub trait Config: frame_support_test::Config {}
frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=frame_support_test {}
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=frame_support_test {}
}
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
struct NoDef(u32);
frame_support::decl_storage! {
trait Store for Module<T: Trait> as Test {
trait Store for Module<T: Config> as Test {
NoDefault: Option<NoDef>;
JustVec: Vec<u32>;
@@ -511,14 +511,14 @@ mod test_append_and_len {
struct Test {}
impl frame_support_test::Trait for Test {
impl frame_support_test::Config for Test {
type Origin = u32;
type BlockNumber = u32;
type PalletInfo = ();
type DbWeight = ();
}
impl Trait for Test {}
impl Config for Test {}
#[test]
fn default_for_option() {
@@ -15,14 +15,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
pub trait Trait: frame_support_test::Trait {}
pub trait Config: frame_support_test::Config {}
frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=frame_support_test {}
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=frame_support_test {}
}
frame_support::decl_storage!{
trait Store for Module<T: Trait> as FinalKeysNone {
trait Store for Module<T: Config> as FinalKeysNone {
pub Value config(value): u32;
pub Value2 config(value): u32;
}
@@ -15,14 +15,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
pub trait Trait: frame_support_test::Trait {}
pub trait Config: frame_support_test::Config {}
frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=frame_support_test {}
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=frame_support_test {}
}
frame_support::decl_storage!{
trait Store for Module<T: Trait> as FinalKeysNone {
trait Store for Module<T: Config> as FinalKeysNone {
pub Value get(fn value) config(): u32;
pub Value2 config(value): u32;
}
@@ -15,14 +15,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
pub trait Trait: frame_support_test::Trait {}
pub trait Config: frame_support_test::Config {}
frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=frame_support_test {}
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=frame_support_test {}
}
frame_support::decl_storage!{
trait Store for Module<T: Trait> as FinalKeysNone {
trait Store for Module<T: Config> as FinalKeysNone {
pub Value get(fn value) config(): u32;
pub Value2 get(fn value) config(): u32;
}
@@ -28,19 +28,19 @@ fn runtime_debug_no_bound_display_correctly() {
assert_eq!(format!("{:?}", Unnamed(1)), "Unnamed(1)");
}
trait Trait {
trait Config {
type C: std::fmt::Debug + Clone + Eq + PartialEq;
}
struct Runtime;
struct ImplNone;
impl Trait for Runtime {
impl Config for Runtime {
type C = u32;
}
#[derive(DebugNoBound, CloneNoBound, EqNoBound, PartialEqNoBound)]
struct StructNamed<T: Trait, U, V> {
struct StructNamed<T: Config, U, V> {
a: u32,
b: u64,
c: T::C,
@@ -77,7 +77,7 @@ fn test_struct_named() {
}
#[derive(DebugNoBound, CloneNoBound, EqNoBound, PartialEqNoBound)]
struct StructUnnamed<T: Trait, U, V>(u32, u64, T::C, core::marker::PhantomData<(U, V)>);
struct StructUnnamed<T: Config, U, V>(u32, u64, T::C, core::marker::PhantomData<(U, V)>);
#[test]
fn test_struct_unnamed() {
@@ -109,7 +109,7 @@ fn test_struct_unnamed() {
}
#[derive(DebugNoBound, CloneNoBound, EqNoBound, PartialEqNoBound)]
enum Enum<T: Trait, U, V> {
enum Enum<T: Config, U, V> {
VariantUnnamed(u32, u64, T::C, core::marker::PhantomData<(U, V)>),
VariantNamed {
a: u32,
@@ -1,9 +1,9 @@
trait Trait {
trait Config {
type C;
}
#[derive(frame_support::CloneNoBound)]
struct Foo<T: Trait> {
struct Foo<T: Config> {
c: T::C,
}
@@ -1,7 +1,7 @@
error[E0277]: the trait bound `<T as Trait>::C: std::clone::Clone` is not satisfied
error[E0277]: the trait bound `<T as Config>::C: std::clone::Clone` is not satisfied
--> $DIR/clone.rs:7:2
|
7 | c: T::C,
| ^ the trait `std::clone::Clone` is not implemented for `<T as Trait>::C`
| ^ the trait `std::clone::Clone` is not implemented for `<T as Config>::C`
|
= note: required by `std::clone::Clone::clone`
@@ -1,9 +1,9 @@
trait Trait {
trait Config {
type C;
}
#[derive(frame_support::DebugNoBound)]
struct Foo<T: Trait> {
struct Foo<T: Config> {
c: T::C,
}
@@ -1,8 +1,8 @@
error[E0277]: `<T as Trait>::C` doesn't implement `std::fmt::Debug`
error[E0277]: `<T as Config>::C` doesn't implement `std::fmt::Debug`
--> $DIR/debug.rs:7:2
|
7 | c: T::C,
| ^ `<T as Trait>::C` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
| ^ `<T as Config>::C` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
|
= help: the trait `std::fmt::Debug` is not implemented for `<T as Trait>::C`
= help: the trait `std::fmt::Debug` is not implemented for `<T as Config>::C`
= note: required for the cast to the object type `dyn std::fmt::Debug`
@@ -1,9 +1,9 @@
trait Trait {
trait Config {
type C;
}
#[derive(frame_support::EqNoBound)]
struct Foo<T: Trait> {
struct Foo<T: Config> {
c: T::C,
}
@@ -1,7 +1,7 @@
error[E0277]: can't compare `Foo<T>` with `Foo<T>`
--> $DIR/eq.rs:6:8
|
6 | struct Foo<T: Trait> {
6 | struct Foo<T: Config> {
| ^^^ no implementation for `Foo<T> == Foo<T>`
|
= help: the trait `std::cmp::PartialEq` is not implemented for `Foo<T>`
@@ -1,9 +1,9 @@
trait Trait {
trait Config {
type C;
}
#[derive(frame_support::PartialEqNoBound)]
struct Foo<T: Trait> {
struct Foo<T: Config> {
c: T::C,
}
@@ -1,7 +1,7 @@
error[E0369]: binary operation `==` cannot be applied to type `<T as Trait>::C`
error[E0369]: binary operation `==` cannot be applied to type `<T as Config>::C`
--> $DIR/partial_eq.rs:7:2
|
7 | c: T::C,
| ^
|
= note: the trait `std::cmp::PartialEq` is not implemented for `<T as Trait>::C`
= note: the trait `std::cmp::PartialEq` is not implemented for `<T as Config>::C`
@@ -21,14 +21,14 @@ use frame_support::{StorageDoubleMap, StorageMap, StorageValue, StoragePrefixedM
use sp_io::{TestExternalities, hashing::{twox_64, twox_128, blake2_128}};
mod no_instance {
pub trait Trait: frame_support_test::Trait {}
pub trait Config: frame_support_test::Config {}
frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=frame_support_test {}
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=frame_support_test {}
}
frame_support::decl_storage!{
trait Store for Module<T: Trait> as FinalKeysNone {
trait Store for Module<T: Config> as FinalKeysNone {
pub Value config(value): u32;
pub Map: map hasher(blake2_128_concat) u32 => u32;
@@ -45,15 +45,15 @@ mod no_instance {
}
mod instance {
pub trait Trait<I = DefaultInstance>: frame_support_test::Trait {}
pub trait Config<I = DefaultInstance>: frame_support_test::Config {}
frame_support::decl_module! {
pub struct Module<T: Trait<I>, I: Instance = DefaultInstance>
pub struct Module<T: Config<I>, I: Instance = DefaultInstance>
for enum Call where origin: T::Origin, system=frame_support_test {}
}
frame_support::decl_storage!{
trait Store for Module<T: Trait<I>, I: Instance = DefaultInstance>
trait Store for Module<T: Config<I>, I: Instance = DefaultInstance>
as FinalKeysSome
{
pub Value config(value): u32;
@@ -15,28 +15,28 @@
// See the License for the specific language governing permissions and
// limitations under the License.
pub trait Trait: frame_support_test::Trait {}
pub trait Config: frame_support_test::Config {}
frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=frame_support_test {}
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=frame_support_test {}
}
frame_support::decl_storage! {
trait Store for Module<T: Trait> as Test {
trait Store for Module<T: Config> as Test {
pub AppendableDM config(t): double_map hasher(identity) u32, hasher(identity) T::BlockNumber => Vec<u32>;
}
}
struct Test;
impl frame_support_test::Trait for Test {
impl frame_support_test::Config for Test {
type BlockNumber = u32;
type Origin = ();
type PalletInfo = ();
type DbWeight = ();
}
impl Trait for Test {}
impl Config for Test {}
#[test]
fn init_genesis_config() {
+27 -27
View File
@@ -41,16 +41,16 @@ mod module1 {
use super::*;
use sp_std::ops::Add;
pub trait Trait<I>: system::Trait where <Self as system::Trait>::BlockNumber: From<u32> {
type Event: From<Event<Self, I>> + Into<<Self as system::Trait>::Event>;
pub trait Config<I>: system::Config where <Self as system::Config>::BlockNumber: From<u32> {
type Event: From<Event<Self, I>> + Into<<Self as system::Config>::Event>;
type Origin: From<Origin<Self, I>>;
type SomeParameter: Get<u32>;
type GenericType: Default + Clone + Codec + EncodeLike;
}
frame_support::decl_module! {
pub struct Module<T: Trait<I>, I: Instance> for enum Call where
origin: <T as system::Trait>::Origin,
pub struct Module<T: Config<I>, I: Instance> for enum Call where
origin: <T as system::Config>::Origin,
system = system,
T::BlockNumber: From<u32>
{
@@ -67,7 +67,7 @@ mod module1 {
}
frame_support::decl_storage! {
trait Store for Module<T: Trait<I>, I: Instance> as Module1 where
trait Store for Module<T: Config<I>, I: Instance> as Module1 where
T::BlockNumber: From<u32> + std::fmt::Display
{
pub Value config(value): T::GenericType;
@@ -83,7 +83,7 @@ mod module1 {
}
frame_support::decl_error! {
pub enum Error for Module<T: Trait<I>, I: Instance> where
pub enum Error for Module<T: Config<I>, I: Instance> where
T::BlockNumber: From<u32>,
T::BlockNumber: Add,
T::AccountId: AsRef<[u8]>,
@@ -101,14 +101,14 @@ mod module1 {
}
#[derive(PartialEq, Eq, Clone, sp_runtime::RuntimeDebug, Encode, Decode)]
pub enum Origin<T: Trait<I>, I> where T::BlockNumber: From<u32> {
pub enum Origin<T: Config<I>, I> where T::BlockNumber: From<u32> {
Members(u32),
_Phantom(std::marker::PhantomData<(T, I)>),
}
pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"12345678";
impl<T: Trait<I>, I: Instance> ProvideInherent for Module<T, I> where
impl<T: Config<I>, I: Instance> ProvideInherent for Module<T, I> where
T::BlockNumber: From<u32>
{
type Call = Call<T, I>;
@@ -131,17 +131,17 @@ mod module1 {
mod module2 {
use super::*;
pub trait Trait<I=DefaultInstance>: system::Trait {
pub trait Config<I=DefaultInstance>: system::Config {
type Amount: Parameter + Default;
type Event: From<Event<Self, I>> + Into<<Self as system::Trait>::Event>;
type Event: From<Event<Self, I>> + Into<<Self as system::Config>::Event>;
type Origin: From<Origin<Self, I>>;
}
impl<T: Trait<I>, I: Instance> Currency for Module<T, I> {}
impl<T: Config<I>, I: Instance> Currency for Module<T, I> {}
frame_support::decl_module! {
pub struct Module<T: Trait<I>, I: Instance=DefaultInstance> for enum Call where
origin: <T as system::Trait>::Origin,
pub struct Module<T: Config<I>, I: Instance=DefaultInstance> for enum Call where
origin: <T as system::Config>::Origin,
system = system
{
fn deposit_event() = default;
@@ -149,7 +149,7 @@ mod module2 {
}
frame_support::decl_storage! {
trait Store for Module<T: Trait<I>, I: Instance=DefaultInstance> as Module2 {
trait Store for Module<T: Config<I>, I: Instance=DefaultInstance> as Module2 {
pub Value config(value): T::Amount;
pub Map config(map): map hasher(identity) u64 => u64;
pub DoubleMap config(double_map): double_map hasher(identity) u64, hasher(identity) u64 => u64;
@@ -157,20 +157,20 @@ mod module2 {
}
frame_support::decl_event! {
pub enum Event<T, I=DefaultInstance> where Amount = <T as Trait<I>>::Amount {
pub enum Event<T, I=DefaultInstance> where Amount = <T as Config<I>>::Amount {
Variant(Amount),
}
}
#[derive(PartialEq, Eq, Clone, sp_runtime::RuntimeDebug, Encode, Decode)]
pub enum Origin<T: Trait<I>, I=DefaultInstance> {
pub enum Origin<T: Config<I>, I=DefaultInstance> {
Members(u32),
_Phantom(std::marker::PhantomData<(T, I)>),
}
pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"12345678";
impl<T: Trait<I>, I: Instance> ProvideInherent for Module<T, I> {
impl<T: Config<I>, I: Instance> ProvideInherent for Module<T, I> {
type Call = Call<T, I>;
type Error = MakeFatalError<sp_inherents::Error>;
const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER;
@@ -190,13 +190,13 @@ mod module2 {
mod module3 {
use super::*;
pub trait Trait: module2::Trait + module2::Trait<module2::Instance1> + system::Trait {
pub trait Config: module2::Config + module2::Config<module2::Instance1> + system::Config {
type Currency: Currency;
type Currency2: Currency;
}
frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: <T as system::Trait>::Origin, system=system {}
pub struct Module<T: Config> for enum Call where origin: <T as system::Config>::Origin, system=system {}
}
}
@@ -204,39 +204,39 @@ parameter_types! {
pub const SomeValue: u32 = 100;
}
impl module1::Trait<module1::Instance1> for Runtime {
impl module1::Config<module1::Instance1> for Runtime {
type Event = Event;
type Origin = Origin;
type SomeParameter = SomeValue;
type GenericType = u32;
}
impl module1::Trait<module1::Instance2> for Runtime {
impl module1::Config<module1::Instance2> for Runtime {
type Event = Event;
type Origin = Origin;
type SomeParameter = SomeValue;
type GenericType = u32;
}
impl module2::Trait for Runtime {
impl module2::Config for Runtime {
type Amount = u16;
type Event = Event;
type Origin = Origin;
}
impl module2::Trait<module2::Instance1> for Runtime {
impl module2::Config<module2::Instance1> for Runtime {
type Amount = u32;
type Event = Event;
type Origin = Origin;
}
impl module2::Trait<module2::Instance2> for Runtime {
impl module2::Config<module2::Instance2> for Runtime {
type Amount = u32;
type Event = Event;
type Origin = Origin;
}
impl module2::Trait<module2::Instance3> for Runtime {
impl module2::Config<module2::Instance3> for Runtime {
type Amount = u64;
type Event = Event;
type Origin = Origin;
}
impl module3::Trait for Runtime {
impl module3::Config for Runtime {
type Currency = Module2_2;
type Currency2 = Module2_3;
}
@@ -246,7 +246,7 @@ pub type AccountId = <Signature as Verify>::Signer;
pub type BlockNumber = u64;
pub type Index = u64;
impl system::Trait for Runtime {
impl system::Config for Runtime {
type BaseCallFilter= ();
type Hash = H256;
type Origin = Origin;
+11 -11
View File
@@ -27,9 +27,9 @@ mod module {
use super::*;
pub type Request<T> = (
<T as system::Trait>::AccountId,
<T as system::Config>::AccountId,
Role,
<T as system::Trait>::BlockNumber,
<T as system::Config>::BlockNumber,
);
pub type Requests<T> = Vec<Request<T>>;
@@ -39,7 +39,7 @@ mod module {
}
#[derive(Encode, Decode, Copy, Clone, Eq, PartialEq, Debug)]
pub struct RoleParameters<T: Trait> {
pub struct RoleParameters<T: Config> {
// minimum actors to maintain - if role is unstaking
// and remaining actors would be less that this value - prevent or punish for unstaking
pub min_actors: u32,
@@ -65,7 +65,7 @@ mod module {
pub startup_grace_period: T::BlockNumber,
}
impl<T: Trait> Default for RoleParameters<T> {
impl<T: Config> Default for RoleParameters<T> {
fn default() -> Self {
Self {
max_actors: 10,
@@ -81,18 +81,18 @@ mod module {
}
}
pub trait Trait: system::Trait {}
pub trait Config: system::Config {}
frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=system {}
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=system {}
}
#[derive(Encode, Decode, Copy, Clone, Serialize, Deserialize)]
pub struct Data<T: Trait> {
pub struct Data<T: Config> {
pub data: T::BlockNumber,
}
impl<T: Trait> Default for Data<T> {
impl<T: Config> Default for Data<T> {
fn default() -> Self {
Self {
data: T::BlockNumber::default(),
@@ -101,7 +101,7 @@ mod module {
}
frame_support::decl_storage! {
trait Store for Module<T: Trait> as Actors {
trait Store for Module<T: Config> as Actors {
/// requirements to enter and maintain status in roles
pub Parameters get(fn parameters) build(|config: &GenesisConfig| {
if config.enable_storage_role {
@@ -157,7 +157,7 @@ pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<u32, Call, Signature, ()>;
impl system::Trait for Runtime {
impl system::Config for Runtime {
type BaseCallFilter = ();
type Hash = H256;
type Origin = Origin;
@@ -169,7 +169,7 @@ impl system::Trait for Runtime {
type DbWeight = ();
}
impl module::Trait for Runtime {}
impl module::Config for Runtime {}
frame_support::construct_runtime!(
pub enum Runtime where
@@ -37,11 +37,11 @@ const SOME_TEST_VERSION: PalletVersion = PalletVersion { major: 3000, minor: 30,
mod module1 {
use super::*;
pub trait Trait: system::Trait {}
pub trait Config: system::Config {}
frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where
origin: <T as system::Trait>::Origin,
pub struct Module<T: Config> for enum Call where
origin: <T as system::Config>::Origin,
system = system,
{}
}
@@ -52,11 +52,11 @@ mod module1 {
mod module2 {
use super::*;
pub trait Trait<I=DefaultInstance>: system::Trait {}
pub trait Config<I=DefaultInstance>: system::Config {}
frame_support::decl_module! {
pub struct Module<T: Trait<I>, I: Instance=DefaultInstance> for enum Call where
origin: <T as system::Trait>::Origin,
pub struct Module<T: Config<I>, I: Instance=DefaultInstance> for enum Call where
origin: <T as system::Config>::Origin,
system = system
{
fn on_runtime_upgrade() -> Weight {
@@ -78,21 +78,21 @@ mod module2 {
}
frame_support::decl_storage! {
trait Store for Module<T: Trait<I>, I: Instance=DefaultInstance> as Module2 {}
trait Store for Module<T: Config<I>, I: Instance=DefaultInstance> as Module2 {}
}
}
impl module1::Trait for Runtime {}
impl module2::Trait for Runtime {}
impl module2::Trait<module2::Instance1> for Runtime {}
impl module2::Trait<module2::Instance2> for Runtime {}
impl module1::Config for Runtime {}
impl module2::Config for Runtime {}
impl module2::Config<module2::Instance1> for Runtime {}
impl module2::Config<module2::Instance2> for Runtime {}
pub type Signature = sr25519::Signature;
pub type AccountId = <Signature as Verify>::Signer;
pub type BlockNumber = u64;
pub type Index = u64;
impl system::Trait for Runtime {
impl system::Config for Runtime {
type BaseCallFilter= ();
type Hash = H256;
type Origin = Origin;
@@ -0,0 +1,157 @@
// This file is part of Substrate.
// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
pub trait Trait: frame_system::Config {
type Balance: frame_support::dispatch::Parameter;
/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
}
frame_support::decl_storage! {
trait Store for Module<T: Trait> as Example {
Dummy get(fn dummy) config(): Option<u32>;
}
}
frame_support::decl_event!(
pub enum Event<T> where B = <T as Trait>::Balance {
Dummy(B),
}
);
frame_support::decl_error!(
pub enum Error for Module<T: Trait> {
Dummy,
}
);
frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
fn deposit_event() = default;
type Error = Error<T>;
const Foo: u32 = u32::max_value();
#[weight = 0]
fn accumulate_dummy(origin, increase_by: T::Balance) {
unimplemented!();
}
fn on_initialize(_n: T::BlockNumber) -> frame_support::weights::Weight {
0
}
}
}
impl<T: Trait> sp_runtime::traits::ValidateUnsigned for Module<T> {
type Call = Call<T>;
fn validate_unsigned(
_source: sp_runtime::transaction_validity::TransactionSource,
_call: &Self::Call,
) -> sp_runtime::transaction_validity::TransactionValidity {
unimplemented!();
}
}
pub const INHERENT_IDENTIFIER: sp_inherents::InherentIdentifier = *b"12345678";
impl<T: Trait> sp_inherents::ProvideInherent for Module<T> {
type Call = Call<T>;
type Error = sp_inherents::MakeFatalError<sp_inherents::Error>;
const INHERENT_IDENTIFIER: sp_inherents::InherentIdentifier = INHERENT_IDENTIFIER;
fn create_inherent(_data: &sp_inherents::InherentData) -> Option<Self::Call> {
unimplemented!();
}
fn check_inherent(_: &Self::Call, _: &sp_inherents::InherentData) -> std::result::Result<(), Self::Error> {
unimplemented!();
}
}
#[cfg(test)]
mod tests {
use crate as pallet_test;
use frame_support::parameter_types;
use sp_runtime::traits::Block;
type SignedExtra = (
frame_system::CheckEra<Runtime>,
frame_system::CheckNonce<Runtime>,
frame_system::CheckWeight<Runtime>,
);
type TestBlock = sp_runtime::generic::Block<TestHeader, TestUncheckedExtrinsic>;
type TestHeader = sp_runtime::generic::Header<u64, sp_runtime::traits::BlakeTwo256>;
type TestUncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic<
<Runtime as frame_system::Config>::AccountId,
<Runtime as frame_system::Config>::Call,
(),
SignedExtra,
>;
frame_support::construct_runtime!(
pub enum Runtime where
Block = TestBlock,
NodeBlock = TestBlock,
UncheckedExtrinsic = TestUncheckedExtrinsic
{
System: frame_system::{Module, Call, Config, Storage, Event<T>},
PalletTest: pallet_test::{Module, Call, Storage, Event<T>, Config, ValidateUnsigned, Inherent},
}
);
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: frame_support::weights::Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: sp_runtime::Perbill = sp_runtime::Perbill::one();
}
impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
type Hash = sp_core::H256;
type Call = Call;
type Hashing = sp_runtime::traits::BlakeTwo256;
type AccountId = u64;
type Lookup = sp_runtime::traits::IdentityLookup<Self::AccountId>;
type Header = TestHeader;
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
type PalletInfo = ();
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
}
impl pallet_test::Trait for Runtime {
type Balance = u32;
type Event = ();
}
}
@@ -4,7 +4,7 @@ macro_rules! reserved {
mod $reserved {
pub use frame_support::dispatch;
pub trait Trait: frame_support_test::Trait {}
pub trait Config: frame_support_test::Config {}
pub mod system {
use frame_support::dispatch;
@@ -15,7 +15,7 @@ macro_rules! reserved {
}
frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=frame_support_test {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=frame_support_test {
#[weight = 0]
fn $reserved(_origin) -> dispatch::DispatchResult { unreachable!() }
}
@@ -22,10 +22,10 @@ use frame_support::{
use sp_io::TestExternalities;
use sp_std::result;
pub trait Trait: frame_support_test::Trait {}
pub trait Config: frame_support_test::Config {}
frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=frame_support_test {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=frame_support_test {
#[weight = 0]
#[transactional]
fn value_commits(_origin, v: u32) {
@@ -42,7 +42,7 @@ frame_support::decl_module! {
}
frame_support::decl_storage!{
trait Store for Module<T: Trait> as StorageTransactions {
trait Store for Module<T: Config> as StorageTransactions {
pub Value: u32;
pub Map: map hasher(twox_64_concat) String => u32;
}
@@ -50,14 +50,14 @@ frame_support::decl_storage!{
struct Runtime;
impl frame_support_test::Trait for Runtime {
impl frame_support_test::Config for Runtime {
type Origin = u32;
type BlockNumber = u32;
type PalletInfo = ();
type DbWeight = ();
}
impl Trait for Runtime {}
impl Config for Runtime {}
#[test]
fn storage_transaction_basic_commit() {
+6 -6
View File
@@ -19,7 +19,7 @@ use frame_support::{
codec::{Encode, Decode, EncodeLike}, traits::Get, weights::RuntimeDbWeight,
};
pub trait Trait: 'static + Eq + Clone {
pub trait Config: 'static + Eq + Clone {
type Origin: Into<Result<RawOrigin<Self::AccountId>, Self::Origin>>
+ From<RawOrigin<Self::AccountId>>;
@@ -34,18 +34,18 @@ pub trait Trait: 'static + Eq + Clone {
}
frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {
#[weight = 0]
fn noop(origin) {}
}
}
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
pub fn deposit_event(_event: impl Into<T::Event>) {}
}
frame_support::decl_event!(
pub enum Event<T> where BlockNumber = <T as Trait>::BlockNumber {
pub enum Event<T> where BlockNumber = <T as Config>::BlockNumber {
ExtrinsicSuccess,
ExtrinsicFailed,
Ignore(BlockNumber),
@@ -53,7 +53,7 @@ frame_support::decl_event!(
);
frame_support::decl_error! {
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// Test error documentation
TestError,
/// Error documentation
@@ -79,7 +79,7 @@ impl<AccountId> From<Option<AccountId>> for RawOrigin<AccountId> {
}
}
pub type Origin<T> = RawOrigin<<T as Trait>::AccountId>;
pub type Origin<T> = RawOrigin<<T as Config>::AccountId>;
#[allow(dead_code)]
pub fn ensure_root<OuterOrigin, AccountId>(o: OuterOrigin) -> Result<(), &'static str>