Skip to content

Commit

Permalink
Update to SDK 1.11 - @bkontur (#327)
Browse files Browse the repository at this point in the history
Partial TODOs, mainly to unblock CI for
#324

<!-- Remember that you can run `/merge` to enable auto-merge in the PR
-->

<!-- Remember to modify the changelog. If you don't need to modify it,
you can check the following box.
Instead, if you have already modified it, simply delete the following
line. -->

- [X] Does not require a CHANGELOG entry
- [x] add hybrid_integration tests
  • Loading branch information
bkontur authored Jun 3, 2024
1 parent 698e314 commit 8ec28f9
Show file tree
Hide file tree
Showing 43 changed files with 2,868 additions and 1,134 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ Creds: config
# send 3 wKSM back to Alice from Polkadot AH to Kusama AH
asset-hub-kusama-collator-1: run {{ENV_PATH}}/helper.sh with "withdraw-reserve-assets-from-asset-hub-polkadot-local 3000000000000" within 120 seconds

# check that //Alice received at least 2.8 wKSM on Westend AH
# check that //Alice received at least 2.8 wKSM on Polkadot AH
# (we wait until //Alice account increases here - there are no other transactions that may increase it)
asset-hub-kusama-collator-1: js-script {{FRAMEWORK_PATH}}/js-helpers/native-assets-balance-increased.js with "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY,2800000000000" within 300 seconds
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ parachains-common = { workspace = true, default-features = true }
cumulus-primitives-core = { workspace = true, default-features = true }
emulated-integration-tests-common = { workspace = true }
xcm = { workspace = true, default-features = true }
polkadot-parachain-primitives = { workspace = true }

# Runtimes
asset-hub-kusama-runtime = { workspace = true }
kusama-emulated-chain = { workspace = true }
penpal-emulated-chain = { workspace = true }
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,33 @@
// limitations under the License.

// Substrate
use sp_core::storage::Storage;
use sp_core::{sr25519, storage::Storage};

// Cumulus
use emulated_integration_tests_common::{
accounts, build_genesis_storage, collators, SAFE_XCM_VERSION,
accounts, build_genesis_storage, collators, get_account_id_from_seed, RESERVABLE_ASSET_ID,
SAFE_XCM_VERSION,
};
use parachains_common::Balance;
use frame_support::sp_runtime::traits::AccountIdConversion;
use parachains_common::{AccountId, Balance};
use polkadot_parachain_primitives::primitives::Sibling;
use xcm::prelude::*;

pub const PARA_ID: u32 = 1000;
pub const ED: Balance = asset_hub_kusama_runtime::ExistentialDeposit::get();

frame_support::parameter_types! {
pub AssetHubKusamaAssetOwner: AccountId = get_account_id_from_seed::<sr25519::Public>("Alice");
pub PenpalATeleportableAssetLocation: Location
= Location::new(1, [
Junction::Parachain(penpal_emulated_chain::PARA_ID_A),
Junction::PalletInstance(penpal_emulated_chain::ASSETS_PALLET_ID),
Junction::GeneralIndex(penpal_emulated_chain::TELEPORTABLE_ASSET_ID.into()),
]
);
pub PenpalASiblingSovereignAccount: AccountId = Sibling::from(penpal_emulated_chain::PARA_ID_A).into_account_truncating();
}

pub fn genesis() -> Storage {
let genesis_config = asset_hub_kusama_runtime::RuntimeGenesisConfig {
system: asset_hub_kusama_runtime::SystemConfig::default(),
Expand Down Expand Up @@ -60,6 +76,22 @@ pub fn genesis() -> Storage {
safe_xcm_version: Some(SAFE_XCM_VERSION),
..Default::default()
},
assets: asset_hub_kusama_runtime::AssetsConfig {
assets: vec![(RESERVABLE_ASSET_ID, AssetHubKusamaAssetOwner::get(), true, ED)],
..Default::default()
},
foreign_assets: asset_hub_kusama_runtime::ForeignAssetsConfig {
assets: vec![
// Penpal's teleportable asset representation
(
PenpalATeleportableAssetLocation::get().try_into().unwrap(),
PenpalASiblingSovereignAccount::get(),
true,
ED,
),
],
..Default::default()
},
..Default::default()
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ parachains-common = { workspace = true, default-features = true }
cumulus-primitives-core = { workspace = true, default-features = true }
emulated-integration-tests-common = { workspace = true }
xcm = { workspace = true, default-features = true }
polkadot-parachain-primitives = { workspace = true }

# Runtimes
asset-hub-polkadot-runtime = { workspace = true }
polkadot-emulated-chain = { workspace = true }
penpal-emulated-chain = { workspace = true }
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,38 @@ use sp_core::storage::Storage;

// Cumulus
use emulated_integration_tests_common::{
accounts, build_genesis_storage, get_account_id_from_seed, get_from_seed, SAFE_XCM_VERSION,
accounts, build_genesis_storage, get_account_id_from_seed, get_from_seed, RESERVABLE_ASSET_ID,
SAFE_XCM_VERSION,
};
use frame_support::sp_runtime::traits::AccountIdConversion;
use parachains_common::{AccountId, AssetHubPolkadotAuraId, Balance};
use polkadot_parachain_primitives::primitives::Sibling;
use sp_core::sr25519;
use xcm::prelude::*;

pub const PARA_ID: u32 = 1000;
pub const ED: Balance = asset_hub_polkadot_runtime::ExistentialDeposit::get();

frame_support::parameter_types! {
pub AssetHubPolkadotAssetOwner: AccountId = get_account_id_from_seed::<sr25519::Public>("Alice");
pub PenpalATeleportableAssetLocation: Location
= Location::new(1, [
Junction::Parachain(penpal_emulated_chain::PARA_ID_A),
Junction::PalletInstance(penpal_emulated_chain::ASSETS_PALLET_ID),
Junction::GeneralIndex(penpal_emulated_chain::TELEPORTABLE_ASSET_ID.into()),
]
);
pub PenpalBTeleportableAssetLocation: Location
= Location::new(1, [
Junction::Parachain(penpal_emulated_chain::PARA_ID_B),
Junction::PalletInstance(penpal_emulated_chain::ASSETS_PALLET_ID),
Junction::GeneralIndex(penpal_emulated_chain::TELEPORTABLE_ASSET_ID.into()),
]
);
pub PenpalASiblingSovereignAccount: AccountId = Sibling::from(penpal_emulated_chain::PARA_ID_A).into_account_truncating();
pub PenpalBSiblingSovereignAccount: AccountId = Sibling::from(penpal_emulated_chain::PARA_ID_B).into_account_truncating();
}

fn invulnerables_asset_hub_polkadot() -> Vec<(AccountId, AssetHubPolkadotAuraId)> {
vec![
(
Expand All @@ -43,7 +67,11 @@ pub fn genesis() -> Storage {
let genesis_config = asset_hub_polkadot_runtime::RuntimeGenesisConfig {
system: asset_hub_polkadot_runtime::SystemConfig::default(),
balances: asset_hub_polkadot_runtime::BalancesConfig {
balances: accounts::init_balances().iter().cloned().map(|k| (k, ED * 4096)).collect(),
balances: accounts::init_balances()
.iter()
.cloned()
.map(|k| (k, ED * 4096 * 4096))
.collect(),
},
parachain_info: asset_hub_polkadot_runtime::ParachainInfoConfig {
parachain_id: PARA_ID.into(),
Expand Down Expand Up @@ -74,6 +102,28 @@ pub fn genesis() -> Storage {
safe_xcm_version: Some(SAFE_XCM_VERSION),
..Default::default()
},
assets: asset_hub_polkadot_runtime::AssetsConfig {
assets: vec![(RESERVABLE_ASSET_ID, AssetHubPolkadotAssetOwner::get(), true, ED)],
..Default::default()
},
foreign_assets: asset_hub_polkadot_runtime::ForeignAssetsConfig {
assets: vec![
// Penpal's teleportable asset representation
(
PenpalATeleportableAssetLocation::get().try_into().unwrap(),
PenpalASiblingSovereignAccount::get().try_into().unwrap(),
true,
ED,
),
(
PenpalBTeleportableAssetLocation::get().try_into().unwrap(),
PenpalBSiblingSovereignAccount::get().try_into().unwrap(),
true,
ED,
),
],
..Default::default()
},
..Default::default()
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,26 @@
// limitations under the License.

// Substrate
use frame_support::parameter_types;
use sp_core::{sr25519, storage::Storage};

// Cumulus
use emulated_integration_tests_common::{
accounts, build_genesis_storage, collators, get_account_id_from_seed, SAFE_XCM_VERSION,
};
use parachains_common::Balance;
use parachains_common::{AccountId, Balance};
use penpal_runtime::xcm_config::{LocalReservableFromAssetHub, RelayLocation};

// Penpal
pub const PARA_ID_A: u32 = 2000;
pub const PARA_ID_B: u32 = 2001;
pub const ED: Balance = penpal_runtime::ExistentialDeposit::get();

parameter_types! {
pub PenpalSudoAccount: AccountId = get_account_id_from_seed::<sr25519::Public>("Alice");
pub PenpalAssetOwner: AccountId = PenpalSudoAccount::get();
}

pub fn genesis(para_id: u32) -> Storage {
let genesis_config = penpal_runtime::RuntimeGenesisConfig {
system: penpal_runtime::SystemConfig::default(),
Expand Down Expand Up @@ -58,8 +65,24 @@ pub fn genesis(para_id: u32) -> Storage {
safe_xcm_version: Some(SAFE_XCM_VERSION),
..Default::default()
},
sudo: penpal_runtime::SudoConfig {
key: Some(get_account_id_from_seed::<sr25519::Public>("Alice")),
sudo: penpal_runtime::SudoConfig { key: Some(PenpalSudoAccount::get()) },
assets: penpal_runtime::AssetsConfig {
assets: vec![(
penpal_runtime::xcm_config::TELEPORTABLE_ASSET_ID,
PenpalAssetOwner::get(),
false,
ED,
)],
..Default::default()
},
foreign_assets: penpal_runtime::ForeignAssetsConfig {
assets: vec![
// Relay Native asset representation
(RelayLocation::get(), PenpalAssetOwner::get(), true, ED),
// Sufficient AssetHub asset representation
(LocalReservableFromAssetHub::get(), PenpalAssetOwner::get(), true, ED),
],
..Default::default()
},
..Default::default()
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
// limitations under the License.

mod genesis;
pub use genesis::{genesis, ED, PARA_ID_A, PARA_ID_B};
pub use genesis::{genesis, PenpalAssetOwner, ED, PARA_ID_A, PARA_ID_B};
pub use penpal_runtime::xcm_config::{
CustomizableAssetFromSystemAssetHub, LocalTeleportableToAssetHub, XcmConfig,
CustomizableAssetFromSystemAssetHub, LocalReservableFromAssetHub, LocalTeleportableToAssetHub,
XcmConfig, ASSETS_PALLET_ID, RESERVABLE_ASSET_ID, TELEPORTABLE_ASSET_ID,
};

// Substrate
Expand All @@ -28,8 +29,6 @@ use emulated_integration_tests_common::{
impl_assets_helpers_for_parachain, impl_foreign_assets_helpers_for_parachain, impls::Parachain,
xcm_emulator::decl_test_parachains,
};
use kusama_emulated_chain::Kusama;
use polkadot_emulated_chain::Polkadot;

// Penpal Parachain declaration
decl_test_parachains! {
Expand Down
95 changes: 2 additions & 93 deletions integration-tests/emulated/helpers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,98 +30,7 @@ pub use xcm_emulator::Chain;

/// TODO: when bumping to polkadot-sdk v1.8.0,
/// remove this crate altogether and get the macros from `emulated-integration-tests-common`.
#[macro_export]
macro_rules! test_sibling_is_trusted_teleporter {
( $sender_para:ty, $sender_xcm_config:ty, vec![$( $receiver_para:ty ),+], ($assets:expr, $amount:expr) ) => {
$crate::paste::paste! {
// init Origin variables
let sender = [<$sender_para Sender>]::get();
let mut para_sender_balance_before =
<$sender_para as $crate::Chain>::account_data_of(sender.clone()).free;
let origin = <$sender_para as $crate::Chain>::RuntimeOrigin::signed(sender.clone());
let fee_asset_item = 0;
let weight_limit = $crate::WeightLimit::Unlimited;

$(
{
// init Destination variables
let receiver = [<$receiver_para Receiver>]::get();
let para_receiver_balance_before =
<$receiver_para as $crate::Chain>::account_data_of(receiver.clone()).free;
let para_destination =
<$sender_para>::sibling_location_of(<$receiver_para>::para_id());
let beneficiary: Location =
$crate::AccountId32 { network: None, id: receiver.clone().into() }.into();

// Send XCM message from Origin Parachain
// We are only testing the limited teleport version, which should be ok since success will
// depend only on a proper `XcmConfig` at destination.
<$sender_para>::execute_with(|| {
assert_ok!(<$sender_para as [<$sender_para Pallet>]>::PolkadotXcm::limited_teleport_assets(
origin.clone(),
bx!(para_destination.clone().into()),
bx!(beneficiary.clone().into()),
bx!($assets.clone().into()),
fee_asset_item,
weight_limit.clone(),
));

type RuntimeEvent = <$sender_para as $crate::Chain>::RuntimeEvent;

assert_expected_events!(
$sender_para,
vec![
RuntimeEvent::PolkadotXcm(
$crate::pallet_xcm::Event::Attempted { outcome: Outcome::Complete { .. } }
) => {},
RuntimeEvent::XcmpQueue(
$crate::cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }
) => {},
RuntimeEvent::Balances(
$crate::pallet_balances::Event::Burned { who: sender, amount }
) => {},
]
);
});

// Receive XCM message in Destination Parachain
<$receiver_para>::execute_with(|| {
type RuntimeEvent = <$receiver_para as $crate::Chain>::RuntimeEvent;

assert_expected_events!(
$receiver_para,
vec![
RuntimeEvent::Balances(
$crate::pallet_balances::Event::Minted { who: receiver, .. }
) => {},
RuntimeEvent::MessageQueue(
$crate::pallet_message_queue::Event::Processed { success: true, .. }
) => {},
]
);
});

// Check if balances are updated accordingly in Origin and Destination Parachains
let para_sender_balance_after =
<$sender_para as $crate::Chain>::account_data_of(sender.clone()).free;
let para_receiver_balance_after =
<$receiver_para as $crate::Chain>::account_data_of(receiver.clone()).free;
let delivery_fees = <$sender_para>::execute_with(|| {
$crate::asset_test_utils::xcm_helpers::teleport_assets_delivery_fees::<
<$sender_xcm_config as xcm_executor::Config>::XcmSender,
>($assets.clone(), fee_asset_item, weight_limit.clone(), beneficiary, para_destination)
});

assert_eq!(para_sender_balance_before - $amount - delivery_fees, para_sender_balance_after);
assert!(para_receiver_balance_after > para_receiver_balance_before);

// Update sender balance
para_sender_balance_before = <$sender_para as $crate::Chain>::account_data_of(sender.clone()).free;
}
)+
}
};
}
/// TODO: backport this macros to polkadot-sdk

#[macro_export]
macro_rules! test_relay_is_trusted_teleporter {
Expand Down Expand Up @@ -215,7 +124,7 @@ macro_rules! test_relay_is_trusted_teleporter {
}

#[macro_export]
macro_rules! test_parachain_is_trusted_teleporter {
macro_rules! test_parachain_is_trusted_teleporter_for_relay {
( $sender_para:ty, $sender_xcm_config:ty, $receiver_relay:ty, $amount:expr ) => {
$crate::paste::paste! {
// init Origin variables
Expand Down
Loading

0 comments on commit 8ec28f9

Please sign in to comment.