Skip to content
Snippets Groups Projects
Unverified Commit 8d1148be authored by bgallois's avatar bgallois
Browse files

wip: fix all pallets tests

parent d5cbe5f5
No related branches found
No related tags found
No related merge requests found
Pipeline #35439 failed
......@@ -6234,6 +6234,7 @@ dependencies = [
"sp-membership",
"sp-runtime 24.0.0",
"sp-staking",
"sp-state-machine 0.28.0",
"sp-std 8.0.0 (git+https://github.com/bgallois/duniter-polkadot-sdk?branch=duniter-v1.6.0)",
]
......@@ -6459,6 +6460,7 @@ dependencies = [
"sp-io 23.0.0",
"sp-keystore 0.27.0",
"sp-runtime 24.0.0",
"sp-state-machine 0.28.0",
"sp-std 8.0.0 (git+https://github.com/bgallois/duniter-polkadot-sdk?branch=duniter-v1.6.0)",
]
......
......@@ -109,3 +109,7 @@ version = '1.0.119'
[dev-dependencies.sp-io]
git = 'https://github.com/bgallois/duniter-polkadot-sdk'
branch = 'duniter-v1.6.0'
[dev-dependencies.sp-state-machine]
git = 'https://github.com/bgallois/duniter-polkadot-sdk'
branch = 'duniter-v1.6.0'
......@@ -16,28 +16,24 @@
use super::*;
use crate::{self as pallet_authority_members};
use frame_support::{
pallet_prelude::*,
parameter_types,
traits::{Everything, GenesisBuild},
BasicExternalities,
};
use frame_support::{pallet_prelude::*, parameter_types, traits::Everything};
use frame_system as system;
use pallet_offences::traits::OnOffenceHandler;
use pallet_offences::SlashStrategy;
use pallet_session::ShouldEndSession;
use sp_core::{crypto::key_types::DUMMY, H256};
use sp_runtime::BuildStorage;
use sp_runtime::{
impl_opaque_keys,
testing::{Header, UintAuthorityId},
testing::UintAuthorityId,
traits::{BlakeTwo256, ConvertInto, IdentityLookup, IsMember, OpaqueKeys},
KeyTypeId,
};
use sp_staking::offence::OffenceDetails;
use sp_state_machine::BasicExternalities;
type AccountId = u64;
type Block = frame_system::mocking::MockBlock<Test>;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
impl_opaque_keys! {
pub struct MockSessionKeys {
......@@ -53,14 +49,11 @@ impl From<UintAuthorityId> for MockSessionKeys {
// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Session: pallet_session::{Pallet, Call, Storage, Config<T>, Event},
AuthorityMembers: pallet_authority_members::{Pallet, Call, Storage, Config<T>, Event<T>},
System: frame_system,
Session: pallet_session,
AuthorityMembers: pallet_authority_members,
}
);
......@@ -73,16 +66,14 @@ impl system::Config for Test {
type BaseCallFilter = Everything;
type BlockWeights = ();
type BlockLength = ();
type Block = Block;
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = ();
......@@ -94,6 +85,8 @@ impl system::Config for Test {
type SS58Prefix = SS58Prefix;
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
type RuntimeTask = ();
type Nonce = u64;
}
pub struct TestSessionHandler;
......@@ -172,10 +165,10 @@ pub fn new_test_ext(initial_authorities_len: u64) -> sp_io::TestExternalities {
.map(|i| (i * 3, i * 3, UintAuthorityId(i * 3).into()))
.collect();
let mut t = frame_system::GenesisConfig::default()
.build_storage::<Test>()
let mut t = frame_system::GenesisConfig::<Test>::default()
.build_storage()
.unwrap();
BasicExternalities::execute_with_storage(&mut t, || {
BasicExternalities::build_storage(&mut t, || {
for (ref k, ..) in &keys {
frame_system::Pallet::<Test>::inc_providers(k);
}
......
......@@ -22,26 +22,19 @@ use frame_support::{
use frame_system as system;
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};
type AccountId = u64;
type BlockNumber = u64;
type Block = frame_system::mocking::MockBlock<Test>;
pub type IdtyIndex = u64;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
DefaultCertification: pallet_certification::{Pallet, Call, Event<T>, Storage, Config<T>},
pub enum Test {
System: frame_system,
DefaultCertification: pallet_certification,
}
);
......@@ -54,16 +47,14 @@ impl system::Config for Test {
type BaseCallFilter = Everything;
type BlockWeights = ();
type BlockLength = ();
type Block = Block;
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = BlockNumber;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = ();
......@@ -75,6 +66,8 @@ impl system::Config for Test {
type SS58Prefix = SS58Prefix;
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
type RuntimeTask = ();
type Nonce = u64;
}
parameter_types! {
......@@ -102,7 +95,7 @@ impl pallet_certification::Config for Test {
pub fn new_test_ext(
gen_conf: pallet_certification::GenesisConfig<Test>,
) -> sp_io::TestExternalities {
GenesisConfig {
RuntimeGenesisConfig {
system: SystemConfig::default(),
default_certification: gen_conf,
}
......
......@@ -19,23 +19,23 @@ use crate::{self as pallet_distance};
use core::marker::PhantomData;
use frame_support::{
parameter_types,
traits::{Everything, GenesisBuild, OnFinalize, OnInitialize},
traits::{Everything, OnFinalize, OnInitialize},
};
use frame_system as system;
use pallet_balances::AccountData;
use pallet_session::ShouldEndSession;
use sp_core::{ConstU32, H256};
use sp_runtime::BuildStorage;
use sp_runtime::{
impl_opaque_keys,
key_types::DUMMY,
testing::{Header, TestSignature, UintAuthorityId},
testing::{TestSignature, UintAuthorityId},
traits::{BlakeTwo256, ConvertInto, IdentityLookup, IsMember, OpaqueKeys},
KeyTypeId, Perbill,
};
type Balance = u64;
type Block = frame_system::mocking::MockBlock<Test>;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
pub type AccountId = u64;
impl_opaque_keys! {
......@@ -52,18 +52,14 @@ impl From<UintAuthorityId> for MockSessionKeys {
// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Session: pallet_session::{Pallet, Call, Storage, Config<T>, Event},
Authorship: pallet_authorship::{Pallet, Storage},
AuthorityMembers: pallet_authority_members::{Pallet, Call, Storage, Config<T>, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Identity: pallet_identity::{Pallet, Call, Storage, Config<T>, Event<T>},
Distance: pallet_distance::{Pallet, Call, Storage, Event<T>},
pub enum Test {
System: frame_system,
Session: pallet_session,
Authorship: pallet_authorship,
AuthorityMembers: pallet_authority_members,
Balances: pallet_balances,
Identity: pallet_identity,
Distance: pallet_distance,
}
);
......@@ -76,16 +72,14 @@ impl system::Config for Test {
type BaseCallFilter = Everything;
type BlockWeights = ();
type BlockLength = ();
type Block = Block;
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = ();
......@@ -97,6 +91,8 @@ impl system::Config for Test {
type SS58Prefix = SS58Prefix;
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
type RuntimeTask = ();
type Nonce = u64;
}
pub struct TestSessionHandler;
......@@ -207,10 +203,11 @@ impl pallet_balances::Config for Test {
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type RuntimeEvent = RuntimeEvent;
type HoldIdentifier = ();
type FreezeIdentifier = ();
type MaxHolds = ConstU32<0>;
type MaxFreezes = ConstU32<0>;
type RuntimeHoldReason = ();
type RuntimeFreezeReason = ();
}
parameter_types! {
......@@ -265,8 +262,8 @@ impl pallet_distance::Config for Test {
// Build genesis storage according to the mock runtime.
#[allow(dead_code)] // ??? Clippy triggers dead code for new_test_ext while it is used during test benchmark
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default()
.build_storage::<Test>()
let mut t = frame_system::GenesisConfig::<Test>::default()
.build_storage()
.unwrap();
pub const NAMES: [&str; 6] = ["Alice", "Bob", "Charlie", "Dave", "Eve", "Ferdie"];
......
......@@ -20,6 +20,7 @@ std = [
'frame-system/std',
'frame-benchmarking/std',
'pallet-balances/std',
'pallet-identity/std',
'pallet-provide-randomness/std',
'pallet-treasury/std',
'serde',
......@@ -117,4 +118,4 @@ version = '1.0.119'
[dev-dependencies.sp-io]
git = 'https://github.com/bgallois/duniter-polkadot-sdk'
branch = 'duniter-v1.6.0'
\ No newline at end of file
branch = 'duniter-v1.6.0'
......@@ -77,3 +77,4 @@ branch = 'duniter-v1.6.0'
serde = { version = "1", features = ["derive"] }
sp-io = { git = 'https://github.com/bgallois/duniter-polkadot-sdk', branch = 'duniter-v1.6.0' }
sp-keystore = { git = 'https://github.com/bgallois/duniter-polkadot-sdk', branch = 'duniter-v1.6.0' }
sp-state-machine = { git = 'https://github.com/bgallois/duniter-polkadot-sdk', branch = 'duniter-v1.6.0' }
......@@ -18,20 +18,20 @@ use super::*;
use crate::{self as pallet_identity};
use frame_support::{
parameter_types,
traits::{Everything, GenesisBuild, OnFinalize, OnInitialize},
traits::{Everything, OnFinalize, OnInitialize},
};
use frame_system as system;
use sp_core::{Pair, H256};
use sp_keystore::{testing::MemoryKeystore, KeystoreExt};
use sp_runtime::BuildStorage;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
MultiSignature, MultiSigner,
};
use sp_state_machine::BasicExternalities;
use std::sync::Arc;
type Block = frame_system::mocking::MockBlock<Test>;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
pub type Signature = MultiSignature;
pub type AccountPublic = <Signature as Verify>::Signer;
pub type AccountId = <AccountPublic as IdentifyAccount>::AccountId;
......@@ -43,13 +43,10 @@ fn account(id: u8) -> AccountId {
// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Identity: pallet_identity::{Pallet, Call, Storage, Config<T>, Event<T>},
System: frame_system,
Identity: pallet_identity,
}
);
......@@ -63,15 +60,13 @@ impl system::Config for Test {
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Block = Block;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = ();
......@@ -83,6 +78,8 @@ impl system::Config for Test {
type SS58Prefix = SS58Prefix;
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
type RuntimeTask = ();
type Nonce = u64;
}
parameter_types! {
......@@ -122,13 +119,13 @@ impl pallet_identity::Config for Test {
// Build genesis storage according to the mock runtime.
pub fn new_test_ext(gen_conf: pallet_identity::GenesisConfig<Test>) -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default()
.build_storage::<Test>()
let mut t = frame_system::GenesisConfig::<Test>::default()
.build_storage()
.unwrap();
gen_conf.assimilate_storage(&mut t).unwrap();
frame_support::BasicExternalities::execute_with_storage(&mut t, || {
BasicExternalities::execute_with_storage(&mut t, || {
frame_system::Pallet::<Test>::inc_providers(&account(2));
frame_system::Pallet::<Test>::inc_providers(&account(3));
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment