Skip to content

Commit

Permalink
Fix some cargo test compilation issues
Browse files Browse the repository at this point in the history
  • Loading branch information
raynaudoe committed Sep 19, 2024
1 parent e1fd37c commit 871de69
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 114 deletions.
2 changes: 1 addition & 1 deletion relay/paseo/tests/asset_rate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! AssetRate pallet instance tests.
use frame_support::traits::tokens::ConversionFromAssetBalance;
use polkadot_runtime::AssetRateWithNative;
use paseo_runtime::AssetRateWithNative;
use polkadot_runtime_common::impls::VersionedLocatableAsset;
use xcm::prelude::*;

Expand Down
223 changes: 112 additions & 111 deletions system-parachains/asset-hub-paseo/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ use asset_hub_paseo_runtime::{
xcm_config::{
bridging::self,
CheckingAccount, DotLocation, ForeignCreatorsSovereignAccountOf, LocationToAccountId,
RelayTreasuryLocation, RelayTreasuryPalletAccount,
RelayTreasuryLocation, RelayTreasuryPalletAccount, StakingPot,
TrustBackedAssetsPalletLocation, XcmConfig,
},
AllPalletsWithoutSystem, AssetConversion, AssetDeposit, Assets, Balances, ExistentialDeposit,
ForeignAssets, ForeignAssetsInstance, MetadataDepositBase, MetadataDepositPerByte,
ParachainSystem, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, SessionKeys,
TrustBackedAssetsInstance, XcmpQueue,
TrustBackedAssetsInstance, XcmpQueue, SLOT_DURATION,
};
use asset_test_utils::{
CollatorSessionKey, CollatorSessionKeys, ExtBuilder,
Expand All @@ -42,7 +42,7 @@ use sp_consensus_aura::SlotDuration;
use sp_runtime::traits::MaybeEquivalence;
use sp_std::ops::Mul;
use system_parachains_constants::{
kusama::consensus::RELAY_CHAIN_SLOT_DURATION_MILLIS, paseo::fee::WeightToFee,
paseo::consensus::RELAY_CHAIN_SLOT_DURATION_MILLIS, paseo::fee::WeightToFee,
};
use xcm::latest::prelude::{Assets as XcmAssets, *};
use xcm_builder::WithLatestLocationConverter;
Expand Down Expand Up @@ -379,20 +379,20 @@ asset_test_utils::include_create_and_manage_foreign_assets_for_local_consensus_p
})
);

fn bridging_to_asset_hub_kusama() -> TestBridgingConfig {
PolkadotXcm::force_xcm_version(
RuntimeOrigin::root(),
Box::new(bridging::to_kusama::AssetHubKusama::get()),
XCM_VERSION,
)
.expect("version saved!");
TestBridgingConfig {
bridged_network: bridging::to_kusama::KusamaNetwork::get(),
local_bridge_hub_para_id: bridging::SiblingBridgeHubParaId::get(),
local_bridge_hub_location: bridging::SiblingBridgeHub::get(),
bridged_target_location: bridging::to_kusama::AssetHubKusama::get(),
}
}
// fn bridging_to_asset_hub_kusama() -> TestBridgingConfig {
// PolkadotXcm::force_xcm_version(
// RuntimeOrigin::root(),
// Box::new(bridging::to_kusama::AssetHubKusama::get()),
// XCM_VERSION,
// )
// .expect("version saved!");
// TestBridgingConfig {
// bridged_network: bridging::to_kusama::KusamaNetwork::get(),
// local_bridge_hub_para_id: bridging::SiblingBridgeHubParaId::get(),
// local_bridge_hub_location: bridging::SiblingBridgeHub::get(),
// bridged_target_location: bridging::to_kusama::AssetHubKusama::get(),
// }
// }

#[test]
fn limited_reserve_transfer_assets_for_native_asset_to_asset_hub_kusama_works() {
Expand Down Expand Up @@ -420,9 +420,9 @@ fn limited_reserve_transfer_assets_for_native_asset_to_asset_hub_kusama_works()
_ => None,
}
}),
bridging_to_asset_hub_kusama,
//bridging_to_asset_hub_kusama,
WeightLimit::Unlimited,
Some(XcmBridgeHubRouterFeeAssetId::get()),
//Some(XcmBridgeHubRouterFeeAssetId::get()),
Some(RelayTreasuryPalletAccount::get()),
)
}
Expand All @@ -433,6 +433,7 @@ fn receive_reserve_asset_deposited_ksm_from_asset_hub_kusama_fees_paid_by_pool_s
let block_author_account = AccountId::from(BLOCK_AUTHOR_ACCOUNT);
let staking_pot = StakingPot::get();


