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