This repository has been archived by the owner on Feb 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add parachain & relay chain runtime mock
- Loading branch information
1 parent
3009064
commit 8022516
Showing
7 changed files
with
687 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// This file is part of Darwinia. | ||
// | ||
// Copyright (C) 2018-2022 Darwinia Network | ||
// SPDX-License-Identifier: GPL-3.0 | ||
// | ||
// Darwinia is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Darwinia is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
mod parachain; | ||
mod relay_chain; | ||
|
||
use polkadot_parachain::primitives::Id as ParaId; | ||
use sp_runtime::traits::AccountIdConversion; | ||
use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain}; | ||
|
||
pub const ALICE: sp_runtime::AccountId32 = sp_runtime::AccountId32::new([0u8; 32]); | ||
pub const INITIAL_BALANCE: u128 = 1_000_000_000; | ||
|
||
decl_test_parachain! { | ||
pub struct ParaA { | ||
Runtime = parachain::Runtime, | ||
XcmpMessageHandler = parachain::MsgQueue, | ||
DmpMessageHandler = parachain::MsgQueue, | ||
new_ext = para_ext(1), | ||
} | ||
} | ||
|
||
decl_test_parachain! { | ||
pub struct ParaB { | ||
Runtime = parachain::Runtime, | ||
XcmpMessageHandler = parachain::MsgQueue, | ||
DmpMessageHandler = parachain::MsgQueue, | ||
new_ext = para_ext(2), | ||
} | ||
} | ||
|
||
decl_test_relay_chain! { | ||
pub struct Relay { | ||
Runtime = relay_chain::Runtime, | ||
XcmConfig = relay_chain::XcmConfig, | ||
new_ext = relay_ext(), | ||
} | ||
} | ||
|
||
decl_test_network! { | ||
pub struct MockNet { | ||
relay_chain = Relay, | ||
parachains = vec![ | ||
(1, ParaA), | ||
(2, ParaB), | ||
], | ||
} | ||
} | ||
|
||
pub fn para_account_id(id: u32) -> relay_chain::AccountId { | ||
ParaId::from(id).into_account_truncating() | ||
} | ||
|
||
pub fn para_ext(para_id: u32) -> sp_io::TestExternalities { | ||
use parachain::{MsgQueue, Runtime, System}; | ||
|
||
let mut t = frame_system::GenesisConfig::default().build_storage::<Runtime>().unwrap(); | ||
|
||
pallet_balances::GenesisConfig::<Runtime> { balances: vec![(ALICE, INITIAL_BALANCE)] } | ||
.assimilate_storage(&mut t) | ||
.unwrap(); | ||
|
||
let mut ext = sp_io::TestExternalities::new(t); | ||
ext.execute_with(|| { | ||
System::set_block_number(1); | ||
MsgQueue::set_para_id(para_id.into()); | ||
}); | ||
ext | ||
} | ||
|
||
pub fn relay_ext() -> sp_io::TestExternalities { | ||
use relay_chain::{Runtime, System}; | ||
|
||
let mut t = frame_system::GenesisConfig::default().build_storage::<Runtime>().unwrap(); | ||
|
||
pallet_balances::GenesisConfig::<Runtime> { | ||
balances: vec![(ALICE, INITIAL_BALANCE), (para_account_id(1), INITIAL_BALANCE)], | ||
} | ||
.assimilate_storage(&mut t) | ||
.unwrap(); | ||
|
||
let mut ext = sp_io::TestExternalities::new(t); | ||
ext.execute_with(|| System::set_block_number(1)); | ||
ext | ||
} | ||
|
||
pub type RelayChainPalletXcm = pallet_xcm::Pallet<relay_chain::Runtime>; | ||
pub type ParachainPalletXcm = pallet_xcm::Pallet<parachain::Runtime>; |
Oops, something went wrong.