Skip to content

Commit

Permalink
Add tests for ownership pallet
Browse files Browse the repository at this point in the history
  • Loading branch information
F3Joule committed Feb 27, 2024
1 parent beb18a6 commit 32518dd
Show file tree
Hide file tree
Showing 5 changed files with 338 additions and 178 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pallets/space-ownership/tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ sp-runtime = { git = 'https://github.com/paritytech/substrate', branch = 'polkad
sp-std = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.40', default-features = false }

[dev-dependencies]
mockall = '0.11.3'
lazy_static = '1.4.0'

sp-core = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.40', default-features = false }
sp-io = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.40', default-features = false }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false }
Expand Down
41 changes: 36 additions & 5 deletions pallets/space-ownership/tests/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@
// Full license is available at https://github.com/dappforce/subsocial-parachain/blob/main/LICENSE

use frame_support::{pallet_prelude::ConstU32, parameter_types, traits::Everything};
use lazy_static::lazy_static;
use mockall::mock;
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
};
use sp_std::convert::{TryFrom, TryInto};
use sp_std::{
convert::{TryFrom, TryInto},
sync::{Mutex, MutexGuard},
};

use subsocial_support::{traits::CreatorStakingProvider, SpaceId};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
Expand All @@ -28,7 +35,7 @@ frame_support::construct_runtime!(
Roles: pallet_roles,
Profiles: pallet_profiles,
SpaceFollows: pallet_space_follows,
SpaceOwnership: pallet_ownership,
Ownership: pallet_ownership,
Spaces: pallet_spaces,
Domains: pallet_domains,
Posts: pallet_posts,
Expand All @@ -41,6 +48,29 @@ pub(super) type BlockNumber = u64;

pub(crate) const DOMAIN_DEPOSIT: Balance = 10;

// Mocks

// CreatorStakingProvider
mock! {
// This will generate MockSpaces
pub CreatorStaking {}
impl CreatorStakingProvider<AccountId> for CreatorStaking {
fn is_creator_active(creator_id: SpaceId) -> bool;
}
}

lazy_static! {
static ref MTX: Mutex<()> = Mutex::new(());
}

// mockall crate requires synchronized access for the mocking of static methods.
pub(super) fn use_static_mock() -> MutexGuard<'static, ()> {
match MTX.lock() {
Ok(guard) => guard,
Err(poisoned) => poisoned.into_inner(),
}
}

parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const SS58Prefix: u8 = 42;
Expand Down Expand Up @@ -148,18 +178,19 @@ impl pallet_posts::Config for Test {
}

parameter_types! {
pub const MaxDomainLength: u32 = 64;
pub const BaseDomainDeposit: Balance = DOMAIN_DEPOSIT;
pub const OuterValueByteDeposit: Balance = 5;
pub const RegistrationPeriodLimit: BlockNumber = 5;
pub const InitialPaymentBeneficiary: AccountId = 1;
pub InitialPricesConfig: pallet_domains::types::PricesConfigVec<Test> = Vec::new();
pub InitialPricesConfig: pallet_domains::types::PricesConfigVec<Test> = vec![(1, 100)];
}

impl pallet_domains::Config for Test {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type MinDomainLength = ConstU32<1>;
type MaxDomainLength = ConstU32<64>;
type MaxDomainLength = MaxDomainLength;
type MaxDomainsPerAccount = ConstU32<5>;
type DomainsInsertLimit = ConstU32<5>;
type RegistrationPeriodLimit = RegistrationPeriodLimit;
Expand All @@ -176,7 +207,7 @@ impl pallet_ownership::Config for Test {
type ProfileManager = Profiles;
type SpacesInterface = Spaces;
type SpacePermissionsProvider = Spaces;
type CreatorStakingProvider = ();
type CreatorStakingProvider = MockCreatorStaking;
type DomainsProvider = Domains;
type PostsProvider = Posts;
type WeightInfo = ();
Expand Down
Loading

0 comments on commit 32518dd

Please sign in to comment.