let foreign_asset_id_location =
xcm::v3::Location::new(2, [xcm::v3::Junction::GlobalConsensus(xcm::v3::NetworkId::Kusama)]);
let foreign_asset_id_minimum_balance = 1_000_000_000;
Expand Down Expand Up @@ -460,7 +461,7 @@ fn receive_reserve_asset_deposited_ksm_from_asset_hub_kusama_fees_paid_by_pool_s
// staking pot account for collecting local native fees from `BuyExecution`
let _ = Balances::force_set_balance(RuntimeOrigin::root(), StakingPot::get().into(), ExistentialDeposit::get());
// prepare bridge configuration
bridging_to_asset_hub_kusama()
//bridging_to_asset_hub_kusama()
},
(
[PalletInstance(bp_bridge_hub_paseo::WITH_BRIDGE_POLKAPAS_TO_KUSAMA_MESSAGES_PALLET_INDEX)].into(),
Expand Down Expand Up @@ -496,62 +497,62 @@ fn receive_reserve_asset_deposited_ksm_from_asset_hub_kusama_fees_paid_by_pool_s
)
}

#[test]
fn receive_reserve_asset_deposited_ksm_from_asset_hub_kusama_fees_paid_by_sufficient_asset_works() {
const BLOCK_AUTHOR_ACCOUNT: [u8; 32] = [13; 32];
let block_author_account = AccountId::from(BLOCK_AUTHOR_ACCOUNT);
let staking_pot = <pallet_collator_selection::Pallet<Runtime>>::account_id();

let foreign_asset_id_location =
xcm::v3::Location::new(2, [xcm::v3::Junction::GlobalConsensus(xcm::v3::NetworkId::Kusama)]);
let foreign_asset_id_minimum_balance = 1_000_000_000;
// sovereign account as foreign asset owner (can be whoever for this scenario)
let foreign_asset_owner = LocationToAccountId::convert_location(&Location::parent()).unwrap();
let foreign_asset_create_params =
(foreign_asset_owner, foreign_asset_id_location, foreign_asset_id_minimum_balance);

asset_test_utils::test_cases_over_bridge::receive_reserve_asset_deposited_from_different_consensus_works::<
Runtime,
AllPalletsWithoutSystem,
XcmConfig,
ForeignAssetsInstance,
>(
collator_session_keys().add(collator_session_key(BLOCK_AUTHOR_ACCOUNT)),
ExistentialDeposit::get(),
AccountId::from([73; 32]),
block_author_account.clone(),
// receiving KSMs
foreign_asset_create_params,
1000000000000,
bridging_to_asset_hub_kusama,
(
PalletInstance(bp_bridge_hub_paseo::WITH_BRIDGE_POLKAPAS_TO_KUSAMA_MESSAGES_PALLET_INDEX).into(),
GlobalConsensus(Kusama),
Parachain(1000).into()
),
|| {
// check block author before
assert_eq!(
ForeignAssets::balance(
foreign_asset_id_location,
&block_author_account
),
0
);
},
|| {
// `TakeFirstAssetTrader` puts fees to the block author
assert!(
ForeignAssets::balance(
foreign_asset_id_location,
&block_author_account
) > 0
);
// nothing adds fees to stakting_pot (e.g. `SwapFirstAssetTrader`, ...)
assert_eq!(Balances::free_balance(&staking_pot), 0);
}
)
}
// #[test]
// fn receive_reserve_asset_deposited_ksm_from_asset_hub_kusama_fees_paid_by_sufficient_asset_works() {
// const BLOCK_AUTHOR_ACCOUNT: [u8; 32] = [13; 32];
// let block_author_account = AccountId::from(BLOCK_AUTHOR_ACCOUNT);
// let staking_pot = <pallet_collator_selection::Pallet<Runtime>>::account_id();
//
// let foreign_asset_id_location =
// xcm::v3::Location::new(2, [xcm::v3::Junction::GlobalConsensus(xcm::v3::NetworkId::Kusama)]);
// let foreign_asset_id_minimum_balance = 1_000_000_000;
// // sovereign account as foreign asset owner (can be whoever for this scenario)
// let foreign_asset_owner = LocationToAccountId::convert_location(&Location::parent()).unwrap();
// let foreign_asset_create_params =
// (foreign_asset_owner, foreign_asset_id_location, foreign_asset_id_minimum_balance);
//
// asset_test_utils::test_cases_over_bridge::receive_reserve_asset_deposited_from_different_consensus_works::<
// Runtime,
// AllPalletsWithoutSystem,
// XcmConfig,
// ForeignAssetsInstance,
// >(
// collator_session_keys().add(collator_session_key(BLOCK_AUTHOR_ACCOUNT)),
// ExistentialDeposit::get(),
// AccountId::from([73; 32]),
// block_author_account.clone(),
// // receiving KSMs
// foreign_asset_create_params,
// 1000000000000,
// //bridging_to_asset_hub_kusama,
// (
// PalletInstance(bp_bridge_hub_paseo::WITH_BRIDGE_POLKAPAS_TO_KUSAMA_MESSAGES_PALLET_INDEX).into(),
// GlobalConsensus(Kusama),
// Parachain(1000).into()
// ),
// || {
// // check block author before
// assert_eq!(
// ForeignAssets::balance(
// foreign_asset_id_location,
// &block_author_account
// ),
// 0
// );
// },
// || {
// // `TakeFirstAssetTrader` puts fees to the block author
// assert!(
// ForeignAssets::balance(
// foreign_asset_id_location,
// &block_author_account
// ) > 0
// );
// // nothing adds fees to stakting_pot (e.g. `SwapFirstAssetTrader`, ...)
// assert_eq!(Balances::free_balance(&staking_pot), 0);
// }
// )
// }

