Replace parameter_types with ConstU32 &c. (#10402)

* remove parameter types and use const type

* remove parameter types and use const type

* Delete {

* Delete count,

* refractor for beefy, benchmarking, child bounties, and collective pallets

* refractor for pallet contracts

* refractor for elections

* refractor for more pallets

* fix CI issues

* fix CI issues

* fix CI issues

* fix CI issues

* remove warning to fix CI issue

* remove warning to fix CI issue
refractor for pallet preimage

* remove warning to fix CI issue
refractor for pallet proxy

* remove warning to fix CI issue
refractor for pallet recovery
refractor for pallet randomness-collective-flip

* remove warning to fix CI issue
refractor for pallet scored-pool
refractor for pallet scheduler
refractor for pallet session

* remove warning to fix CI issue
refractor for pallet society, support, system, timestamp, tips

* remove warning to fix CI issue
refractor for pallet transaction_payment, transaction_storage, treasury, uniques, utility

* remove warning to fix CI issue

* cargo +nightly fmt

* CI fix

* more param refractor on beefy-mmr

* refractor for beefy

* Update frame/babe/src/mock.rs

* Update frame/babe/src/mock.rs

* Update frame/bounties/src/tests.rs

* Update frame/tips/src/tests.rs

* Delete mock.rs

* Update frame/examples/basic/src/tests.rs

* Apply suggestions from code review

* Update frame/im-online/src/mock.rs

* Update frame/im-online/src/mock.rs

* Update frame/offences/benchmarking/src/mock.rs

* Update frame/session/benchmarking/src/mock.rs

* Update frame/support/test/tests/pallet_compatibility.rs

* Update frame/support/test/tests/pallet_compatibility_instance.rs

* Update frame/treasury/src/tests.rs

* Update test-utils/runtime/src/lib.rs

* some cleanup

* fmt

* remove unused

Co-authored-by: Damilare <dakinlose@teamapt.com>
Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
dharjeezy
2021-12-16 04:06:11 +01:00
committed by GitHub
parent cf1eb73046
commit 1b0be8ae06
76 changed files with 629 additions and 966 deletions
@@ -306,18 +306,14 @@ impl<K, V, S> codec::EncodeLike<BTreeMap<K, V>> for BoundedBTreeMap<K, V, S> whe
pub mod test {
use super::*;
use crate::Twox128;
use frame_support::traits::ConstU32;
use sp_io::TestExternalities;
crate::parameter_types! {
pub const Seven: u32 = 7;
pub const Four: u32 = 4;
}
crate::generate_storage_alias! { Prefix, Foo => Value<BoundedBTreeMap<u32, (), Seven>> }
crate::generate_storage_alias! { Prefix, FooMap => Map<(u32, Twox128), BoundedBTreeMap<u32, (), Seven>> }
crate::generate_storage_alias! { Prefix, Foo => Value<BoundedBTreeMap<u32, (), ConstU32<7>>> }
crate::generate_storage_alias! { Prefix, FooMap => Map<(u32, Twox128), BoundedBTreeMap<u32, (), ConstU32<7>>> }
crate::generate_storage_alias! {
Prefix,
FooDoubleMap => DoubleMap<(u32, Twox128), (u32, Twox128), BoundedBTreeMap<u32, (), Seven>>
FooDoubleMap => DoubleMap<(u32, Twox128), (u32, Twox128), BoundedBTreeMap<u32, (), ConstU32<7>>>
}
fn map_from_keys<K>(keys: &[K]) -> BTreeMap<K, ()>
@@ -338,13 +334,13 @@ pub mod test {
#[test]
fn decode_len_works() {
TestExternalities::default().execute_with(|| {
let bounded = boundedmap_from_keys::<u32, Seven>(&[1, 2, 3]);
let bounded = boundedmap_from_keys::<u32, ConstU32<7>>(&[1, 2, 3]);
Foo::put(bounded);
assert_eq!(Foo::decode_len().unwrap(), 3);
});
TestExternalities::default().execute_with(|| {
let bounded = boundedmap_from_keys::<u32, Seven>(&[1, 2, 3]);
let bounded = boundedmap_from_keys::<u32, ConstU32<7>>(&[1, 2, 3]);
FooMap::insert(1, bounded);
assert_eq!(FooMap::decode_len(1).unwrap(), 3);
assert!(FooMap::decode_len(0).is_none());
@@ -352,7 +348,7 @@ pub mod test {
});
TestExternalities::default().execute_with(|| {
let bounded = boundedmap_from_keys::<u32, Seven>(&[1, 2, 3]);
let bounded = boundedmap_from_keys::<u32, ConstU32<7>>(&[1, 2, 3]);
FooDoubleMap::insert(1, 1, bounded);
assert_eq!(FooDoubleMap::decode_len(1, 1).unwrap(), 3);
assert!(FooDoubleMap::decode_len(2, 1).is_none());
@@ -363,7 +359,7 @@ pub mod test {
#[test]
fn try_insert_works() {
let mut bounded = boundedmap_from_keys::<u32, Four>(&[1, 2, 3]);
let mut bounded = boundedmap_from_keys::<u32, ConstU32<4>>(&[1, 2, 3]);
bounded.try_insert(0, ()).unwrap();
assert_eq!(*bounded, map_from_keys(&[1, 0, 2, 3]));
@@ -373,7 +369,7 @@ pub mod test {
#[test]
fn deref_coercion_works() {
let bounded = boundedmap_from_keys::<u32, Seven>(&[1, 2, 3]);
let bounded = boundedmap_from_keys::<u32, ConstU32<7>>(&[1, 2, 3]);
// these methods come from deref-ed vec.
assert_eq!(bounded.len(), 3);
assert!(bounded.iter().next().is_some());
@@ -382,7 +378,7 @@ pub mod test {
#[test]
fn try_mutate_works() {
let bounded = boundedmap_from_keys::<u32, Seven>(&[1, 2, 3, 4, 5, 6]);
let bounded = boundedmap_from_keys::<u32, ConstU32<7>>(&[1, 2, 3, 4, 5, 6]);
let bounded = bounded
.try_mutate(|v| {
v.insert(7, ());
@@ -398,7 +394,7 @@ pub mod test {
#[test]
fn btree_map_eq_works() {
let bounded = boundedmap_from_keys::<u32, Seven>(&[1, 2, 3, 4, 5, 6]);
let bounded = boundedmap_from_keys::<u32, ConstU32<7>>(&[1, 2, 3, 4, 5, 6]);
assert_eq!(bounded, map_from_keys(&[1, 2, 3, 4, 5, 6]));
}
@@ -406,7 +402,7 @@ pub mod test {
fn too_big_fail_to_decode() {
let v: Vec<(u32, u32)> = vec![(1, 1), (2, 2), (3, 3), (4, 4), (5, 5)];
assert_eq!(
BoundedBTreeMap::<u32, u32, Four>::decode(&mut &v.encode()[..]),
BoundedBTreeMap::<u32, u32, ConstU32<4>>::decode(&mut &v.encode()[..]),
Err("BoundedBTreeMap exceeds its limit".into()),
);
}
@@ -436,7 +432,7 @@ pub mod test {
}
}
let mut map = BoundedBTreeMap::<Unequal, u32, Four>::new();
let mut map = BoundedBTreeMap::<Unequal, u32, ConstU32<4>>::new();
// when the set is full
@@ -287,19 +287,15 @@ impl<T, S> codec::EncodeLike<BTreeSet<T>> for BoundedBTreeSet<T, S> where BTreeS
pub mod test {
use super::*;
use crate::Twox128;
use frame_support::traits::ConstU32;
use sp_io::TestExternalities;
use sp_std::convert::TryInto;
crate::parameter_types! {
pub const Seven: u32 = 7;
pub const Four: u32 = 4;
}
crate::generate_storage_alias! { Prefix, Foo => Value<BoundedBTreeSet<u32, Seven>> }
crate::generate_storage_alias! { Prefix, FooMap => Map<(u32, Twox128), BoundedBTreeSet<u32, Seven>> }
crate::generate_storage_alias! { Prefix, Foo => Value<BoundedBTreeSet<u32, ConstU32<7>>> }
crate::generate_storage_alias! { Prefix, FooMap => Map<(u32, Twox128), BoundedBTreeSet<u32, ConstU32<7>>> }
crate::generate_storage_alias! {
Prefix,
FooDoubleMap => DoubleMap<(u32, Twox128), (u32, Twox128), BoundedBTreeSet<u32, Seven>>
FooDoubleMap => DoubleMap<(u32, Twox128), (u32, Twox128), BoundedBTreeSet<u32, ConstU32<7>>>
}
fn map_from_keys<T>(keys: &[T]) -> BTreeSet<T>
@@ -320,13 +316,13 @@ pub mod test {
#[test]
fn decode_len_works() {
TestExternalities::default().execute_with(|| {
let bounded = boundedmap_from_keys::<u32, Seven>(&[1, 2, 3]);
let bounded = boundedmap_from_keys::<u32, ConstU32<7>>(&[1, 2, 3]);
Foo::put(bounded);
assert_eq!(Foo::decode_len().unwrap(), 3);
});
TestExternalities::default().execute_with(|| {
let bounded = boundedmap_from_keys::<u32, Seven>(&[1, 2, 3]);
let bounded = boundedmap_from_keys::<u32, ConstU32<7>>(&[1, 2, 3]);
FooMap::insert(1, bounded);
assert_eq!(FooMap::decode_len(1).unwrap(), 3);
assert!(FooMap::decode_len(0).is_none());
@@ -334,7 +330,7 @@ pub mod test {
});
TestExternalities::default().execute_with(|| {
let bounded = boundedmap_from_keys::<u32, Seven>(&[1, 2, 3]);
let bounded = boundedmap_from_keys::<u32, ConstU32<7>>(&[1, 2, 3]);
FooDoubleMap::insert(1, 1, bounded);
assert_eq!(FooDoubleMap::decode_len(1, 1).unwrap(), 3);
assert!(FooDoubleMap::decode_len(2, 1).is_none());
@@ -345,7 +341,7 @@ pub mod test {
#[test]
fn try_insert_works() {
let mut bounded = boundedmap_from_keys::<u32, Four>(&[1, 2, 3]);
let mut bounded = boundedmap_from_keys::<u32, ConstU32<4>>(&[1, 2, 3]);
bounded.try_insert(0).unwrap();
assert_eq!(*bounded, map_from_keys(&[1, 0, 2, 3]));
@@ -355,7 +351,7 @@ pub mod test {
#[test]
fn deref_coercion_works() {
let bounded = boundedmap_from_keys::<u32, Seven>(&[1, 2, 3]);
let bounded = boundedmap_from_keys::<u32, ConstU32<7>>(&[1, 2, 3]);
// these methods come from deref-ed vec.
assert_eq!(bounded.len(), 3);
assert!(bounded.iter().next().is_some());
@@ -364,7 +360,7 @@ pub mod test {
#[test]
fn try_mutate_works() {
let bounded = boundedmap_from_keys::<u32, Seven>(&[1, 2, 3, 4, 5, 6]);
let bounded = boundedmap_from_keys::<u32, ConstU32<7>>(&[1, 2, 3, 4, 5, 6]);
let bounded = bounded
.try_mutate(|v| {
v.insert(7);
@@ -380,7 +376,7 @@ pub mod test {
#[test]
fn btree_map_eq_works() {
let bounded = boundedmap_from_keys::<u32, Seven>(&[1, 2, 3, 4, 5, 6]);
let bounded = boundedmap_from_keys::<u32, ConstU32<7>>(&[1, 2, 3, 4, 5, 6]);
assert_eq!(bounded, map_from_keys(&[1, 2, 3, 4, 5, 6]));
}
@@ -388,7 +384,7 @@ pub mod test {
fn too_big_fail_to_decode() {
let v: Vec<u32> = vec![1, 2, 3, 4, 5];
assert_eq!(
BoundedBTreeSet::<u32, Four>::decode(&mut &v.encode()[..]),
BoundedBTreeSet::<u32, ConstU32<4>>::decode(&mut &v.encode()[..]),
Err("BoundedBTreeSet exceeds its limit".into()),
);
}
@@ -418,7 +414,7 @@ pub mod test {
}
}
let mut set = BoundedBTreeSet::<Unequal, Four>::new();
let mut set = BoundedBTreeSet::<Unequal, ConstU32<4>>::new();
// when the set is full
@@ -348,35 +348,31 @@ where
pub mod test {
use super::*;
use crate::Twox128;
use frame_support::traits::ConstU32;
use sp_io::TestExternalities;
crate::parameter_types! {
pub const Seven: u32 = 7;
pub const Four: u32 = 4;
}
crate::generate_storage_alias! { Prefix, Foo => Value<BoundedVec<u32, Seven>> }
crate::generate_storage_alias! { Prefix, FooMap => Map<(u32, Twox128), BoundedVec<u32, Seven>> }
crate::generate_storage_alias! { Prefix, Foo => Value<BoundedVec<u32, ConstU32<7>>> }
crate::generate_storage_alias! { Prefix, FooMap => Map<(u32, Twox128), BoundedVec<u32, ConstU32<7>>> }
crate::generate_storage_alias! {
Prefix,
FooDoubleMap => DoubleMap<(u32, Twox128), (u32, Twox128), BoundedVec<u32, Seven>>
FooDoubleMap => DoubleMap<(u32, Twox128), (u32, Twox128), BoundedVec<u32, ConstU32<7>>>
}
#[test]
fn try_append_is_correct() {
assert_eq!(BoundedVec::<u32, Seven>::bound(), 7);
assert_eq!(BoundedVec::<u32, ConstU32<7>>::bound(), 7);
}
#[test]
fn decode_len_works() {
TestExternalities::default().execute_with(|| {
let bounded: BoundedVec<u32, Seven> = vec![1, 2, 3].try_into().unwrap();
let bounded: BoundedVec<u32, ConstU32<7>> = vec![1, 2, 3].try_into().unwrap();
Foo::put(bounded);
assert_eq!(Foo::decode_len().unwrap(), 3);
});
TestExternalities::default().execute_with(|| {
let bounded: BoundedVec<u32, Seven> = vec![1, 2, 3].try_into().unwrap();
let bounded: BoundedVec<u32, ConstU32<7>> = vec![1, 2, 3].try_into().unwrap();
FooMap::insert(1, bounded);
assert_eq!(FooMap::decode_len(1).unwrap(), 3);
assert!(FooMap::decode_len(0).is_none());
@@ -384,7 +380,7 @@ pub mod test {
});
TestExternalities::default().execute_with(|| {
let bounded: BoundedVec<u32, Seven> = vec![1, 2, 3].try_into().unwrap();
let bounded: BoundedVec<u32, ConstU32<7>> = vec![1, 2, 3].try_into().unwrap();
FooDoubleMap::insert(1, 1, bounded);
assert_eq!(FooDoubleMap::decode_len(1, 1).unwrap(), 3);
assert!(FooDoubleMap::decode_len(2, 1).is_none());
@@ -395,7 +391,7 @@ pub mod test {
#[test]
fn try_insert_works() {
let mut bounded: BoundedVec<u32, Four> = vec![1, 2, 3].try_into().unwrap();
let mut bounded: BoundedVec<u32, ConstU32<4>> = vec![1, 2, 3].try_into().unwrap();
bounded.try_insert(1, 0).unwrap();
assert_eq!(*bounded, vec![1, 0, 2, 3]);
@@ -406,13 +402,13 @@ pub mod test {
#[test]
#[should_panic(expected = "insertion index (is 9) should be <= len (is 3)")]
fn try_inert_panics_if_oob() {
let mut bounded: BoundedVec<u32, Four> = vec![1, 2, 3].try_into().unwrap();
let mut bounded: BoundedVec<u32, ConstU32<4>> = vec![1, 2, 3].try_into().unwrap();
bounded.try_insert(9, 0).unwrap();
}
#[test]
fn try_push_works() {
let mut bounded: BoundedVec<u32, Four> = vec![1, 2, 3].try_into().unwrap();
let mut bounded: BoundedVec<u32, ConstU32<4>> = vec![1, 2, 3].try_into().unwrap();
bounded.try_push(0).unwrap();
assert_eq!(*bounded, vec![1, 2, 3, 0]);
@@ -421,7 +417,7 @@ pub mod test {
#[test]
fn deref_coercion_works() {
let bounded: BoundedVec<u32, Seven> = vec![1, 2, 3].try_into().unwrap();
let bounded: BoundedVec<u32, ConstU32<7>> = vec![1, 2, 3].try_into().unwrap();
// these methods come from deref-ed vec.
assert_eq!(bounded.len(), 3);
assert!(bounded.iter().next().is_some());
@@ -430,7 +426,7 @@ pub mod test {
#[test]
fn try_mutate_works() {
let bounded: BoundedVec<u32, Seven> = vec![1, 2, 3, 4, 5, 6].try_into().unwrap();
let bounded: BoundedVec<u32, ConstU32<7>> = vec![1, 2, 3, 4, 5, 6].try_into().unwrap();
let bounded = bounded.try_mutate(|v| v.push(7)).unwrap();
assert_eq!(bounded.len(), 7);
assert!(bounded.try_mutate(|v| v.push(8)).is_none());
@@ -438,13 +434,13 @@ pub mod test {
#[test]
fn slice_indexing_works() {
let bounded: BoundedVec<u32, Seven> = vec![1, 2, 3, 4, 5, 6].try_into().unwrap();
let bounded: BoundedVec<u32, ConstU32<7>> = vec![1, 2, 3, 4, 5, 6].try_into().unwrap();
assert_eq!(&bounded[0..=2], &[1, 2, 3]);
}
#[test]
fn vec_eq_works() {
let bounded: BoundedVec<u32, Seven> = vec![1, 2, 3, 4, 5, 6].try_into().unwrap();
let bounded: BoundedVec<u32, ConstU32<7>> = vec![1, 2, 3, 4, 5, 6].try_into().unwrap();
assert_eq!(bounded, vec![1, 2, 3, 4, 5, 6]);
}
@@ -452,7 +448,7 @@ pub mod test {
fn too_big_vec_fail_to_decode() {
let v: Vec<u32> = vec![1, 2, 3, 4, 5];
assert_eq!(
BoundedVec::<u32, Four>::decode(&mut &v.encode()[..]),
BoundedVec::<u32, ConstU32<4>>::decode(&mut &v.encode()[..]),
Err("BoundedVec exceeds its limit".into()),
);
}
+11 -15
View File
@@ -1404,6 +1404,7 @@ mod test {
use super::*;
use crate::{assert_ok, hash::Identity, Twox128};
use bounded_vec::BoundedVec;
use frame_support::traits::ConstU32;
use generator::StorageValue as _;
use sp_core::hashing::twox_128;
use sp_io::TestExternalities;
@@ -1714,22 +1715,17 @@ mod test {
});
}
crate::parameter_types! {
pub const Seven: u32 = 7;
pub const Four: u32 = 4;
}
crate::generate_storage_alias! { Prefix, Foo => Value<WeakBoundedVec<u32, Seven>> }
crate::generate_storage_alias! { Prefix, FooMap => Map<(u32, Twox128), BoundedVec<u32, Seven>> }
crate::generate_storage_alias! { Prefix, Foo => Value<WeakBoundedVec<u32, ConstU32<7>>> }
crate::generate_storage_alias! { Prefix, FooMap => Map<(u32, Twox128), BoundedVec<u32, ConstU32<7>>> }
crate::generate_storage_alias! {
Prefix,
FooDoubleMap => DoubleMap<(u32, Twox128), (u32, Twox128), BoundedVec<u32, Seven>>
FooDoubleMap => DoubleMap<(u32, Twox128), (u32, Twox128), BoundedVec<u32, ConstU32<7>>>
}
#[test]
fn try_append_works() {
TestExternalities::default().execute_with(|| {
let bounded: WeakBoundedVec<u32, Seven> = vec![1, 2, 3].try_into().unwrap();
let bounded: WeakBoundedVec<u32, ConstU32<7>> = vec![1, 2, 3].try_into().unwrap();
Foo::put(bounded);
assert_ok!(Foo::try_append(4));
assert_ok!(Foo::try_append(5));
@@ -1740,7 +1736,7 @@ mod test {
});
TestExternalities::default().execute_with(|| {
let bounded: BoundedVec<u32, Seven> = vec![1, 2, 3].try_into().unwrap();
let bounded: BoundedVec<u32, ConstU32<7>> = vec![1, 2, 3].try_into().unwrap();
FooMap::insert(1, bounded);
assert_ok!(FooMap::try_append(1, 4));
@@ -1755,17 +1751,17 @@ mod test {
assert_ok!(FooMap::try_append(2, 4));
assert_eq!(
FooMap::get(2).unwrap(),
BoundedVec::<u32, Seven>::try_from(vec![4]).unwrap(),
BoundedVec::<u32, ConstU32<7>>::try_from(vec![4]).unwrap(),
);
assert_ok!(FooMap::try_append(2, 5));
assert_eq!(
FooMap::get(2).unwrap(),
BoundedVec::<u32, Seven>::try_from(vec![4, 5]).unwrap(),
BoundedVec::<u32, ConstU32<7>>::try_from(vec![4, 5]).unwrap(),
);
});
TestExternalities::default().execute_with(|| {
let bounded: BoundedVec<u32, Seven> = vec![1, 2, 3].try_into().unwrap();
let bounded: BoundedVec<u32, ConstU32<7>> = vec![1, 2, 3].try_into().unwrap();
FooDoubleMap::insert(1, 1, bounded);
assert_ok!(FooDoubleMap::try_append(1, 1, 4));
@@ -1780,12 +1776,12 @@ mod test {
assert_ok!(FooDoubleMap::try_append(2, 1, 4));
assert_eq!(
FooDoubleMap::get(2, 1).unwrap(),
BoundedVec::<u32, Seven>::try_from(vec![4]).unwrap(),
BoundedVec::<u32, ConstU32<7>>::try_from(vec![4]).unwrap(),
);
assert_ok!(FooDoubleMap::try_append(2, 1, 5));
assert_eq!(
FooDoubleMap::get(2, 1).unwrap(),
BoundedVec::<u32, Seven>::try_from(vec![4, 5]).unwrap(),
BoundedVec::<u32, ConstU32<7>>::try_from(vec![4, 5]).unwrap(),
);
});
}
@@ -318,36 +318,32 @@ where
pub mod test {
use super::*;
use crate::Twox128;
use frame_support::traits::ConstU32;
use sp_io::TestExternalities;
use sp_std::convert::TryInto;
crate::parameter_types! {
pub const Seven: u32 = 7;
pub const Four: u32 = 4;
}
crate::generate_storage_alias! { Prefix, Foo => Value<WeakBoundedVec<u32, Seven>> }
crate::generate_storage_alias! { Prefix, FooMap => Map<(u32, Twox128), WeakBoundedVec<u32, Seven>> }
crate::generate_storage_alias! { Prefix, Foo => Value<WeakBoundedVec<u32, ConstU32<7>>> }
crate::generate_storage_alias! { Prefix, FooMap => Map<(u32, Twox128), WeakBoundedVec<u32, ConstU32<7>>> }
crate::generate_storage_alias! {
Prefix,
FooDoubleMap => DoubleMap<(u32, Twox128), (u32, Twox128), WeakBoundedVec<u32, Seven>>
FooDoubleMap => DoubleMap<(u32, Twox128), (u32, Twox128), WeakBoundedVec<u32, ConstU32<7>>>
}
#[test]
fn try_append_is_correct() {
assert_eq!(WeakBoundedVec::<u32, Seven>::bound(), 7);
assert_eq!(WeakBoundedVec::<u32, ConstU32<7>>::bound(), 7);
}
#[test]
fn decode_len_works() {
TestExternalities::default().execute_with(|| {
let bounded: WeakBoundedVec<u32, Seven> = vec![1, 2, 3].try_into().unwrap();
let bounded: WeakBoundedVec<u32, ConstU32<7>> = vec![1, 2, 3].try_into().unwrap();
Foo::put(bounded);
assert_eq!(Foo::decode_len().unwrap(), 3);
});
TestExternalities::default().execute_with(|| {
let bounded: WeakBoundedVec<u32, Seven> = vec![1, 2, 3].try_into().unwrap();
let bounded: WeakBoundedVec<u32, ConstU32<7>> = vec![1, 2, 3].try_into().unwrap();
FooMap::insert(1, bounded);
assert_eq!(FooMap::decode_len(1).unwrap(), 3);
assert!(FooMap::decode_len(0).is_none());
@@ -355,7 +351,7 @@ pub mod test {
});
TestExternalities::default().execute_with(|| {
let bounded: WeakBoundedVec<u32, Seven> = vec![1, 2, 3].try_into().unwrap();
let bounded: WeakBoundedVec<u32, ConstU32<7>> = vec![1, 2, 3].try_into().unwrap();
FooDoubleMap::insert(1, 1, bounded);
assert_eq!(FooDoubleMap::decode_len(1, 1).unwrap(), 3);
assert!(FooDoubleMap::decode_len(2, 1).is_none());
@@ -366,7 +362,7 @@ pub mod test {
#[test]
fn try_insert_works() {
let mut bounded: WeakBoundedVec<u32, Four> = vec![1, 2, 3].try_into().unwrap();
let mut bounded: WeakBoundedVec<u32, ConstU32<4>> = vec![1, 2, 3].try_into().unwrap();
bounded.try_insert(1, 0).unwrap();
assert_eq!(*bounded, vec![1, 0, 2, 3]);
@@ -377,13 +373,13 @@ pub mod test {
#[test]
#[should_panic(expected = "insertion index (is 9) should be <= len (is 3)")]
fn try_inert_panics_if_oob() {
let mut bounded: WeakBoundedVec<u32, Four> = vec![1, 2, 3].try_into().unwrap();
let mut bounded: WeakBoundedVec<u32, ConstU32<4>> = vec![1, 2, 3].try_into().unwrap();
bounded.try_insert(9, 0).unwrap();
}
#[test]
fn try_push_works() {
let mut bounded: WeakBoundedVec<u32, Four> = vec![1, 2, 3].try_into().unwrap();
let mut bounded: WeakBoundedVec<u32, ConstU32<4>> = vec![1, 2, 3].try_into().unwrap();
bounded.try_push(0).unwrap();
assert_eq!(*bounded, vec![1, 2, 3, 0]);
@@ -392,7 +388,7 @@ pub mod test {
#[test]
fn deref_coercion_works() {
let bounded: WeakBoundedVec<u32, Seven> = vec![1, 2, 3].try_into().unwrap();
let bounded: WeakBoundedVec<u32, ConstU32<7>> = vec![1, 2, 3].try_into().unwrap();
// these methods come from deref-ed vec.
assert_eq!(bounded.len(), 3);
assert!(bounded.iter().next().is_some());
@@ -401,7 +397,7 @@ pub mod test {
#[test]
fn try_mutate_works() {
let bounded: WeakBoundedVec<u32, Seven> = vec![1, 2, 3, 4, 5, 6].try_into().unwrap();
let bounded: WeakBoundedVec<u32, ConstU32<7>> = vec![1, 2, 3, 4, 5, 6].try_into().unwrap();
let bounded = bounded.try_mutate(|v| v.push(7)).unwrap();
assert_eq!(bounded.len(), 7);
assert!(bounded.try_mutate(|v| v.push(8)).is_none());
@@ -409,20 +405,20 @@ pub mod test {
#[test]
fn slice_indexing_works() {
let bounded: WeakBoundedVec<u32, Seven> = vec![1, 2, 3, 4, 5, 6].try_into().unwrap();
let bounded: WeakBoundedVec<u32, ConstU32<7>> = vec![1, 2, 3, 4, 5, 6].try_into().unwrap();
assert_eq!(&bounded[0..=2], &[1, 2, 3]);
}
#[test]
fn vec_eq_works() {
let bounded: WeakBoundedVec<u32, Seven> = vec![1, 2, 3, 4, 5, 6].try_into().unwrap();
let bounded: WeakBoundedVec<u32, ConstU32<7>> = vec![1, 2, 3, 4, 5, 6].try_into().unwrap();
assert_eq!(bounded, vec![1, 2, 3, 4, 5, 6]);
}
#[test]
fn too_big_succeed_to_decode() {
let v: Vec<u32> = vec![1, 2, 3, 4, 5];
let w = WeakBoundedVec::<u32, Four>::decode(&mut &v.encode()[..]).unwrap();
let w = WeakBoundedVec::<u32, ConstU32<4>>::decode(&mut &v.encode()[..]).unwrap();
assert_eq!(v, *w);
}
}
@@ -22,7 +22,10 @@
//! This crate tests that `construct_runtime!` expands the pallet parts
//! correctly even when frame-support is renamed in Cargo.toml
use frame_support::{construct_runtime, parameter_types};
use frame_support::{
construct_runtime, parameter_types,
traits::{ConstU16, ConstU32},
};
use sp_core::{sr25519, H256};
use sp_runtime::{
create_runtime_str, generic,
@@ -48,7 +51,6 @@ pub type Index = u64;
parameter_types! {
pub const BlockHashCount: BlockNumber = 2400;
pub const Version: RuntimeVersion = VERSION;
pub const SS58Prefix: u8 = 0;
}
impl frame_system::Config for Runtime {
@@ -73,9 +75,9 @@ impl frame_system::Config for Runtime {
type OnNewAccount = ();
type OnKilledAccount = ();
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
type MaxConsumers = ConstU32<16>;
type SystemWeightInfo = ();
type SS58Prefix = SS58Prefix;
type SS58Prefix = ConstU16<0>;
}
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
@@ -24,8 +24,7 @@ use frame_support::{
PalletStorageMetadata, StorageEntryMetadata, StorageEntryModifier, StorageEntryType,
StorageHasher,
},
parameter_types,
traits::Get,
traits::{ConstU32, Get},
Parameter, StorageDoubleMap, StorageMap, StorageValue,
};
use scale_info::TypeInfo;
@@ -229,20 +228,16 @@ mod module3 {
}
}
parameter_types! {
pub const SomeValue: u32 = 100;
}
impl module1::Config<module1::Instance1> for Runtime {
type Event = Event;
type Origin = Origin;
type SomeParameter = SomeValue;
type SomeParameter = ConstU32<100>;
type GenericType = u32;
}
impl module1::Config<module1::Instance2> for Runtime {
type Event = Event;
type Origin = Origin;
type SomeParameter = SomeValue;
type SomeParameter = ConstU32<100>;
type GenericType = u32;
}
impl module2::Config for Runtime {
+6 -9
View File
@@ -19,8 +19,8 @@ use frame_support::{
dispatch::{Parameter, UnfilteredDispatchable},
storage::unhashed,
traits::{
GetCallName, GetStorageVersion, OnFinalize, OnGenesis, OnInitialize, OnRuntimeUpgrade,
PalletInfoAccess, StorageVersion,
ConstU32, GetCallName, GetStorageVersion, OnFinalize, OnGenesis, OnInitialize,
OnRuntimeUpgrade, PalletInfoAccess, StorageVersion,
},
weights::{DispatchClass, DispatchInfo, GetDispatchInfo, Pays, RuntimeDbWeight},
};
@@ -536,10 +536,7 @@ pub mod pallet4 {
}
frame_support::parameter_types!(
pub const MyGetParam: u32 = 10;
pub const MyGetParam2: u32 = 11;
pub const MyGetParam3: u32 = 12;
pub const BlockHashCount: u32 = 250;
);
impl frame_system::Config for Runtime {
@@ -554,7 +551,7 @@ impl frame_system::Config for Runtime {
type Lookup = sp_runtime::traits::IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = Event;
type BlockHashCount = BlockHashCount;
type BlockHashCount = ConstU32<250>;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
@@ -566,12 +563,12 @@ impl frame_system::Config for Runtime {
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
type MaxConsumers = ConstU32<16>;
}
impl pallet::Config for Runtime {
type Event = Event;
type MyGetParam = MyGetParam;
type MyGetParam2 = MyGetParam2;
type MyGetParam = ConstU32<10>;
type MyGetParam2 = ConstU32<11>;
type MyGetParam3 = MyGetParam3;
type Balance = u64;
}
@@ -15,6 +15,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use frame_support::traits::{ConstU32, ConstU64};
pub trait SomeAssociation {
type A: frame_support::dispatch::Parameter + Default;
}
@@ -217,11 +219,6 @@ pub mod pallet {
}
}
frame_support::parameter_types!(
pub const SomeConst: u64 = 10;
pub const BlockHashCount: u32 = 250;
);
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type Origin = Origin;
@@ -234,7 +231,7 @@ impl frame_system::Config for Runtime {
type Lookup = sp_runtime::traits::IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = Event;
type BlockHashCount = BlockHashCount;
type BlockHashCount = ConstU32<250>;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
@@ -246,16 +243,16 @@ impl frame_system::Config for Runtime {
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
type MaxConsumers = ConstU32<16>;
}
impl pallet::Config for Runtime {
type Event = Event;
type SomeConst = SomeConst;
type SomeConst = ConstU64<10>;
type Balance = u64;
}
impl pallet_old::Config for Runtime {
type Event = Event;
type SomeConst = SomeConst;
type SomeConst = ConstU64<10>;
type Balance = u64;
}
@@ -15,6 +15,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use frame_support::traits::{ConstU32, ConstU64};
mod pallet_old {
use frame_support::{
decl_error, decl_event, decl_module, decl_storage, traits::Get, weights::Weight, Parameter,
@@ -197,11 +199,6 @@ pub mod pallet {
}
}
frame_support::parameter_types!(
pub const SomeConst: u64 = 10;
pub const BlockHashCount: u32 = 250;
);
impl frame_system::Config for Runtime {
type BlockWeights = ();
type BlockLength = ();
@@ -217,7 +214,7 @@ impl frame_system::Config for Runtime {
type Lookup = sp_runtime::traits::IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = Event;
type BlockHashCount = BlockHashCount;
type BlockHashCount = ConstU32<250>;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = ();
@@ -226,36 +223,36 @@ impl frame_system::Config for Runtime {
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
type MaxConsumers = ConstU32<16>;
}
impl pallet::Config for Runtime {
type Event = Event;
type SomeConst = SomeConst;
type SomeConst = ConstU64<10>;
type Balance = u64;
}
impl pallet::Config<pallet::Instance2> for Runtime {
type Event = Event;
type SomeConst = SomeConst;
type SomeConst = ConstU64<10>;
type Balance = u64;
}
impl pallet::Config<pallet::Instance3> for Runtime {
type Event = Event;
type SomeConst = SomeConst;
type SomeConst = ConstU64<10>;
type Balance = u64;
}
impl pallet_old::Config for Runtime {
type Event = Event;
type SomeConst = SomeConst;
type SomeConst = ConstU64<10>;
type Balance = u64;
}
impl pallet_old::Config<pallet_old::Instance2> for Runtime {
type Event = Event;
type SomeConst = SomeConst;
type SomeConst = ConstU64<10>;
type Balance = u64;
}
impl pallet_old::Config<pallet_old::Instance3> for Runtime {
type Event = Event;
type SomeConst = SomeConst;
type SomeConst = ConstU64<10>;
type Balance = u64;
}
@@ -18,7 +18,7 @@
use frame_support::{
dispatch::UnfilteredDispatchable,
storage::unhashed,
traits::{GetCallName, OnFinalize, OnGenesis, OnInitialize, OnRuntimeUpgrade},
traits::{ConstU32, GetCallName, OnFinalize, OnGenesis, OnInitialize, OnRuntimeUpgrade},
weights::{DispatchClass, DispatchInfo, GetDispatchInfo, Pays},
};
use sp_io::{
@@ -245,11 +245,6 @@ pub mod pallet2 {
}
}
frame_support::parameter_types!(
pub const MyGetParam: u32 = 10;
pub const BlockHashCount: u32 = 250;
);
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type Origin = Origin;
@@ -262,7 +257,7 @@ impl frame_system::Config for Runtime {
type Lookup = sp_runtime::traits::IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = Event;
type BlockHashCount = BlockHashCount;
type BlockHashCount = ConstU32<250>;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
@@ -274,16 +269,16 @@ impl frame_system::Config for Runtime {
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
type MaxConsumers = ConstU32<16>;
}
impl pallet::Config for Runtime {
type Event = Event;
type MyGetParam = MyGetParam;
type MyGetParam = ConstU32<10>;
type Balance = u64;
}
impl pallet::Config<pallet::Instance1> for Runtime {
type Event = Event;
type MyGetParam = MyGetParam;
type MyGetParam = ConstU32<10>;
type Balance = u64;
}
impl pallet2::Config for Runtime {
@@ -97,7 +97,7 @@ impl<T: Trait> frame_support::inherent::ProvideInherent for Module<T> {
mod tests {
use crate as pallet_test;
use frame_support::parameter_types;
use frame_support::traits::ConstU64;
type SignedExtra = (
frame_system::CheckEra<Runtime>,
@@ -124,10 +124,6 @@ mod tests {
}
);
parameter_types! {
pub const BlockHashCount: u64 = 250;
}
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type Origin = Origin;
@@ -140,7 +136,7 @@ mod tests {
type Lookup = sp_runtime::traits::IdentityLookup<Self::AccountId>;
type Header = TestHeader;
type Event = ();
type BlockHashCount = BlockHashCount;
type BlockHashCount = ConstU64<250>;
type DbWeight = ();
type BlockWeights = ();
type BlockLength = ();