diff --git a/.github/workflows/integration-tests-matrix.json b/.github/workflows/integration-tests-matrix.json new file mode 100644 index 0000000000..f5f50521a5 --- /dev/null +++ b/.github/workflows/integration-tests-matrix.json @@ -0,0 +1,10 @@ +[ + { + "name": "asset-hub-kusama", + "package": "asset-hub-kusama-integration-tests" + }, + { + "name": "asset-hub-polkadot", + "package": "asset-hub-polkadot-integration-tests" + } +] diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2b2fa8005a..2f8b9d48a9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,9 +12,39 @@ concurrency: cancel-in-progress: true jobs: - test: - runs-on: ubuntu-22.04 + runtime-matrix: + runs-on: ubuntu-latest + outputs: + runtime: ${{ steps.runtime.outputs.runtime }} + name: Extract runtimes from matrix + steps: + - uses: actions/checkout@v2 + - id: runtime + run: | + TASKS=$(echo $(cat .github/workflows/runtimes-matrix.json) | sed 's/ //g' ) + echo $TASKS + echo "runtime=$TASKS" >> $GITHUB_OUTPUT + integration-test-matrix: + runs-on: ubuntu-latest + outputs: + itest: ${{ steps.itest.outputs.itest }} + name: Extract integration tests from matrix + steps: + - uses: actions/checkout@v2 + - id: itest + run: | + TASKS=$(echo $(cat .github/workflows/integration-tests-matrix.json) | sed 's/ //g' ) + echo $TASKS + echo "itest=$TASKS" >> $GITHUB_OUTPUT + + runtime-test: + needs: [ runtime-matrix ] + continue-on-error: true + runs-on: ubuntu-22.04 + strategy: + matrix: + runtime: ${{ fromJSON(needs.runtime-matrix.outputs.runtime) }} steps: - name: Cancel previous runs uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 # v0.11.0 @@ -58,13 +88,119 @@ jobs: with: shared-key: "fellowship-cache-tests" - - name: Test - run: cargo test --workspace --release --locked -q --features=runtime-metrics,try-runtime + - name: Test ${{ matrix.runtime.name }} + run: cargo test -p ${{ matrix.runtime.package }} --release --locked -q --features=try-runtime env: RUSTFLAGS: "-C debug-assertions -D warnings" - - name: Test all features - run: cargo test --workspace --release --locked -q --features=runtime-benchmarks,runtime-metrics,try-runtime + - name: Test all features ${{ matrix.runtime.name }} + run: cargo test -p ${{ matrix.runtime.package }} --release --locked -q --features=runtime-benchmarks,try-runtime env: RUSTFLAGS: "-C debug-assertions -D warnings" SKIP_WASM_BUILD: 1 + + integration-test: + needs: [ integration-test-matrix ] + continue-on-error: true + runs-on: ubuntu-22.04 + strategy: + matrix: + itest: ${{ fromJSON(needs.integration-test-matrix.outputs.itest) }} + steps: + - name: Cancel previous runs + uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 # v0.11.0 + with: + access_token: ${{ github.token }} + + - name: Install updates and protobuf-compiler + run: sudo apt update && sudo apt install --assume-yes cmake protobuf-compiler + + - name: Free space on the runner + run: | + df -h + sudo apt -y autoremove --purge + sudo apt -y autoclean + sudo rm -rf /usr/share/dotnet + sudo rm -rf /opt/ghc + sudo rm -rf "/usr/local/share/boost" + sudo rm -rf "$AGENT_TOOLSDIRECTORY" + df -h + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + target: wasm32-unknown-unknown + components: rust-src + + - name: Install nightly toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + target: wasm32-unknown-unknown + + - name: Checkout + uses: actions/checkout@v3 + + - name: Fetch cache + uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 # v2.7.0 + with: + shared-key: "fellowship-cache-tests" + + - name: Test ${{ matrix.itest.name }} + run: cargo test -p ${{ matrix.itest.package }} --release --locked -q + env: + RUSTFLAGS: "-C debug-assertions -D warnings" + + build-chain-spec-generator: + runs-on: ubuntu-latest + steps: + - name: Cancel previous runs + uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 # v0.11.0 + with: + access_token: ${{ github.token }} + + - name: Install updates and protobuf-compiler + run: sudo apt update && sudo apt install --assume-yes cmake protobuf-compiler + + - name: Free space on the runner + run: | + df -h + sudo apt -y autoremove --purge + sudo apt -y autoclean + sudo rm -rf /usr/share/dotnet + sudo rm -rf /opt/ghc + sudo rm -rf "/usr/local/share/boost" + sudo rm -rf "$AGENT_TOOLSDIRECTORY" + df -h + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + target: wasm32-unknown-unknown + components: rust-src + + - name: Install nightly toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + target: wasm32-unknown-unknown + + - name: Checkout + uses: actions/checkout@v3 + + - name: Fetch cache + uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 # v2.7.0 + with: + shared-key: "fellowship-cache-tests" + + - name: Build + run: cargo test -p chain-spec-generator --release --locked -q --features=runtime-benchmarks + env: + RUSTFLAGS: "-C debug-assertions -D warnings" + SKIP_WASM_BUILD: 1 \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 90055cab37..5a97afed45 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9463,7 +9463,6 @@ dependencies = [ "frame-system-benchmarking 29.0.0", "frame-system-rpc-runtime-api 27.0.0", "frame-try-runtime 0.35.0", - "hex-literal", "log", "pallet-asset-tx-payment 29.0.0", "pallet-assets 30.0.0", diff --git a/integration-tests/emulated/assets/asset-hub-kusama/Cargo.toml b/integration-tests/emulated/assets/asset-hub-kusama/Cargo.toml index 7eac29d6e4..a5c7a6a016 100644 --- a/integration-tests/emulated/assets/asset-hub-kusama/Cargo.toml +++ b/integration-tests/emulated/assets/asset-hub-kusama/Cargo.toml @@ -35,6 +35,3 @@ integration-tests-common = { path = "../../common" } asset-hub-kusama-runtime = { path = "../../../../system-parachains/asset-hubs/asset-hub-kusama" } kusama-runtime = { package = "staging-kusama-runtime", path = "../../../../relay/kusama" } system-parachains-constants = { path = "../../../../system-parachains/constants" } - -[features] -runtime-benchmarks = [] diff --git a/integration-tests/emulated/assets/asset-hub-polkadot/Cargo.toml b/integration-tests/emulated/assets/asset-hub-polkadot/Cargo.toml index 05110bc672..b7b36538d0 100644 --- a/integration-tests/emulated/assets/asset-hub-polkadot/Cargo.toml +++ b/integration-tests/emulated/assets/asset-hub-polkadot/Cargo.toml @@ -33,6 +33,3 @@ integration-tests-common = { path = "../../common" } asset-hub-polkadot-runtime = { path = "../../../../system-parachains/asset-hubs/asset-hub-polkadot" } polkadot-runtime = { path = "../../../../relay/polkadot" } system-parachains-constants = { path = "../../../../system-parachains/constants" } - -[features] -runtime-benchmarks = [] diff --git a/integration-tests/emulated/chains/Cargo.toml b/integration-tests/emulated/chains/Cargo.toml index e8ee0f6115..71e4becbf8 100644 --- a/integration-tests/emulated/chains/Cargo.toml +++ b/integration-tests/emulated/chains/Cargo.toml @@ -42,8 +42,3 @@ bridge-hub-polkadot-runtime = { path = "../../../system-parachains/bridge-hubs/b bridge-hub-kusama-runtime = { path = "../../../system-parachains/bridge-hubs/bridge-hub-kusama" } # TODO: replace with `emulated-integration-tests-common@X.Y.Z` from `polkadot-sdk` integration-tests-common = { path = "../common" } - -[features] -runtime-benchmarks = [ - "penpal-runtime/runtime-benchmarks", -] diff --git a/relay/kusama/src/lib.rs b/relay/kusama/src/lib.rs index ca902cabd9..b810fd8dbc 100644 --- a/relay/kusama/src/lib.rs +++ b/relay/kusama/src/lib.rs @@ -2746,7 +2746,7 @@ mod init_state_migration { pub struct InitMigrate; impl OnRuntimeUpgrade for InitMigrate { #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, sp_runtime::DispatchError> { + fn pre_upgrade() -> Result, sp_runtime::DispatchError> { use parity_scale_codec::Encode; let migration_should_start = AutoLimits::::get().is_none() && MigrationProcess::::get() == Default::default(); @@ -2778,7 +2778,7 @@ mod init_state_migration { #[cfg(feature = "try-runtime")] fn post_upgrade( - migration_should_start_bytes: Vec, + migration_should_start_bytes: sp_std::vec::Vec, ) -> Result<(), sp_runtime::DispatchError> { use parity_scale_codec::Decode; let migration_should_start: bool = diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs index 6f172e6464..85256e3eda 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs @@ -31,7 +31,7 @@ use assets_common::{ foreign_creators::ForeignCreators, local_and_foreign_assets::{LocalFromLeft, TargetFromLeft}, matching::{FromNetwork, FromSiblingParachain}, - AssetIdForTrustBackedAssetsConvert, LocationForAssetId, + AssetIdForTrustBackedAssetsConvert, }; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; @@ -74,16 +74,16 @@ use parachains_common::{ BlockNumber, Hash, Header, Nonce, Signature, }; use sp_runtime::RuntimeDebug; +pub use system_parachains_constants::SLOT_DURATION; use system_parachains_constants::{ kusama::{consensus::*, currency::*, fee::WeightToFee, snowbridge::EthereumNetwork}, AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, - SLOT_DURATION, }; -use xcm::opaque::v3::Location; +use xcm::latest::prelude::{AssetId, BodyId}; use xcm_config::{ FellowshipLocation, ForeignAssetsConvertedConcreteId, ForeignCreatorsSovereignAccountOf, - GovernanceLocation, KsmLocation, PoolAssetsConvertedConcreteId, - TrustBackedAssetsConvertedConcreteId, TrustBackedAssetsPalletLocation, + GovernanceLocation, KsmLocation, KsmLocationV3, PoolAssetsConvertedConcreteId, + TrustBackedAssetsConvertedConcreteId, TrustBackedAssetsPalletLocationV3, }; #[cfg(any(feature = "std", test))] @@ -92,7 +92,6 @@ pub use sp_runtime::BuildStorage; // Polkadot imports use pallet_xcm::{EnsureXcm, IsVoiceOfBody}; use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; -use xcm::prelude::*; use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; @@ -322,15 +321,25 @@ impl pallet_assets::Config for Runtime { type BenchmarkHelper = (); } -/// Union fungibles implementation for `Assets`` and `ForeignAssets`. +/// Union fungibles implementation for `Assets` and `ForeignAssets`. pub type LocalAndForeignAssets = fungibles::UnionOf< Assets, ForeignAssets, LocalFromLeft< - AssetIdForTrustBackedAssetsConvert, + AssetIdForTrustBackedAssetsConvert, AssetIdForTrustBackedAssets, + xcm::v3::Location, >, - Location, + xcm::v3::Location, + AccountId, +>; + +/// Union fungibles implementation for [`LocalAndForeignAssets`] and `Balances`. +pub type NativeAndAssets = fungible::UnionOf< + Balances, + LocalAndForeignAssets, + TargetFromLeft, + xcm::v3::Location, AccountId, >; @@ -338,21 +347,15 @@ impl pallet_asset_conversion::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = Balance; type HigherPrecisionBalance = sp_core::U256; - type AssetKind = Location; - type Assets = fungible::UnionOf< - Balances, - LocalAndForeignAssets, - TargetFromLeft, - Self::AssetKind, - Self::AccountId, - >; + type AssetKind = xcm::v3::Location; + type Assets = NativeAndAssets; type PoolId = (Self::AssetKind, Self::AssetKind); type PoolLocator = - pallet_asset_conversion::WithFirstAsset; + pallet_asset_conversion::WithFirstAsset; type PoolAssetId = u32; type PoolAssets = PoolAssets; type PoolSetupFee = ConstU128<0>; // Asset class deposit fees are sufficient to prevent spam - type PoolSetupFeeAsset = KsmLocation; + type PoolSetupFeeAsset = KsmLocationV3; type PoolSetupFeeTarget = ResolveAssetTo; type LiquidityWithdrawalFee = LiquidityWithdrawalFee; type LPFee = ConstU32<3>; @@ -362,9 +365,10 @@ impl pallet_asset_conversion::Config for Runtime { type WeightInfo = weights::pallet_asset_conversion::WeightInfo; #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = assets_common::benchmarks::AssetPairFactory< - KsmLocation, + KsmLocationV3, parachain_info::Pallet, - xcm_config::AssetsPalletIndex, + xcm_config::TrustBackedAssetsPalletIndex, + xcm::v3::Location, >; } @@ -385,16 +389,17 @@ pub type ForeignAssetsInstance = pallet_assets::Instance2; impl pallet_assets::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = Balance; - type AssetId = LocationForAssetId; - type AssetIdParameter = LocationForAssetId; + type AssetId = xcm::v3::Location; + type AssetIdParameter = xcm::v3::Location; type Currency = Balances; type CreateOrigin = ForeignCreators< ( - FromSiblingParachain>, + FromSiblingParachain, xcm::v3::Location>, FromNetwork, ), ForeignCreatorsSovereignAccountOf, AccountId, + xcm::v3::Location, >; type ForceOrigin = AssetsForceOrigin; type AssetDeposit = ForeignAssetsAssetDeposit; @@ -775,7 +780,8 @@ impl pallet_collator_selection::Config for Runtime { impl pallet_asset_conversion_tx_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Fungibles = LocalAndForeignAssets; - type OnChargeAssetTransaction = AssetConversionAdapter; + type OnChargeAssetTransaction = + AssetConversionAdapter; } parameter_types! { @@ -1125,18 +1131,18 @@ impl_runtime_apis! { impl pallet_asset_conversion::AssetConversionApi< Block, Balance, - Location, + xcm::v3::Location, > for Runtime { - fn quote_price_exact_tokens_for_tokens(asset1: Location, asset2: Location, amount: Balance, include_fee: bool) -> Option { + fn quote_price_exact_tokens_for_tokens(asset1: xcm::v3::Location, asset2: xcm::v3::Location, amount: Balance, include_fee: bool) -> Option { AssetConversion::quote_price_exact_tokens_for_tokens(asset1, asset2, amount, include_fee) } - fn quote_price_tokens_for_exact_tokens(asset1: Location, asset2: Location, amount: Balance, include_fee: bool) -> Option { + fn quote_price_tokens_for_exact_tokens(asset1: xcm::v3::Location, asset2: xcm::v3::Location, amount: Balance, include_fee: bool) -> Option { AssetConversion::quote_price_tokens_for_exact_tokens(asset1, asset2, amount, include_fee) } - fn get_reserves(asset1: Location, asset2: Location) -> Option<(Balance, Balance)> { + fn get_reserves(asset1: xcm::v3::Location, asset2: xcm::v3::Location) -> Option<(Balance, Balance)> { AssetConversion::get_reserves(asset1, asset2).ok() } } @@ -1301,6 +1307,10 @@ impl_runtime_apis! { ) -> Result, sp_runtime::RuntimeString> { use frame_benchmarking::{Benchmarking, BenchmarkBatch, BenchmarkError}; use sp_storage::TrackedStorageKey; + use xcm::latest::prelude::{ + Asset, Fungible, Here, InteriorLocation, Junction, Junction::*, Location, NetworkId, + NonFungible, Parent, ParentThen, Response, XCM_VERSION, + }; use frame_system_benchmarking::Pallet as SystemBench; impl frame_system_benchmarking::Config for Runtime { @@ -1317,7 +1327,6 @@ impl_runtime_apis! { use cumulus_pallet_session_benchmarking::Pallet as SessionBench; impl cumulus_pallet_session_benchmarking::Config for Runtime {} - use xcm::latest::prelude::*; use xcm_config::{KsmLocation, MaxAssetsIntoHolding}; use pallet_xcm_benchmarks::asset_instance_from; @@ -1354,7 +1363,7 @@ impl_runtime_apis! { } fn set_up_complex_asset_transfer( - ) -> Option<(Assets, u32, Location, Box)> { + ) -> Option<(xcm::v4::Assets, u32, Location, Box)> { // Transfer to Relay some local AH asset (local-reserve-transfer) while paying // fees using teleported native token. // (We don't care that Relay doesn't accept incoming unknown AH local asset) @@ -1385,7 +1394,7 @@ impl_runtime_apis! { ); let transfer_asset: Asset = (asset_location, asset_amount).into(); - let assets: Assets = vec![fee_asset.clone(), transfer_asset].into(); + let assets: xcm::v4::Assets = vec![fee_asset.clone(), transfer_asset].into(); let fee_index = if assets.get(0).unwrap().eq(&fee_asset) { 0 } else { 1 }; // verify transferred successfully @@ -1421,7 +1430,7 @@ impl_runtime_apis! { fn valid_destination() -> Result { Ok(KsmLocation::get()) } - fn worst_case_holding(depositable_count: u32) -> Assets { + fn worst_case_holding(depositable_count: u32) -> xcm::v4::Assets { // A mix of fungible, non-fungible, and concrete assets. let holding_non_fungibles = MaxAssetsIntoHolding::get() / 2 - depositable_count; let holding_fungibles = holding_non_fungibles.saturating_sub(1); @@ -1486,7 +1495,7 @@ impl_runtime_apis! { (0u64, Response::Version(Default::default())) } - fn worst_case_asset_exchange() -> Result<(Assets, Assets), BenchmarkError> { + fn worst_case_asset_exchange() -> Result<(xcm::v4::Assets, xcm::v4::Assets), BenchmarkError> { Err(BenchmarkError::Skip) } @@ -1503,9 +1512,9 @@ impl_runtime_apis! { Ok(KsmLocation::get()) } - fn claimable_asset() -> Result<(Location, Location, Assets), BenchmarkError> { + fn claimable_asset() -> Result<(Location, Location, xcm::v4::Assets), BenchmarkError> { let origin = KsmLocation::get(); - let assets: Assets = (AssetId(KsmLocation::get()), 1_000 * UNITS).into(); + let assets: xcm::v4::Assets = (AssetId(KsmLocation::get()), 1_000 * UNITS).into(); let ticket = Location { parents: 0, interior: Here }; Ok((origin, ticket, assets)) } @@ -1550,7 +1559,7 @@ impl_runtime_apis! { let bridged_asset_hub = xcm_config::bridging::to_polkadot::AssetHubPolkadot::get(); let _ = PolkadotXcm::force_xcm_version( RuntimeOrigin::root(), - Box::new(bridged_asset_hub), + Box::new(bridged_asset_hub.clone()), XCM_VERSION, ).map_err(|e| { log::error!( @@ -1616,6 +1625,7 @@ parameter_types! { impl pallet_state_trie_migration::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; + type RuntimeHoldReason = RuntimeHoldReason; type SignedDepositPerItem = MigrationSignedDepositPerItem; type SignedDepositBase = MigrationSignedDepositBase; // An origin that can control the whole pallet: should be Root, or a part of your council. diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs index 6f9a96e93b..1a385f593a 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs @@ -55,13 +55,17 @@ use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; parameter_types! { pub const KsmLocation: Location = Location::parent(); + pub const KsmLocationV3: xcm::v3::Location = xcm::v3::Location::parent(); pub const RelayNetwork: Option = Some(NetworkId::Kusama); pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())].into(); pub UniversalLocationNetworkId: NetworkId = UniversalLocation::get().global_consensus().unwrap(); - pub AssetsPalletIndex: u32 = ::index() as u32; - pub TrustBackedAssetsPalletLocation: Location = PalletInstance(AssetsPalletIndex::get() as u8).into(); + + pub TrustBackedAssetsPalletIndex: u8 = ::index() as u8; + pub TrustBackedAssetsPalletLocation: Location = PalletInstance(TrustBackedAssetsPalletIndex::get()).into(); + pub TrustBackedAssetsPalletLocationV3: xcm::v3::Location = xcm::v3::Junction::PalletInstance(TrustBackedAssetsPalletIndex::get()).into(); + pub ForeignAssetsPalletLocation: Location = PalletInstance(::index() as u8).into(); pub PoolAssetsPalletLocation: Location = @@ -94,7 +98,7 @@ pub type LocationToAccountId = ( ); /// Means for transacting the native currency on this chain. -pub type CurrencyTransactor = FungibleAdapter< +pub type FungibleTransactor = FungibleAdapter< // Use this currency: Balances, // Use this currency when it is a fungible asset matching the given location or name: @@ -182,7 +186,7 @@ pub type PoolFungiblesTransactor = FungiblesAdapter< /// Means for transacting assets on this chain. pub type AssetTransactors = - (CurrencyTransactor, FungiblesTransactor, ForeignFungiblesTransactor, PoolFungiblesTransactor); + (FungibleTransactor, FungiblesTransactor, ForeignFungiblesTransactor, PoolFungiblesTransactor); /// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, /// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can @@ -653,9 +657,9 @@ pub type ForeignCreatorsSovereignAccountOf = ( /// Simple conversion of `u32` into an `AssetId` for use in benchmarking. pub struct XcmBenchmarkHelper; #[cfg(feature = "runtime-benchmarks")] -impl pallet_assets::BenchmarkHelper for XcmBenchmarkHelper { - fn create_asset_id_parameter(id: u32) -> Location { - Location { parents: 1, interior: Parachain(id).into() } +impl pallet_assets::BenchmarkHelper for XcmBenchmarkHelper { + fn create_asset_id_parameter(id: u32) -> xcm::v3::Location { + xcm::v3::Location::new(1, xcm::v3::Junction::Parachain(id)) } } diff --git a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs index 124fcb4f9f..1469b385de 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs @@ -27,7 +27,7 @@ use asset_hub_kusama_runtime::{ AllPalletsWithoutSystem, AssetDeposit, Assets, Balances, ExistentialDeposit, ForeignAssets, ForeignAssetsInstance, MetadataDepositBase, MetadataDepositPerByte, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, SessionKeys, - ToPolkadotXcmRouterInstance, TrustBackedAssetsInstance, XcmpQueue, + ToPolkadotXcmRouterInstance, TrustBackedAssetsInstance, XcmpQueue, SLOT_DURATION, }; use asset_test_utils::{ test_cases_over_bridge::TestBridgingConfig, CollatorSessionKey, CollatorSessionKeys, ExtBuilder, @@ -40,16 +40,21 @@ use frame_support::{ weights::{Weight, WeightToFee as WeightToFeeT}, }; use parachains_common::{AccountId, AssetIdForTrustBackedAssets, AuraId, Balance}; +use parachains_runtimes_test_utils::SlotDurations; +use sp_consensus_aura::SlotDuration; use sp_runtime::traits::MaybeEquivalence; -use system_parachains_constants::kusama::fee::WeightToFee; -use xcm::latest::prelude::*; -use xcm_executor::traits::{Identity, JustTry, WeightTrader}; +use system_parachains_constants::kusama::{ + consensus::RELAY_CHAIN_SLOT_DURATION_MILLIS, fee::WeightToFee, +}; +use xcm::latest::prelude::{Assets as XcmAssets, *}; +use xcm_builder::V4V3LocationConverter; +use xcm_executor::traits::{JustTry, WeightTrader}; const ALICE: [u8; 32] = [1u8; 32]; const SOME_ASSET_ADMIN: [u8; 32] = [5u8; 32]; -type AssetIdForTrustBackedAssetsConvert = - assets_common::AssetIdForTrustBackedAssetsConvert; +type AssetIdForTrustBackedAssetsConvertLatest = + assets_common::AssetIdForTrustBackedAssetsConvertLatest; type RuntimeHelper = asset_test_utils::RuntimeHelper; @@ -69,6 +74,13 @@ fn collator_session_keys() -> CollatorSessionKeys { ) } +fn slot_durations() -> SlotDurations { + SlotDurations { + relay: SlotDuration::from_millis(RELAY_CHAIN_SLOT_DURATION_MILLIS.into()), + para: SlotDuration::from_millis(SLOT_DURATION), + } +} + #[test] fn test_ed_is_one_hundredth_of_relay() { ExtBuilder::::default() @@ -118,7 +130,7 @@ fn test_asset_xcm_trader() { // get asset id as location let asset_location = - AssetIdForTrustBackedAssetsConvert::convert_back(&local_asset_id).unwrap(); + AssetIdForTrustBackedAssetsConvertLatest::convert_back(&local_asset_id).unwrap(); // Set Alice as block author, who will receive fees RuntimeHelper::run_to_block(2, AccountId::from(ALICE)); @@ -136,7 +148,8 @@ fn test_asset_xcm_trader() { // Lets pay with: asset_amount_needed + asset_amount_extra let asset_amount_extra = 100_u128; - let asset: Asset = (asset_location, asset_amount_needed + asset_amount_extra).into(); + let asset: Asset = + (asset_location.clone(), asset_amount_needed + asset_amount_extra).into(); let mut trader = ::Trader::new(); let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None }; @@ -201,12 +214,13 @@ fn test_asset_xcm_trader_with_refund() { // We are going to buy 4e9 weight let bought = Weight::from_parts(4_000_000_000u64, 0); - let asset_location = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap(); + let asset_location = + AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap(); // lets calculate amount needed let amount_bought = WeightToFee::weight_to_fee(&bought); - let asset: Asset = (asset_location, amount_bought).into(); + let asset: Asset = (asset_location.clone(), amount_bought).into(); // Make sure buy_weight does not return an error assert_ok!(trader.buy_weight(bought, asset.clone().into(), &ctx)); @@ -273,7 +287,8 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() { // We are going to buy small amount let bought = Weight::from_parts(50_000_000u64, 0); - let asset_location = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap(); + let asset_location = + AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap(); let amount_bought = WeightToFee::weight_to_fee(&bought); @@ -325,7 +340,8 @@ fn test_that_buying_ed_refund_does_not_refund() { // We are gonna buy ED let bought = Weight::from_parts(ExistentialDeposit::get().try_into().unwrap(), 0); - let asset_location = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap(); + let asset_location = + AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap(); let amount_bought = WeightToFee::weight_to_fee(&bought); @@ -336,7 +352,7 @@ fn test_that_buying_ed_refund_does_not_refund() { // We know we will have to buy at least ED, so lets make sure first it will // fail with a payment of less than ED - let asset: Asset = (asset_location, amount_bought).into(); + let asset: Asset = (asset_location.clone(), amount_bought).into(); assert_noop!(trader.buy_weight(bought, asset.into(), &ctx), XcmError::TooExpensive); // Now lets buy ED at least @@ -401,7 +417,8 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { // lets calculate amount needed let asset_amount_needed = WeightToFee::weight_to_fee(&bought); - let asset_location = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap(); + let asset_location = + AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap(); let asset: Asset = (asset_location, asset_amount_needed).into(); @@ -433,8 +450,10 @@ fn test_assets_balances_api_works() { .build() .execute_with(|| { let local_asset_id = 1; - let foreign_asset_id_location = - Location { parents: 1, interior: X2(Parachain(1234), GeneralIndex(12345)) }; + let foreign_asset_id_location = xcm::v3::Location::new( + 1, + [xcm::v3::Junction::Parachain(1234), xcm::v3::Junction::GeneralIndex(12345)], + ); // check before assert_eq!(Assets::balance(local_asset_id, AccountId::from(ALICE)), 0); @@ -445,7 +464,7 @@ fn test_assets_balances_api_works() { assert_eq!(Balances::free_balance(AccountId::from(ALICE)), 0); assert!(Runtime::query_account_balances(AccountId::from(ALICE)) .unwrap() - .try_as::() + .try_as::() .unwrap() .is_none()); @@ -501,7 +520,7 @@ fn test_assets_balances_api_works() { ); assert_eq!(Balances::free_balance(AccountId::from(ALICE)), some_currency); - let result: Assets = Runtime::query_account_balances(AccountId::from(ALICE)) + let result: XcmAssets = Runtime::query_account_balances(AccountId::from(ALICE)) .unwrap() .try_into() .unwrap(); @@ -516,13 +535,13 @@ fn test_assets_balances_api_works() { ))); // check trusted asset assert!(result.inner().iter().any(|asset| asset.eq(&( - AssetIdForTrustBackedAssetsConvert::convert_back(&local_asset_id).unwrap(), + AssetIdForTrustBackedAssetsConvertLatest::convert_back(&local_asset_id).unwrap(), minimum_asset_balance ) .into()))); // check foreign asset assert!(result.inner().iter().any(|asset| asset.eq(&( - Identity::convert_back(&foreign_asset_id_location).unwrap(), + V4V3LocationConverter::convert_back(&foreign_asset_id_location).unwrap(), 6 * foreign_asset_minimum_asset_balance ) .into()))); @@ -537,6 +556,7 @@ asset_test_utils::include_teleports_for_native_asset_works!( WeightToFee, ParachainSystem, collator_session_keys(), + slot_durations(), ExistentialDeposit::get(), Box::new(|runtime_event_encoded: Vec| { match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) { @@ -557,6 +577,7 @@ asset_test_utils::include_teleports_for_foreign_assets_works!( ForeignCreatorsSovereignAccountOf, ForeignAssetsInstance, collator_session_keys(), + slot_durations(), ExistentialDeposit::get(), Box::new(|runtime_event_encoded: Vec| { match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) { @@ -593,7 +614,7 @@ asset_test_utils::include_asset_transactor_transfer_with_pallet_assets_instance_ XcmConfig, TrustBackedAssetsInstance, AssetIdForTrustBackedAssets, - AssetIdForTrustBackedAssetsConvert, + AssetIdForTrustBackedAssetsConvertLatest, collator_session_keys(), ExistentialDeposit::get(), 12345, @@ -610,11 +631,14 @@ asset_test_utils::include_asset_transactor_transfer_with_pallet_assets_instance_ Runtime, XcmConfig, ForeignAssetsInstance, - Location, + xcm::v3::Location, JustTry, collator_session_keys(), ExistentialDeposit::get(), - Location { parents: 1, interior: X2(Parachain(1313), GeneralIndex(12345)) }, + xcm::v3::Location::new( + 1, + [xcm::v3::Junction::Parachain(1313), xcm::v3::Junction::GeneralIndex(12345)] + ), Box::new(|| { assert!(Assets::asset_ids().collect::>().is_empty()); }), @@ -629,8 +653,8 @@ asset_test_utils::include_create_and_manage_foreign_assets_for_local_consensus_p WeightToFee, ForeignCreatorsSovereignAccountOf, ForeignAssetsInstance, - Location, - JustTry, + xcm::v3::Location, + V4V3LocationConverter, collator_session_keys(), ExistentialDeposit::get(), AssetDeposit::get(), @@ -679,6 +703,7 @@ fn limited_reserve_transfer_assets_for_native_asset_to_asset_hub_polkadot_works( LocationToAccountId, >( collator_session_keys(), + slot_durations(), ExistentialDeposit::get(), AccountId::from(ALICE), Box::new(|runtime_event_encoded: Vec| { @@ -701,7 +726,7 @@ fn limited_reserve_transfer_assets_for_native_asset_to_asset_hub_polkadot_works( } #[test] -fn receive_reserve_asset_deposited_roc_from_asset_hub_polkadot_works() { +fn receive_reserve_asset_deposited_dot_from_asset_hub_polkadot_works() { const BLOCK_AUTHOR_ACCOUNT: [u8; 32] = [13; 32]; asset_test_utils::test_cases_over_bridge::receive_reserve_asset_deposited_from_different_consensus_works::< Runtime, @@ -714,13 +739,13 @@ fn receive_reserve_asset_deposited_roc_from_asset_hub_polkadot_works() { ExistentialDeposit::get(), AccountId::from([73; 32]), AccountId::from(BLOCK_AUTHOR_ACCOUNT), - // receiving ROCs - (Location { parents: 2, interior: X1(GlobalConsensus(Polkadot)) }, 1000000000000, 1_000_000_000), + // receiving DOTs + (xcm::v3::Location::new(2, [xcm::v3::Junction::GlobalConsensus(xcm::v3::NetworkId::Polkadot)]), 1000000000000, 1_000_000_000), bridging_to_asset_hub_polkadot, ( - X1(PalletInstance(bp_bridge_hub_kusama::WITH_BRIDGE_KUSAMA_TO_POLKADOT_MESSAGES_PALLET_INDEX)), + PalletInstance(bp_bridge_hub_kusama::WITH_BRIDGE_KUSAMA_TO_POLKADOT_MESSAGES_PALLET_INDEX).into(), GlobalConsensus(Polkadot), - X1(Parachain(1000)) + Parachain(1000).into() ) ) } diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index 121b82682a..a5a1a7c85b 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -62,11 +62,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); mod weights; pub mod xcm_config; -use assets_common::{ - foreign_creators::ForeignCreators, - matching::{FromNetwork, FromSiblingParachain}, - LocationForAssetId, -}; +use assets_common::{foreign_creators::ForeignCreators, matching::{FromNetwork, FromSiblingParachain}}; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use sp_api::impl_runtime_apis; @@ -320,16 +316,17 @@ pub type ForeignAssetsInstance = pallet_assets::Instance2; impl pallet_assets::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = Balance; - type AssetId = LocationForAssetId; - type AssetIdParameter = LocationForAssetId; + type AssetId = xcm::v3::Location; + type AssetIdParameter = xcm::v3::Location; type Currency = Balances; type CreateOrigin = ForeignCreators< ( - FromSiblingParachain>, + FromSiblingParachain, xcm::v3::Location>, FromNetwork, ), ForeignCreatorsSovereignAccountOf, AccountId, + xcm::v3::Location, >; type ForceOrigin = AssetsForceOrigin; type AssetDeposit = ForeignAssetsAssetDeposit; @@ -1237,7 +1234,7 @@ impl_runtime_apis! { } fn set_up_complex_asset_transfer( - ) -> Option<(Assets, u32, Location, Box)> { + ) -> Option<(xcm::v4::Assets, u32, Location, Box)> { // Transfer to Relay some local AH asset (local-reserve-transfer) while paying // fees using teleported native token. // (We don't care that Relay doesn't accept incoming unknown AH local asset) @@ -1268,7 +1265,7 @@ impl_runtime_apis! { ); let transfer_asset: Asset = (asset_location, asset_amount).into(); - let assets: Assets = vec![fee_asset.clone(), transfer_asset].into(); + let assets: xcm::v4::Assets = vec![fee_asset.clone(), transfer_asset].into(); let fee_index = if assets.get(0).unwrap().eq(&fee_asset) { 0 } else { 1 }; // verify transferred successfully diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs index d09a4a7e1e..9bbb9044c7 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs @@ -607,9 +607,9 @@ pub type ForeignCreatorsSovereignAccountOf = ( /// Simple conversion of `u32` into an `AssetId` for use in benchmarking. pub struct XcmBenchmarkHelper; #[cfg(feature = "runtime-benchmarks")] -impl pallet_assets::BenchmarkHelper for XcmBenchmarkHelper { - fn create_asset_id_parameter(id: u32) -> Location { - Location { parents: 1, interior: Parachain(id).into() } +impl pallet_assets::BenchmarkHelper for XcmBenchmarkHelper { + fn create_asset_id_parameter(id: u32) -> xcm::v3::Location { + xcm::v3::Location::new(1, xcm::v3::Junction::Parachain(id)) } } diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs index ed41a5264c..f1892af8ff 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs @@ -726,7 +726,7 @@ fn limited_reserve_transfer_assets_for_native_asset_to_asset_hub_kusama_works() ) } #[test] -fn receive_reserve_asset_deposited_roc_from_asset_hub_kusama_works() { +fn receive_reserve_asset_deposited_ksm_from_asset_hub_kusama_works() { const BLOCK_AUTHOR_ACCOUNT: [u8; 32] = [13; 32]; asset_test_utils::test_cases_over_bridge::receive_reserve_asset_deposited_from_different_consensus_works::< Runtime, @@ -739,7 +739,7 @@ fn receive_reserve_asset_deposited_roc_from_asset_hub_kusama_works() { ExistentialDeposit::get(), AccountId::from([73; 32]), AccountId::from(BLOCK_AUTHOR_ACCOUNT), - // receiving ROCs + // receiving KSMs (Location { parents: 2, interior: X1(GlobalConsensus(Kusama)) }, 1000000000000, 1_000_000_000), bridging_to_asset_hub_kusama, (