frame-support-test: migrate tests from decl_* macros to the new pallet macros (#12445)

* frame-support: migrate some tests from decl macros to new pallet attribute macros

* Remove useless type alias

* Remove useless type alias

* frame-support-test: migrate old decl_macros to new pallet attribute macros

* fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix features

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove deprecated stuff

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update UI tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix UI test

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix test

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update UI tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Cleanup

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: parity-processbot <>
This commit is contained in:
Qinxuan Chen
2023-05-09 17:22:55 +08:00
committed by GitHub
parent 1d42bdf664
commit dcc0858f67
41 changed files with 1139 additions and 2988 deletions
@@ -15,30 +15,86 @@
// See the License for the specific language governing permissions and
// limitations under the License.
pub trait Config: frame_support_test::Config {}
use sp_core::sr25519;
use sp_runtime::{
generic,
traits::{BlakeTwo256, Verify},
};
frame_support::decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, system=frame_support_test {}
}
#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_support_test as frame_system;
frame_support::decl_storage! {
trait Store for Module<T: Config> as Test {
pub AppendableDM config(t): double_map hasher(identity) u32, hasher(identity) T::BlockNumber => Vec<u32>;
#[pallet::pallet]
pub struct Pallet<T>(PhantomData<T>);
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::storage]
#[pallet::unbounded]
pub type AppendableDM<T: Config> =
StorageDoubleMap<_, Identity, u32, Identity, T::BlockNumber, Vec<u32>>;
#[pallet::genesis_config]
pub struct GenesisConfig<T: Config> {
pub t: Vec<(u32, T::BlockNumber, Vec<u32>)>,
}
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
Self { t: Default::default() }
}
}
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
fn build(&self) {
for (k1, k2, v) in &self.t {
<AppendableDM<T>>::insert(k1, k2, v);
}
}
}
}
struct Test;
pub type BlockNumber = u32;
pub type Signature = sr25519::Signature;
pub type AccountId = <Signature as Verify>::Signer;
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<u32, RuntimeCall, Signature, ()>;
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
frame_support::construct_runtime!(
pub enum Test
where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_support_test,
MyPallet: pallet,
}
);
impl frame_support_test::Config for Test {
type BlockNumber = u32;
type RuntimeOrigin = ();
type PalletInfo = frame_support_test::PanicPalletInfo;
type BlockNumber = BlockNumber;
type AccountId = AccountId;
type BaseCallFilter = frame_support::traits::Everything;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type PalletInfo = PalletInfo;
type DbWeight = ();
}
impl Config for Test {}
impl pallet::Config for Test {}
#[test]
fn init_genesis_config() {
GenesisConfig::<Test>::default();
pallet::GenesisConfig::<Test>::default();
}