Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pallet setting test cases #1288

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
212 changes: 209 additions & 3 deletions runtime/common/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,15 +413,16 @@ macro_rules! impl_account_migration_tests {
}

#[macro_export]
macro_rules! impl_evm_tests {
macro_rules! impl_ethereum_tests {
() => {
mod evm {
mod ethereum {
// darwinia
use super::mock::*;
// frontier
use pallet_ethereum::PostLogContent;
use pallet_evm_precompile_dispatch::DispatchValidateT;
// substrate
use frame_support::assert_err;
use frame_support::{assert_err, traits::Get};
use sp_core::{H160, U256};
use sp_runtime::{DispatchError, ModuleError};

Expand All @@ -435,10 +436,22 @@ macro_rules! impl_evm_tests {
assert!(base_extrinsic.ref_time() <= min_ethereum_transaction_weight.ref_time());
}

fn ethereum_constants_are_correctly() {
assert_eq!(
<<Runtime as pallet_ethereum::Config>::ExtraDataLength as Get<u32>>::get(),
64
);
assert_eq!(
<Runtime as pallet_ethereum::Config>::PostLogContent::get() as u8,
PostLogContent::BlockAndTxnHashes as u8
);
}

#[test]
fn evm_constants_are_correctly() {
assert_eq!(BlockGasLimit::get(), U256::from(20_000_000));
assert_eq!(WeightPerGas::get().ref_time(), 18750);
assert_eq!(GasLimitPovSizeRatio::get(), 6);
}

#[test]
Expand Down Expand Up @@ -886,3 +899,196 @@ macro_rules! impl_messages_bridge_tests {
}
};
}

#[macro_export]
macro_rules! impl_governance_tests {
() => {
mod governance {
// darwinia
use super::mock::*;
// crates.io
use static_assertions::assert_type_eq_all;
// substrate
use frame_support::traits::{AsEnsureOriginWithArg, Get, IsInVec, NeverEnsureOrigin};

#[test]
fn preimages_setting_correctly() {
// Origins
assert_type_eq_all!(<Runtime as pallet_preimage::Config>::ManagerOrigin, Root);
// Values
assert_eq!(<<Runtime as pallet_preimage::Config>::BaseDeposit as Get<u128>>::get(), 500 * UNIT);
assert_eq!(<<Runtime as pallet_preimage::Config>::ByteDeposit as Get<u128>>::get(), darwinia_deposit(0, 1));
}

#[test]
fn scheduler_setting_correctly() {
// Origins
assert_type_eq_all!(<Runtime as pallet_scheduler::Config>::ScheduleOrigin, Root);
// Values
assert_eq!(<<Runtime as pallet_scheduler::Config>::MaxScheduledPerBlock as Get<u32>>::get(), 50);
}

#[test]
fn democracy_setting_correctly() {
// Origins
assert_type_eq_all!(<Runtime as pallet_democracy::Config>::BlacklistOrigin, Root);
assert_type_eq_all!(<Runtime as pallet_democracy::Config>::CancelProposalOrigin, RootOrAll<TechnicalCollective>);
assert_type_eq_all!(<Runtime as pallet_democracy::Config>::CancellationOrigin, RootOrAtLeastTwoThird<CouncilCollective>);
assert_type_eq_all!(<Runtime as pallet_democracy::Config>::ExternalDefaultOrigin, RootOrAll<CouncilCollective>);
assert_type_eq_all!(<Runtime as pallet_democracy::Config>::ExternalMajorityOrigin, RootOrAtLeastHalf<CouncilCollective>);
assert_type_eq_all!(<Runtime as pallet_democracy::Config>::ExternalOrigin, RootOrAtLeastHalf<CouncilCollective>);
assert_type_eq_all!(<Runtime as pallet_democracy::Config>::FastTrackOrigin, RootOrAtLeastTwoThird<TechnicalCollective>);
assert_type_eq_all!(<Runtime as pallet_democracy::Config>::InstantOrigin, RootOrAll<TechnicalCollective>);
assert_type_eq_all!(<Runtime as pallet_democracy::Config>::VetoOrigin, pallet_collective::EnsureMember<AccountId, TechnicalCollective>);

// Values
assert_eq!(<<Runtime as pallet_democracy::Config>::InstantAllowed as Get<bool>>::get(), true);
assert_eq!(<<Runtime as pallet_democracy::Config>::MaxBlacklisted as Get<u32>>::get(), 100);
assert_eq!(<<Runtime as pallet_democracy::Config>::MaxDeposits as Get<u32>>::get(), 100);
assert_eq!(<<Runtime as pallet_democracy::Config>::MaxProposals as Get<u32>>::get(), 100);
assert_eq!(<<Runtime as pallet_democracy::Config>::MaxVotes as Get<u32>>::get(), 100);
assert_eq!(<<Runtime as pallet_democracy::Config>::MinimumDeposit as Get<u128>>::get(), DARWINIA_PROPOSAL_REQUIREMENT);
}

#[test]
fn council_setting_correctly() {
// Origins
assert_type_eq_all!(<Runtime as pallet_collective::Config<CouncilCollective>>::SetMembersOrigin, Root);
// Values
assert_eq!(<<Runtime as pallet_collective::Config<CouncilCollective>>::MaxMembers as Get<u32>>::get(), 100);
assert_eq!(<<Runtime as pallet_collective::Config<CouncilCollective>>::MaxProposals as Get<u32>>::get(), 100);
}

#[test]
fn technical_setting_correctly() {
// Origins
assert_type_eq_all!(<Runtime as pallet_collective::Config<TechnicalCollective>>::SetMembersOrigin, Root);
// Values
assert_eq!(<<Runtime as pallet_collective::Config<TechnicalCollective>>::MaxMembers as Get<u32>>::get(), 100);
assert_eq!(<<Runtime as pallet_collective::Config<TechnicalCollective>>::MaxProposals as Get<u32>>::get(), 100);
}

#[test]
fn treasury_setting_correctly() {
// Origins
assert_type_eq_all!(<Runtime as pallet_treasury::Config>::ApproveOrigin, Root);
assert_type_eq_all!(<Runtime as pallet_treasury::Config>::RejectOrigin, RootOrAll<CouncilCollective>);
assert_type_eq_all!(<Runtime as pallet_treasury::Config>::SpendOrigin, NeverEnsureOrigin<Balance>);
// Values
assert_eq!(<<Runtime as pallet_treasury::Config>::MaxApprovals as Get<u32>>::get(), 100);
}

#[test]
fn membership_setting_correctly() {
// Origins
assert_type_eq_all!(<Runtime as pallet_membership::Config<pallet_membership::Instance1>>::AddOrigin, Root);
assert_type_eq_all!(<Runtime as pallet_membership::Config<pallet_membership::Instance1>>::MembershipChanged, TechnicalCommittee);
assert_type_eq_all!(<Runtime as pallet_membership::Config<pallet_membership::Instance1>>::MembershipInitialized, TechnicalCommittee);
assert_type_eq_all!(<Runtime as pallet_membership::Config<pallet_membership::Instance1>>::PrimeOrigin, Root);
assert_type_eq_all!(<Runtime as pallet_membership::Config<pallet_membership::Instance1>>::RemoveOrigin, Root);
assert_type_eq_all!(<Runtime as pallet_membership::Config<pallet_membership::Instance1>>::ResetOrigin, Root);
assert_type_eq_all!(<Runtime as pallet_membership::Config<pallet_membership::Instance1>>::SwapOrigin, Root);
// Values
assert_eq!(<<Runtime as pallet_membership::Config<pallet_membership::Instance1>>::MaxMembers as Get<u32>>::get(), COLLECTIVE_MAX_MEMBERS);
}
}
}
}

#[macro_export]
macro_rules! impl_balances_tests {
() => {
mod balances {
// darwinia
use super::mock::*;
// substrate
use frame_support::traits::Get;

#[test]
fn ensure_constants_correctly() {
// the value is 1 under runtime-benchmarks feature
assert_eq!(<Runtime as pallet_balances::Config>::ExistentialDeposit::get(), 1);
assert_eq!(<<Runtime as pallet_balances::Config>::MaxLocks as Get<u32>>::get(), 50);
assert_eq!(
<<Runtime as pallet_balances::Config>::MaxReserves as Get<u32>>::get(),
50
);
}
}
};
}

#[macro_export]
macro_rules! impl_assets_tests {
() => {
mod assets {
// darwinia
use super::mock::*;
// crates.io
use static_assertions::assert_type_eq_all;
// substrate
use frame_support::traits::{AsEnsureOriginWithArg, Get, IsInVec};

#[test]
fn assets_setting_correctly() {
// Origins
assert_type_eq_all!(<Runtime as pallet_assets::Config>::ForceOrigin, Root);
assert_type_eq_all!(
<Runtime as pallet_assets::Config>::CreateOrigin,
AsEnsureOriginWithArg<
frame_system::EnsureSignedBy<IsInVec<Creators>, AccountId>,
>
);

// Values
assert_eq!(
<<Runtime as pallet_assets::Config>::MetadataDepositPerByte as Get<u128>>::get(
),
0
);
// the value is 1 under runtime-benchmarks feature
assert_eq!(
<<Runtime as pallet_assets::Config>::AssetAccountDeposit as Get<u128>>::get(),
1
);
assert_eq!(
<<Runtime as pallet_assets::Config>::MetadataDepositBase as Get<u128>>::get(),
0
);
assert_eq!(
<<Runtime as pallet_assets::Config>::AssetDeposit as Get<u128>>::get(),
0
);
assert_eq!(
<<Runtime as pallet_assets::Config>::RemoveItemsLimit as Get<u32>>::get(),
1000
);
assert_eq!(
<<Runtime as pallet_assets::Config>::StringLimit as Get<u32>>::get(),
50
);
}
}
};
}

#[macro_export]
macro_rules! impl_message_transact_tests {
() => {
mod message_transact {
// darwinia
use super::mock::*;
use darwinia_message_transact::EnsureLcmpEthOrigin;
// crates.io
use static_assertions::assert_type_eq_all;

#[test]
fn ensure_origin_correctly() {
assert_type_eq_all!(
<Runtime as darwinia_message_transact::Config>::LcmpEthOrigin,
EnsureLcmpEthOrigin
);
}
}
};
}
76 changes: 75 additions & 1 deletion runtime/crab/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,80 @@ pub mod mock;

darwinia_common_runtime::impl_weight_tests! {}
darwinia_common_runtime::impl_fee_tests! {}
darwinia_common_runtime::impl_evm_tests! {}
darwinia_common_runtime::impl_ethereum_tests! {}
darwinia_common_runtime::impl_account_migration_tests! {}
darwinia_common_runtime::impl_messages_bridge_tests! {}
darwinia_common_runtime::impl_governance_tests! {}
darwinia_common_runtime::impl_balances_tests! {}
darwinia_common_runtime::impl_assets_tests! {}
darwinia_common_runtime::impl_message_transact_tests! {}

mod specific_setting {
// darwinia
use crate::mock::*;
// substrate
use frame_support::traits::Get;

#[test]
fn precompile_address() {
assert_eq!(
CrabPrecompiles::<Runtime>::used_addresses()
.iter()
.map(|a| a.to_low_u64_be())
.collect::<Vec<u64>>(),
vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 1024, 1025, 1026, 1536, 1537, 2048]
);
}

#[test]
fn democracy_mod() {
assert_eq!(
<<Runtime as pallet_democracy::Config>::CooloffPeriod as Get<u32>>::get(),
7 * DAYS
);
assert_eq!(
<<Runtime as pallet_democracy::Config>::EnactmentPeriod as Get<u32>>::get(),
8 * DAYS
);
assert_eq!(
<<Runtime as pallet_democracy::Config>::FastTrackVotingPeriod as Get<u32>>::get(),
3 * HOURS
);
assert_eq!(
<<Runtime as pallet_democracy::Config>::LaunchPeriod as Get<u32>>::get(),
7 * DAYS
);
assert_eq!(
<<Runtime as pallet_democracy::Config>::VoteLockingPeriod as Get<u32>>::get(),
8 * DAYS
);
assert_eq!(
<<Runtime as pallet_democracy::Config>::VotingPeriod as Get<u32>>::get(),
7 * DAYS
);
}

#[test]
fn collective_mod() {
assert_eq!(
<<Runtime as pallet_collective::Config<CouncilCollective>>::MotionDuration as Get<
u32,
>>::get(),
3 * DAYS
);
assert_eq!(
<<Runtime as pallet_collective::Config<TechnicalCollective>>::MotionDuration as Get<
u32,
>>::get(),
3 * DAYS
);
}

#[test]
fn treasury_mod() {
assert_eq!(
<<Runtime as pallet_treasury::Config>::SpendPeriod as Get<u32>>::get(),
6 * DAYS
);
}
}
4 changes: 2 additions & 2 deletions runtime/darwinia/src/pallets/democracy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl pallet_democracy::Config for Runtime {
type FastTrackVotingPeriod = ConstU32<{ 3 * HOURS }>;
type InstantAllowed = ConstBool<true>;
type InstantOrigin = RootOrAll<TechnicalCollective>;
type LaunchPeriod = ConstU32<{ 28 * DAYS }>;
type LaunchPeriod = ConstU32<{ ENACTMENT_PERIOD }>;
type MaxBlacklisted = ConstU32<100>;
type MaxDeposits = ConstU32<100>;
type MaxProposals = ConstU32<100>;
Expand All @@ -60,6 +60,6 @@ impl pallet_democracy::Config for Runtime {
// only do it once and it lasts only for the cool-off period.
type VetoOrigin = pallet_collective::EnsureMember<AccountId, TechnicalCollective>;
type VoteLockingPeriod = ConstU32<ENACTMENT_PERIOD>;
type VotingPeriod = ConstU32<{ 28 * DAYS }>;
type VotingPeriod = ConstU32<{ ENACTMENT_PERIOD }>;
type WeightInfo = weights::pallet_democracy::WeightInfo<Self>;
}
Loading