Skip to content

Commit

Permalink
Relay chain unittest (#654)
Browse files Browse the repository at this point in the history
* debug: temp push

* debug: temp finialize the unittest

* debug: fmt and clippy

* debug: sunc to moonbase and rococo

* debug: pub mod

* debug: fix test cases

* feat: Unittest improve

* debug: adjust test code style

* debug: magic number replace

* debug: rename

* debug: finalize the test code to rococo/moonbase runtime

* debug: cargo fmt

* debug: wrong comment

Co-authored-by: Kai <[email protected]>
  • Loading branch information
wangminqi and Kailai-Wang authored Jul 1, 2022
1 parent ca9822a commit c380b52
Show file tree
Hide file tree
Showing 17 changed files with 3,278 additions and 404 deletions.
2 changes: 1 addition & 1 deletion runtime/litmus/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
// along with Litentry. If not, see <https://www.gnu.org/licenses/>.

mod base_call_filter;
mod setup;
pub mod setup;
mod transaction_payment;
mod xcm_parachain;
27 changes: 12 additions & 15 deletions runtime/litmus/src/tests/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ pub use crate::{
AccountId, AssetManager, Balance, Balances, Call, CumulusXcm, DmpQueue, Event, ExtrinsicFilter,
MinimumMultiplier, Multisig, Origin, ParachainSystem, PolkadotXcm, Runtime,
RuntimeBlockWeights, SlowAdjustingFeeUpdate, System, TargetBlockFullness, Tokens,
TransactionByteFee, TransactionPayment, Treasury, Vesting, XTokens, XcmpQueue, UNIT,
TransactionByteFee, TransactionPayment, Treasury, Vesting, XTokens, XcmpQueue, CENTS,
MILLICENTS, UNIT,
};
pub const ALICE: [u8; 32] = [1u8; 32];
pub const BOB: [u8; 32] = [2u8; 32];
Expand Down Expand Up @@ -51,6 +52,9 @@ pub(crate) fn charlie() -> AccountId {
AccountId::from(CHARLIE)
}

pub const PARA_A_USER_INITIAL_BALANCE: u128 = 500_000 * UNIT;
pub const PARA_B_USER_INITIAL_BALANCE: u128 = 600_000 * UNIT;

pub struct ExtBuilder {
balances: Vec<(AccountId, Balance)>,
parachain_id: u32,
Expand Down Expand Up @@ -137,9 +141,8 @@ decl_test_parachain! {
DmpMessageHandler = DmpQueue,
new_ext = ExtBuilder::default()
.balances(vec![
// fund Alice and BOB
(AccountId::from(ALICE), 500_000_000_000_000_000),
(AccountId::from(BOB), 500_000_000_000_000_000),
// fund Alice
(alice(), PARA_A_USER_INITIAL_BALANCE),
]).parachain_id(1).build(),
}
}
Expand All @@ -151,9 +154,8 @@ decl_test_parachain! {
DmpMessageHandler = DmpQueue,
new_ext = ExtBuilder::default()
.balances(vec![
// fund Alice and BOB
(AccountId::from(ALICE), 600_000_000_000_000_000),
(AccountId::from(BOB), 600_000_000_000_000_000),
// fund BOB
(bob(), PARA_B_USER_INITIAL_BALANCE),
]).parachain_id(2).build(),
}
}
Expand All @@ -163,14 +165,9 @@ pub fn relay_ext() -> sp_io::TestExternalities {
.build_storage::<relay::Runtime>()
.unwrap();

pallet_balances::GenesisConfig::<relay::Runtime> {
balances: vec![
(AccountId::from(ALICE), 700_000_000_000_000_000),
(AccountId::from(BOB), 700_000_000_000_000_000),
],
}
.assimilate_storage(&mut t)
.unwrap();
pallet_balances::GenesisConfig::<relay::Runtime> { balances: vec![] }
.assimilate_storage(&mut t)
.unwrap();

let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| relay::System::set_block_number(1));
Expand Down
31 changes: 25 additions & 6 deletions runtime/litmus/src/tests/setup/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Litentry. If not, see <https://www.gnu.org/licenses/>.

use frame_support::{
construct_runtime, parameter_types,
construct_runtime, match_types, parameter_types,
traits::{ConstU128, ConstU32, ConstU64, Everything},
weights::IdentityFee,
};
Expand All @@ -27,10 +27,11 @@ use cumulus_primitives_core::ParaId;
use polkadot_runtime_parachains::{configuration, origin, shared, ump};
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, ChildParachainAsNative,
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, ChildParachainAsNative,
ChildParachainConvertsVia, CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds,
IsConcrete, LocationInverter, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, UsingComponents,
IsChildSystemParachain, IsConcrete, LocationInverter, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents,
};
use xcm_executor::{Config, XcmExecutor};

Expand Down Expand Up @@ -105,7 +106,25 @@ type LocalOriginConverter = (
);

pub type XcmRouter = super::RelayChainXcmRouter;
pub type Barrier = (TakeWeightCredit, AllowTopLevelPaidExecutionFrom<Everything>);

match_types! {
pub type OnlyParachains: impl Contains<MultiLocation> = {
MultiLocation { parents: 0, interior: X1(Parachain(_)) }
};
}
/// The barriers one of which must be passed for an XCM message to be executed.
pub type Barrier = (
// Weight that is paid for may be consumed.
TakeWeightCredit,
// If the message is one that immediately attemps to pay for execution, then allow it.
AllowTopLevelPaidExecutionFrom<Everything>,
// Messages coming from system parachains need not pay for execution.
AllowUnpaidExecutionFrom<IsChildSystemParachain<ParaId>>,
// Expected responses are OK.
AllowKnownQueryResponses<XcmPallet>,
// Subscriptions for version tracking are OK.
AllowSubscriptionsFrom<OnlyParachains>,
);

pub struct XcmConfig;
impl Config for XcmConfig {
Expand All @@ -116,7 +135,7 @@ impl Config for XcmConfig {
type IsReserve = ();
type IsTeleporter = ();
type LocationInverter = LocationInverter<Ancestry>;
type Barrier = Barrier;
type Barrier = Barrier; // This is the setting should be same from Kusama
type Weigher = FixedWeightBounds<ConstU64<10>, Call, ConstU32<100>>;
type Trader = UsingComponents<IdentityFee<Balance>, KsmLocation, AccountId, Balances, ()>;
type ResponseHandler = ();
Expand Down
Loading

0 comments on commit c380b52

Please sign in to comment.