#[test]
fn reserve_transfer_native_asset_to_non_teleport_para_works() {
Expand Down Expand Up @@ -583,27 +584,27 @@ fn reserve_transfer_native_asset_to_non_teleport_para_works() {
);
}

#[test]
fn report_bridge_status_from_xcm_bridge_router_for_kusama_works() {
asset_test_utils::test_cases_over_bridge::report_bridge_status_from_xcm_bridge_router_works::<
Runtime,
AllPalletsWithoutSystem,
XcmConfig,
LocationToAccountId,
ToKusamaXcmRouterInstance,
>(
collator_session_keys(),
bridging_to_asset_hub_kusama,
|| {
Decode::decode(&mut &bp_asset_hub_paseo::CongestedMessage::get().encode()[..])
.unwrap()
},
|| {
Decode::decode(&mut &bp_asset_hub_paseo::UncongestedMessage::get().encode()[..])
.unwrap()
},
)
}
// #[test]
// fn report_bridge_status_from_xcm_bridge_router_for_kusama_works() {
// asset_test_utils::test_cases_over_bridge::report_bridge_status_from_xcm_bridge_router_works::<
// Runtime,
// AllPalletsWithoutSystem,
// XcmConfig,
// LocationToAccountId,
// //ToKusamaXcmRouterInstance,
// >(
// collator_session_keys(),
// //bridging_to_asset_hub_kusama,
// || {
// Decode::decode(&mut &bp_asset_hub_paseo::CongestedMessage::get().encode()[..])
// .unwrap()
// },
// || {
// Decode::decode(&mut &bp_asset_hub_paseo::UncongestedMessage::get().encode()[..])
// .unwrap()
// },
// )
// }

#[test]
fn test_report_bridge_status_call_compatibility() {
Expand All @@ -624,20 +625,20 @@ fn test_report_bridge_status_call_compatibility() {
)
}

#[test]
fn check_sane_weight_report_bridge_status() {
use pallet_xcm_bridge_hub_router::WeightInfo;
let actual = <Runtime as pallet_xcm_bridge_hub_router::Config<
ToKusamaXcmRouterInstance,
>>::WeightInfo::report_bridge_status();
let max_weight = bp_asset_hub_paseo::XcmBridgeHubRouterTransactCallMaxWeight::get();
assert!(
actual.all_lte(max_weight),
"max_weight: {:?} should be adjusted to actual {:?}",
max_weight,
actual
);
}
// #[test]
// fn check_sane_weight_report_bridge_status() {
// use pallet_xcm_bridge_hub_router::WeightInfo;
// let actual = <Runtime as pallet_xcm_bridge_hub_router::Config<
// ToKusamaXcmRouterInstance,
// >>::WeightInfo::report_bridge_status();
// let max_weight = bp_asset_hub_paseo::XcmBridgeHubRouterTransactCallMaxWeight::get();
// assert!(
// actual.all_lte(max_weight),
// "max_weight: {:?} should be adjusted to actual {:?}",
// max_weight,
// actual
// );
// }

#[test]
fn change_xcm_bridge_hub_router_base_fee_by_governance_works() {
Expand Down
13 changes: 11 additions & 2 deletions system-parachains/bridge-hub-paseo/tests/snowbridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use bridge_hub_paseo_runtime::{
};
use codec::{Decode, Encode};
use cumulus_primitives_core::XcmError::{FailedToTransactAsset, TooExpensive};
use frame_support::{parameter_types, traits::Contains};
use frame_support::{parameter_types, traits::Contains, assert_err, assert_ok};
use parachains_common::{AccountId, AuraId, Balance};
pub use parachains_runtimes_test_utils::test_cases::change_storage_constant_by_governance_works;
use snowbridge_pallet_ethereum_client::WeightInfo;
Expand All @@ -39,7 +39,16 @@ use sp_runtime::{
};
use xcm::latest::prelude::*;
use xcm_builder::HandleFee;
use xcm_executor::traits::{FeeManager, FeeReason};
use xcm_executor::{
traits::{FeeManager, FeeReason},
XcmExecutor,
};
use parachains_runtimes_test_utils::{
AccountIdOf, CollatorSessionKeys, ExtBuilder, XcmReceivedFrom,
};

type RuntimeHelper<Runtime, AllPalletsWithoutSystem = ()> =
parachains_runtimes_test_utils::RuntimeHelper<Runtime, AllPalletsWithoutSystem>;

parameter_types! {
pub const DefaultBridgeHubEthereumBaseFee: Balance = 2_750_872_500_000;
Expand Down

0 comments on commit 871de69

Please sign in to comment.