referrerpolicy=no-referrer-when-downgrade

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