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
22use hex_literal::hex;
23
24// Substrate
25use frame_support::parameter_types;
26use sc_consensus_grandpa::AuthorityId as GrandpaId;
27use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
28use sp_consensus_babe::AuthorityId as BabeId;
29use sp_consensus_beefy::ecdsa_crypto::AuthorityId as BeefyId;
30use sp_core::storage::Storage;
31use sp_keyring::{Ed25519Keyring, Sr25519Keyring};
32use sp_runtime::{traits::AccountIdConversion, BuildStorage};
33
34// Polkadot
35use parachains_common::BlockNumber;
36use polkadot_parachain_primitives::primitives::Sibling;
37use polkadot_runtime_parachains::configuration::HostConfiguration;
38
39// Cumulus
40use parachains_common::{AccountId, AuraId};
41use polkadot_primitives::{AssignmentId, ValidatorId};
42
43pub const XCM_V2: u32 = 2;
44pub const XCM_V3: u32 = 3;
45pub const XCM_V4: u32 = 4;
46pub const XCM_V5: u32 = 5;
47pub const REF_TIME_THRESHOLD: u64 = 33;
48pub const PROOF_SIZE_THRESHOLD: u64 = 33;
49
50/// The default XCM version to set in genesis config.
51pub const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION;
52
53// (trust-backed) Asset registered on AH and reserve-transferred between Parachain and AH
54pub const RESERVABLE_ASSET_ID: u32 = 1;
55// ForeignAsset registered on AH and teleported between Penpal and AH
56pub const TELEPORTABLE_ASSET_ID: u32 = 2;
57
58// USDT registered on AH as (trust-backed) Asset and reserve-transferred between Parachain and AH
59pub const USDT_ID: u32 = 1984;
60
61pub const PENPAL_A_ID: u32 = 2000;
62pub const PENPAL_B_ID: u32 = 2001;
63pub const ASSET_HUB_ROCOCO_ID: u32 = 1000;
64pub const ASSET_HUB_WESTEND_ID: u32 = 1000;
65pub const ASSETS_PALLET_ID: u8 = 50;
66
67// Address of WETH ERC20 token contract on remote Ethereum network
68pub const WETH: [u8; 20] = hex!("fff9976782d46cc05630d1f6ebab18b2324d6b14");
69
70parameter_types! {
71	pub PenpalATeleportableAssetLocation: xcm::v5::Location
72		= xcm::v5::Location::new(1, [
73				xcm::v5::Junction::Parachain(PENPAL_A_ID),
74				xcm::v5::Junction::PalletInstance(ASSETS_PALLET_ID),
75				xcm::v5::Junction::GeneralIndex(TELEPORTABLE_ASSET_ID.into()),
76			]
77		);
78	pub PenpalBTeleportableAssetLocation: xcm::v5::Location
79		= xcm::v5::Location::new(1, [
80				xcm::v5::Junction::Parachain(PENPAL_B_ID),
81				xcm::v5::Junction::PalletInstance(ASSETS_PALLET_ID),
82				xcm::v5::Junction::GeneralIndex(TELEPORTABLE_ASSET_ID.into()),
83			]
84		);
85	pub PenpalASiblingSovereignAccount: AccountId = Sibling::from(PENPAL_A_ID).into_account_truncating();
86	pub PenpalBSiblingSovereignAccount: AccountId = Sibling::from(PENPAL_B_ID).into_account_truncating();
87}
88
89pub fn get_host_config() -> HostConfiguration<BlockNumber> {
90	HostConfiguration {
91		max_upward_queue_count: 10,
92		max_upward_queue_size: 51200,
93		max_upward_message_size: 51200,
94		max_upward_message_num_per_candidate: 10,
95		max_downward_message_size: 51200,
96		hrmp_sender_deposit: 0,
97		hrmp_recipient_deposit: 0,
98		hrmp_channel_max_capacity: 1000,
99		hrmp_channel_max_message_size: 102400,
100		hrmp_channel_max_total_size: 102400,
101		hrmp_max_parachain_outbound_channels: 30,
102		hrmp_max_parachain_inbound_channels: 30,
103		..Default::default()
104	}
105}
106
107/// Helper function used in tests to build the genesis storage using given RuntimeGenesisConfig and
108/// code Used in `legacy_vs_json_check` submods to verify storage building with JSON patch against
109/// building with RuntimeGenesisConfig struct.
110pub fn build_genesis_storage(builder: &dyn BuildStorage, code: &[u8]) -> Storage {
111	let mut storage = builder.build_storage().unwrap();
112	storage
113		.top
114		.insert(sp_core::storage::well_known_keys::CODE.to_vec(), code.into());
115	storage
116}
117
118pub mod accounts {
119	use super::*;
120	pub const ALICE: &str = "Alice";
121	pub const BOB: &str = "Bob";
122	pub const DUMMY_EMPTY: &str = "JohnDoe";
123
124	pub fn init_balances() -> Vec<AccountId> {
125		Sr25519Keyring::well_known().map(|k| k.to_account_id()).collect()
126	}
127}
128
129pub mod collators {
130	use super::*;
131
132	pub fn invulnerables() -> Vec<(AccountId, AuraId)> {
133		vec![
134			(Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Alice.public().into()),
135			(Sr25519Keyring::Bob.to_account_id(), Sr25519Keyring::Bob.public().into()),
136		]
137	}
138}
139
140pub mod validators {
141	use sp_consensus_beefy::test_utils::Keyring;
142
143	use super::*;
144
145	pub fn initial_authorities() -> Vec<(
146		AccountId,
147		AccountId,
148		BabeId,
149		GrandpaId,
150		ValidatorId,
151		AssignmentId,
152		AuthorityDiscoveryId,
153		BeefyId,
154	)> {
155		vec![(
156			Sr25519Keyring::AliceStash.to_account_id(),
157			Sr25519Keyring::Alice.to_account_id(),
158			BabeId::from(Sr25519Keyring::Alice.public()),
159			GrandpaId::from(Ed25519Keyring::Alice.public()),
160			ValidatorId::from(Sr25519Keyring::Alice.public()),
161			AssignmentId::from(Sr25519Keyring::Alice.public()),
162			AuthorityDiscoveryId::from(Sr25519Keyring::Alice.public()),
163			BeefyId::from(Keyring::<BeefyId>::Alice.public()),
164		)]
165	}
166}