referrerpolicy=no-referrer-when-downgrade

asset_hub_westend_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::westend::snowbridge::EthereumNetwork;
32use xcm::{latest::prelude::*, opaque::latest::WESTEND_GENESIS_HASH};
33use xcm_builder::ExternalConsensusLocationsConverterFor;
34
35pub const PARA_ID: u32 = 1000;
36pub const ED: Balance = testnet_parachains_constants::westend::currency::EXISTENTIAL_DEPOSIT;
37pub const USDT_ED: Balance = 70_000;
38
39parameter_types! {
40	pub AssetHubWestendAssetOwner: AccountId = Keyring::Alice.to_account_id();
41	pub WestendGlobalConsensusNetwork: NetworkId = NetworkId::ByGenesis(WESTEND_GENESIS_HASH);
42	pub AssetHubWestendUniversalLocation: InteriorLocation = [GlobalConsensus(WestendGlobalConsensusNetwork::get()), Parachain(PARA_ID)].into();
43	pub EthereumSovereignAccount: AccountId = ExternalConsensusLocationsConverterFor::<
44			AssetHubWestendUniversalLocation,
45			AccountId,
46		>::convert_location(&Location::new(
47			2,
48			[Junction::GlobalConsensus(EthereumNetwork::get())],
49		))
50		.unwrap();
51}
52
53pub fn genesis() -> Storage {
54	let genesis_config = asset_hub_westend_runtime::RuntimeGenesisConfig {
55		system: asset_hub_westend_runtime::SystemConfig::default(),
56		balances: asset_hub_westend_runtime::BalancesConfig {
57			balances: accounts::init_balances()
58				.iter()
59				.cloned()
60				.map(|k| (k, ED * 4096))
61				// pre-fund checking account to avoid pre-funding for every test scenario
62				// teleporting funds to asset hub
63				.chain(std::iter::once((
64					asset_hub_westend_runtime::xcm_config::CheckingAccount::get(),
65					ED * 1000,
66				)))
67				.collect(),
68			..Default::default()
69		},
70		parachain_info: asset_hub_westend_runtime::ParachainInfoConfig {
71			parachain_id: PARA_ID.into(),
72			..Default::default()
73		},
74		collator_selection: asset_hub_westend_runtime::CollatorSelectionConfig {
75			invulnerables: collators::invulnerables().iter().cloned().map(|(acc, _)| acc).collect(),
76			candidacy_bond: ED * 16,
77			..Default::default()
78		},
79		session: asset_hub_westend_runtime::SessionConfig {
80			keys: collators::invulnerables()
81				.into_iter()
82				.map(|(acc, aura)| {
83					(
84						acc.clone(),                                     // account id
85						acc,                                             // validator id
86						asset_hub_westend_runtime::SessionKeys { aura }, // session keys
87					)
88				})
89				.collect(),
90			..Default::default()
91		},
92		polkadot_xcm: asset_hub_westend_runtime::PolkadotXcmConfig {
93			safe_xcm_version: Some(SAFE_XCM_VERSION),
94			..Default::default()
95		},
96		assets: asset_hub_westend_runtime::AssetsConfig {
97			assets: vec![
98				(RESERVABLE_ASSET_ID, AssetHubWestendAssetOwner::get(), false, ED),
99				(USDT_ID, AssetHubWestendAssetOwner::get(), true, USDT_ED),
100			],
101			..Default::default()
102		},
103		foreign_assets: asset_hub_westend_runtime::ForeignAssetsConfig {
104			assets: vec![
105				// PenpalA's teleportable asset representation
106				(
107					PenpalATeleportableAssetLocation::get(),
108					PenpalASiblingSovereignAccount::get(),
109					false,
110					ED,
111				),
112				// PenpalB's teleportable asset representation
113				(
114					PenpalBTeleportableAssetLocation::get(),
115					PenpalBSiblingSovereignAccount::get(),
116					false,
117					ED,
118				),
119				// Ether
120				(
121					xcm::v5::Location::new(2, [GlobalConsensus(EthereumNetwork::get())]),
122					EthereumSovereignAccount::get(),
123					true,
124					ETHER_MIN_BALANCE,
125				),
126				// Weth
127				(
128					xcm::v5::Location::new(
129						2,
130						[
131							GlobalConsensus(EthereumNetwork::get()),
132							AccountKey20 { network: None, key: WETH.into() },
133						],
134					),
135					EthereumSovereignAccount::get(),
136					true,
137					ETHER_MIN_BALANCE,
138				),
139			],
140			..Default::default()
141		},
142		..Default::default()
143	};
144
145	build_genesis_storage(
146		&genesis_config,
147		asset_hub_westend_runtime::WASM_BINARY
148			.expect("WASM binary was not built, please build it!"),
149	)
150}