referrerpolicy=no-referrer-when-downgrade

asset_hub_rococo_emulated_chain/
genesis.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
16// Substrate
17use frame_support::parameter_types;
18use sp_core::storage::Storage;
19use sp_keyring::Sr25519Keyring as Keyring;
20
21// Cumulus
22use emulated_integration_tests_common::{
23	accounts, build_genesis_storage, collators,
24	snowbridge::{ETHER_MIN_BALANCE, WETH},
25	xcm_emulator::ConvertLocation,
26	PenpalASiblingSovereignAccount, PenpalATeleportableAssetLocation,
27	PenpalBSiblingSovereignAccount, PenpalBTeleportableAssetLocation, RESERVABLE_ASSET_ID,
28	SAFE_XCM_VERSION, USDT_ID,
29};
30use parachains_common::{AccountId, Balance};
31use testnet_parachains_constants::rococo::snowbridge::EthereumNetwork;
32use xcm::{
33	latest::prelude::*,
34	opaque::latest::{ROCOCO_GENESIS_HASH, WESTEND_GENESIS_HASH},
35};
36use xcm_builder::ExternalConsensusLocationsConverterFor;
37
38pub const PARA_ID: u32 = 1000;
39pub const ED: Balance = testnet_parachains_constants::rococo::currency::EXISTENTIAL_DEPOSIT;
40
41parameter_types! {
42	pub AssetHubRococoAssetOwner: AccountId = Keyring::Alice.to_account_id();
43	pub RococoGlobalConsensusNetwork: NetworkId = NetworkId::ByGenesis(ROCOCO_GENESIS_HASH);
44	pub AssetHubRococoUniversalLocation: InteriorLocation = [GlobalConsensus(RococoGlobalConsensusNetwork::get()), Parachain(PARA_ID)].into();
45	pub AssetHubWestendSovereignAccount: AccountId = ExternalConsensusLocationsConverterFor::<
46			AssetHubRococoUniversalLocation,
47			AccountId,
48		>::convert_location(&Location::new(
49			2,
50			[Junction::GlobalConsensus( NetworkId::ByGenesis(WESTEND_GENESIS_HASH)), Parachain(PARA_ID)],
51		))
52		.unwrap();
53}
54
55pub fn genesis() -> Storage {
56	let genesis_config = asset_hub_rococo_runtime::RuntimeGenesisConfig {
57		system: asset_hub_rococo_runtime::SystemConfig::default(),
58		balances: asset_hub_rococo_runtime::BalancesConfig {
59			balances: accounts::init_balances()
60				.iter()
61				.cloned()
62				.map(|k| (k, ED * 4096 * 4096))
63				.collect(),
64			..Default::default()
65		},
66		parachain_info: asset_hub_rococo_runtime::ParachainInfoConfig {
67			parachain_id: PARA_ID.into(),
68			..Default::default()
69		},
70		collator_selection: asset_hub_rococo_runtime::CollatorSelectionConfig {
71			invulnerables: collators::invulnerables().iter().cloned().map(|(acc, _)| acc).collect(),
72			candidacy_bond: ED * 16,
73			..Default::default()
74		},
75		session: asset_hub_rococo_runtime::SessionConfig {
76			keys: collators::invulnerables()
77				.into_iter()
78				.map(|(acc, aura)| {
79					(
80						acc.clone(),                                    // account id
81						acc,                                            // validator id
82						asset_hub_rococo_runtime::SessionKeys { aura }, // session keys
83					)
84				})
85				.collect(),
86			..Default::default()
87		},
88		polkadot_xcm: asset_hub_rococo_runtime::PolkadotXcmConfig {
89			safe_xcm_version: Some(SAFE_XCM_VERSION),
90			..Default::default()
91		},
92		assets: asset_hub_rococo_runtime::AssetsConfig {
93			assets: vec![
94				(RESERVABLE_ASSET_ID, AssetHubRococoAssetOwner::get(), false, ED),
95				(USDT_ID, AssetHubRococoAssetOwner::get(), true, ED),
96			],
97			..Default::default()
98		},
99		foreign_assets: asset_hub_rococo_runtime::ForeignAssetsConfig {
100			assets: vec![
101				// PenpalA's teleportable asset representation
102				(
103					PenpalATeleportableAssetLocation::get(),
104					PenpalASiblingSovereignAccount::get(),
105					false,
106					ED,
107				),
108				// PenpalB's teleportable asset representation
109				(
110					PenpalBTeleportableAssetLocation::get(),
111					PenpalBSiblingSovereignAccount::get(),
112					false,
113					ED,
114				),
115				// Ether
116				(
117					xcm::v5::Location::new(2, [GlobalConsensus(EthereumNetwork::get())]),
118					AssetHubWestendSovereignAccount::get(), /* To emulate double bridging, where
119					                                         * WAH is the owner of assets from
120					                                         * Ethereum on RAH */
121					true,
122					ETHER_MIN_BALANCE,
123				),
124				// Weth
125				(
126					xcm::v5::Location::new(
127						2,
128						[
129							GlobalConsensus(EthereumNetwork::get()),
130							AccountKey20 { network: None, key: WETH.into() },
131						],
132					),
133					AssetHubWestendSovereignAccount::get(),
134					true,
135					ETHER_MIN_BALANCE,
136				),
137			],
138			..Default::default()
139		},
140		..Default::default()
141	};
142
143	build_genesis_storage(
144		&genesis_config,
145		asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
146	)
147}