emulated_integration_tests_common/
lib.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// SPDX-License-Identifier: Apache-2.0
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// 	http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16pub mod impls;
17pub mod macros;
18pub mod xcm_helpers;
19
20pub use xcm_emulator;
21
22// Substrate
23use frame_support::parameter_types;
24use sc_consensus_grandpa::AuthorityId as GrandpaId;
25use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
26use sp_consensus_babe::AuthorityId as BabeId;
27use sp_consensus_beefy::ecdsa_crypto::AuthorityId as BeefyId;
28use sp_core::storage::Storage;
29use sp_keyring::{Ed25519Keyring, Sr25519Keyring};
30use sp_runtime::{traits::AccountIdConversion, BuildStorage};
31
32// Polakdot
33use parachains_common::BlockNumber;
34use polkadot_parachain_primitives::primitives::Sibling;
35use polkadot_runtime_parachains::configuration::HostConfiguration;
36
37// Cumulus
38use parachains_common::{AccountId, AuraId};
39use polkadot_primitives::{AssignmentId, ValidatorId};
40
41pub const XCM_V2: u32 = 2;
42pub const XCM_V3: u32 = 3;
43pub const XCM_V4: u32 = 4;
44pub const XCM_V5: u32 = 5;
45pub const REF_TIME_THRESHOLD: u64 = 33;
46pub const PROOF_SIZE_THRESHOLD: u64 = 33;
47
48/// The default XCM version to set in genesis config.
49pub const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION;
50
51// (trust-backed) Asset registered on AH and reserve-transferred between Parachain and AH
52pub const RESERVABLE_ASSET_ID: u32 = 1;
53// ForeignAsset registered on AH and teleported between Penpal and AH
54pub const TELEPORTABLE_ASSET_ID: u32 = 2;
55
56// USDT registered on AH as (trust-backed) Asset and reserve-transferred between Parachain and AH
57pub const USDT_ID: u32 = 1984;
58
59pub const PENPAL_A_ID: u32 = 2000;
60pub const PENPAL_B_ID: u32 = 2001;
61pub const ASSETS_PALLET_ID: u8 = 50;
62
63parameter_types! {
64	pub PenpalATeleportableAssetLocation: xcm::v5::Location
65		= xcm::v5::Location::new(1, [
66				xcm::v5::Junction::Parachain(PENPAL_A_ID),
67				xcm::v5::Junction::PalletInstance(ASSETS_PALLET_ID),
68				xcm::v5::Junction::GeneralIndex(TELEPORTABLE_ASSET_ID.into()),
69			]
70		);
71	pub PenpalBTeleportableAssetLocation: xcm::v5::Location
72		= xcm::v5::Location::new(1, [
73				xcm::v5::Junction::Parachain(PENPAL_B_ID),
74				xcm::v5::Junction::PalletInstance(ASSETS_PALLET_ID),
75				xcm::v5::Junction::GeneralIndex(TELEPORTABLE_ASSET_ID.into()),
76			]
77		);
78	pub PenpalASiblingSovereignAccount: AccountId = Sibling::from(PENPAL_A_ID).into_account_truncating();
79	pub PenpalBSiblingSovereignAccount: AccountId = Sibling::from(PENPAL_B_ID).into_account_truncating();
80}
81
82pub fn get_host_config() -> HostConfiguration<BlockNumber> {
83	HostConfiguration {
84		max_upward_queue_count: 10,
85		max_upward_queue_size: 51200,
86		max_upward_message_size: 51200,
87		max_upward_message_num_per_candidate: 10,
88		max_downward_message_size: 51200,
89		hrmp_sender_deposit: 0,
90		hrmp_recipient_deposit: 0,
91		hrmp_channel_max_capacity: 1000,
92		hrmp_channel_max_message_size: 102400,
93		hrmp_channel_max_total_size: 102400,
94		hrmp_max_parachain_outbound_channels: 30,
95		hrmp_max_parachain_inbound_channels: 30,
96		..Default::default()
97	}
98}
99
100/// Helper function used in tests to build the genesis storage using given RuntimeGenesisConfig and
101/// code Used in `legacy_vs_json_check` submods to verify storage building with JSON patch against
102/// building with RuntimeGenesisConfig struct.
103pub fn build_genesis_storage(builder: &dyn BuildStorage, code: &[u8]) -> Storage {
104	let mut storage = builder.build_storage().unwrap();
105	storage
106		.top
107		.insert(sp_core::storage::well_known_keys::CODE.to_vec(), code.into());
108	storage
109}
110
111pub mod accounts {
112	use super::*;
113	pub const ALICE: &str = "Alice";
114	pub const BOB: &str = "Bob";
115	pub const DUMMY_EMPTY: &str = "JohnDoe";
116
117	pub fn init_balances() -> Vec<AccountId> {
118		Sr25519Keyring::well_known().map(|k| k.to_account_id()).collect()
119	}
120}
121
122pub mod collators {
123	use super::*;
124
125	pub fn invulnerables() -> Vec<(AccountId, AuraId)> {
126		vec![
127			(Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Alice.public().into()),
128			(Sr25519Keyring::Bob.to_account_id(), Sr25519Keyring::Bob.public().into()),
129		]
130	}
131}
132
133pub mod validators {
134	use sp_consensus_beefy::test_utils::Keyring;
135
136	use super::*;
137
138	pub fn initial_authorities() -> Vec<(
139		AccountId,
140		AccountId,
141		BabeId,
142		GrandpaId,
143		ValidatorId,
144		AssignmentId,
145		AuthorityDiscoveryId,
146		BeefyId,
147	)> {
148		vec![(
149			Sr25519Keyring::AliceStash.to_account_id(),
150			Sr25519Keyring::Alice.to_account_id(),
151			BabeId::from(Sr25519Keyring::Alice.public()),
152			GrandpaId::from(Ed25519Keyring::Alice.public()),
153			ValidatorId::from(Sr25519Keyring::Alice.public()),
154			AssignmentId::from(Sr25519Keyring::Alice.public()),
155			AuthorityDiscoveryId::from(Sr25519Keyring::Alice.public()),
156			BeefyId::from(Keyring::<BeefyId>::Alice.public()),
157		)]
158	}
159}