diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/treasury.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/treasury.rs index 69111d38bcac3..3064e94cc9191 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/treasury.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/treasury.rs @@ -81,7 +81,7 @@ fn spend_roc_on_asset_hub() { })), }); - // Dispatched from Root to `despatch_as` `Signed(treasury_account)`. + // Dispatched from Root to `dispatch_as` `Signed(treasury_account)`. assert_ok!(teleport_call.dispatch(root)); assert_expected_events!( diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs index 1e8a2be4a7779..eae97549f6fb0 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs @@ -21,8 +21,8 @@ use asset_hub_rococo_runtime::{ xcm_config, xcm_config::{ bridging, AssetFeeAsExistentialDepositMultiplierFeeCharger, CheckingAccount, - ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, LocationToAccountId, StakingPot, - TokenLocation, TrustBackedAssetsPalletLocation, XcmConfig, + ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, GovernanceLocation, + LocationToAccountId, StakingPot, TokenLocation, TrustBackedAssetsPalletLocation, XcmConfig, }, AllPalletsWithoutSystem, AssetConversion, AssetDeposit, Assets, Balances, CollatorSelection, ExistentialDeposit, ForeignAssets, ForeignAssetsInstance, MetadataDepositBase, @@ -31,13 +31,13 @@ use asset_hub_rococo_runtime::{ }; use asset_test_utils::{ test_cases_over_bridge::TestBridgingConfig, CollatorSessionKey, CollatorSessionKeys, - ExtBuilder, SlotDurations, + ExtBuilder, GovernanceOrigin, SlotDurations, }; use codec::{Decode, Encode}; use core::ops::Mul; use cumulus_primitives_utility::ChargeWeightInFungibles; use frame_support::{ - assert_noop, assert_ok, + assert_noop, assert_ok, parameter_types, traits::{ fungible::{Inspect, Mutate}, fungibles::{ @@ -60,6 +60,10 @@ use xcm_runtime_apis::conversions::LocationToAccountHelper; const ALICE: [u8; 32] = [1u8; 32]; const SOME_ASSET_ADMIN: [u8; 32] = [5u8; 32]; +parameter_types! { + pub Governance: GovernanceOrigin = GovernanceOrigin::Location(GovernanceLocation::get()); +} + type AssetIdForTrustBackedAssetsConvert = assets_common::AssetIdForTrustBackedAssetsConvert; @@ -1334,7 +1338,7 @@ fn change_xcm_bridge_hub_router_byte_fee_by_governance_works() { >( collator_session_keys(), 1000, - Box::new(|call| RuntimeCall::System(call).encode()), + Governance::get(), || { ( bridging::XcmBridgeHubRouterByteFee::key().to_vec(), @@ -1360,7 +1364,7 @@ fn change_xcm_bridge_hub_router_base_fee_by_governance_works() { >( collator_session_keys(), 1000, - Box::new(|call| RuntimeCall::System(call).encode()), + Governance::get(), || { log::error!( target: "bridges::estimate", @@ -1392,7 +1396,7 @@ fn change_xcm_bridge_hub_ethereum_base_fee_by_governance_works() { >( collator_session_keys(), 1000, - Box::new(|call| RuntimeCall::System(call).encode()), + Governance::get(), || { log::error!( target: "bridges::estimate", diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs index 88ccd42dff7f8..0deb2e5ac20ed 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs @@ -44,6 +44,7 @@ use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_common::xcm_sender::ExponentialPrice; use snowbridge_router_primitives::inbound::EthereumLocationsConverterFor; use sp_runtime::traits::{AccountIdConversion, ConvertInto, TryConvertInto}; +use westend_runtime_constants::system_parachain::COLLECTIVES_ID; use xcm::latest::{prelude::*, ROCOCO_GENESIS_HASH, WESTEND_GENESIS_HASH}; use xcm_builder::{ AccountId32Aliases, AliasChildLocation, AllowExplicitUnpaidExecutionFrom, @@ -263,9 +264,9 @@ impl Contains for FellowshipEntities { fn contains(location: &Location) -> bool { matches!( location.unpack(), - (1, [Parachain(1001), Plurality { id: BodyId::Technical, .. }]) | - (1, [Parachain(1001), PalletInstance(64)]) | - (1, [Parachain(1001), PalletInstance(65)]) + (1, [Parachain(COLLECTIVES_ID), Plurality { id: BodyId::Technical, .. }]) | + (1, [Parachain(COLLECTIVES_ID), PalletInstance(64)]) | + (1, [Parachain(COLLECTIVES_ID), PalletInstance(65)]) ) } } @@ -273,7 +274,7 @@ impl Contains for FellowshipEntities { pub struct AmbassadorEntities; impl Contains for AmbassadorEntities { fn contains(location: &Location) -> bool { - matches!(location.unpack(), (1, [Parachain(1001), PalletInstance(74)])) + matches!(location.unpack(), (1, [Parachain(COLLECTIVES_ID), PalletInstance(74)])) } } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs index bdac1050207ec..633787bc34c08 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs @@ -21,8 +21,9 @@ use asset_hub_westend_runtime::{ xcm_config, xcm_config::{ bridging, AssetFeeAsExistentialDepositMultiplierFeeCharger, CheckingAccount, - ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, LocationToAccountId, StakingPot, - TrustBackedAssetsPalletLocation, WestendLocation, XcmConfig, + ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, GovernanceLocation, + LocationToAccountId, StakingPot, TrustBackedAssetsPalletLocation, WestendLocation, + XcmConfig, }, AllPalletsWithoutSystem, Assets, Balances, ExistentialDeposit, ForeignAssets, ForeignAssetsInstance, MetadataDepositBase, MetadataDepositPerByte, ParachainSystem, @@ -32,12 +33,12 @@ use asset_hub_westend_runtime::{ pub use asset_hub_westend_runtime::{AssetConversion, AssetDeposit, CollatorSelection, System}; use asset_test_utils::{ test_cases_over_bridge::TestBridgingConfig, CollatorSessionKey, CollatorSessionKeys, - ExtBuilder, SlotDurations, + ExtBuilder, GovernanceOrigin, SlotDurations, }; use codec::{Decode, Encode}; use cumulus_primitives_utility::ChargeWeightInFungibles; use frame_support::{ - assert_noop, assert_ok, + assert_err, assert_noop, assert_ok, parameter_types, traits::{ fungible::{Inspect, Mutate}, fungibles::{ @@ -49,7 +50,7 @@ use frame_support::{ use parachains_common::{AccountId, AssetIdForTrustBackedAssets, AuraId, Balance}; use sp_consensus_aura::SlotDuration; use sp_core::crypto::Ss58Codec; -use sp_runtime::traits::MaybeEquivalence; +use sp_runtime::{traits::MaybeEquivalence, Either}; use std::{convert::Into, ops::Mul}; use testnet_parachains_constants::westend::{consensus::*, currency::UNITS, fee::WeightToFee}; use xcm::latest::{ @@ -63,6 +64,10 @@ use xcm_runtime_apis::conversions::LocationToAccountHelper; const ALICE: [u8; 32] = [1u8; 32]; const SOME_ASSET_ADMIN: [u8; 32] = [5u8; 32]; +parameter_types! { + pub Governance: GovernanceOrigin = GovernanceOrigin::Location(GovernanceLocation::get()); +} + type AssetIdForTrustBackedAssetsConvert = assets_common::AssetIdForTrustBackedAssetsConvert; @@ -1309,7 +1314,7 @@ fn change_xcm_bridge_hub_router_byte_fee_by_governance_works() { >( collator_session_keys(), 1000, - Box::new(|call| RuntimeCall::System(call).encode()), + Governance::get(), || { ( bridging::XcmBridgeHubRouterByteFee::key().to_vec(), @@ -1335,7 +1340,7 @@ fn change_xcm_bridge_hub_router_base_fee_by_governance_works() { >( collator_session_keys(), 1000, - Box::new(|call| RuntimeCall::System(call).encode()), + Governance::get(), || { log::error!( target: "bridges::estimate", @@ -1496,3 +1501,73 @@ fn location_conversion_works() { assert_eq!(got, expected, "{}", tc.description); } } +<<<<<<< HEAD +======= + +#[test] +fn xcm_payment_api_works() { + parachains_runtimes_test_utils::test_cases::xcm_payment_api_with_native_token_works::< + Runtime, + RuntimeCall, + RuntimeOrigin, + Block, + >(); + asset_test_utils::test_cases::xcm_payment_api_with_pools_works::< + Runtime, + RuntimeCall, + RuntimeOrigin, + Block, + >(); +} + +#[test] +fn governance_authorize_upgrade_works() { + use westend_runtime_constants::system_parachain::{ASSET_HUB_ID, COLLECTIVES_ID}; + + // no - random para + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), + Either::Right(XcmError::Barrier) + ); + // no - AssetHub + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(ASSET_HUB_ID)))), + Either::Right(XcmError::Barrier) + ); + // no - Collectives + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(COLLECTIVES_ID)))), + Either::Right(XcmError::Barrier) + ); + // no - Collectives Voice of Fellows plurality + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::LocationAndDescendOrigin( + Location::new(1, Parachain(COLLECTIVES_ID)), + Plurality { id: BodyId::Technical, part: BodyPart::Voice }.into() + )), + Either::Right(XcmError::BadOrigin) + ); + + // ok - relaychain + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::parent()))); + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(GovernanceLocation::get()))); +} +>>>>>>> e9be92d6 (Authorize upgrade tests for testnet runtimes + `execute_as_governance` refactor (#7656)) diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/tests.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/tests.rs index 6ca858e961d3e..b4b6a7a47b357 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/tests.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/tests.rs @@ -24,7 +24,7 @@ use bridge_hub_rococo_runtime::{ ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, SessionKeys, TransactionPayment, TxExtension, UncheckedExtrinsic, }; -use bridge_hub_test_utils::SlotDurations; +use bridge_hub_test_utils::{GovernanceOrigin, SlotDurations}; use codec::{Decode, Encode}; use frame_support::{dispatch::GetDispatchInfo, parameter_types, traits::ConstU8}; use parachains_common::{AccountId, AuraId, Balance}; @@ -42,6 +42,7 @@ use xcm_runtime_apis::conversions::LocationToAccountHelper; parameter_types! { pub CheckingAccount: AccountId = PolkadotXcm::check_account(); + pub Governance: GovernanceOrigin = GovernanceOrigin::Location(Location::parent()); } fn construct_extrinsic( @@ -165,7 +166,11 @@ mod bridge_hub_westend_tests { bridge_hub_test_utils::test_cases::initialize_bridge_by_governance_works::< Runtime, BridgeGrandpaWestendInstance, - >(collator_session_keys(), bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID) + >( + collator_session_keys(), + bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID, + Governance::get(), + ) } #[test] @@ -174,7 +179,11 @@ mod bridge_hub_westend_tests { bridge_hub_test_utils::test_cases::change_bridge_grandpa_pallet_mode_by_governance_works::< Runtime, BridgeGrandpaWestendInstance, - >(collator_session_keys(), bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID) + >( + collator_session_keys(), + bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID, + Governance::get(), + ) } #[test] @@ -183,7 +192,11 @@ mod bridge_hub_westend_tests { bridge_hub_test_utils::test_cases::change_bridge_parachains_pallet_mode_by_governance_works::< Runtime, BridgeParachainWestendInstance, - >(collator_session_keys(), bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID) + >( + collator_session_keys(), + bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID, + Governance::get(), + ) } #[test] @@ -192,7 +205,11 @@ mod bridge_hub_westend_tests { bridge_hub_test_utils::test_cases::change_bridge_messages_pallet_mode_by_governance_works::< Runtime, WithBridgeHubWestendMessagesInstance, - >(collator_session_keys(), bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID) + >( + collator_session_keys(), + bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID, + Governance::get(), + ) } #[test] @@ -204,7 +221,7 @@ mod bridge_hub_westend_tests { >( collator_session_keys(), bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID, - Box::new(|call| RuntimeCall::System(call).encode()), + Governance::get(), || (EthereumGatewayAddress::key().to_vec(), EthereumGatewayAddress::get()), |_| [1; 20].into(), ) @@ -220,7 +237,7 @@ mod bridge_hub_westend_tests { bridge_hub_test_utils::test_cases::set_storage_keys_by_governance_works::( collator_session_keys(), bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID, - Box::new(|call| RuntimeCall::System(call).encode()), + Governance::get(), vec![ (snowbridge_pallet_outbound_queue::Nonce::::hashed_key_for::( channel_id_one, @@ -285,7 +302,7 @@ mod bridge_hub_westend_tests { >( collator_session_keys(), bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID, - Box::new(|call| RuntimeCall::System(call).encode()), + Governance::get(), || (DeliveryRewardInBalance::key().to_vec(), DeliveryRewardInBalance::get()), |old_value| old_value.checked_mul(2).unwrap(), ) @@ -537,7 +554,11 @@ mod bridge_hub_bulletin_tests { bridge_hub_test_utils::test_cases::initialize_bridge_by_governance_works::< Runtime, BridgeGrandpaRococoBulletinInstance, - >(collator_session_keys(), bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID) + >( + collator_session_keys(), + bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID, + Governance::get(), + ) } #[test] @@ -546,7 +567,11 @@ mod bridge_hub_bulletin_tests { bridge_hub_test_utils::test_cases::change_bridge_grandpa_pallet_mode_by_governance_works::< Runtime, BridgeGrandpaRococoBulletinInstance, - >(collator_session_keys(), bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID) + >( + collator_session_keys(), + bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID, + Governance::get(), + ) } #[test] @@ -555,7 +580,11 @@ mod bridge_hub_bulletin_tests { bridge_hub_test_utils::test_cases::change_bridge_messages_pallet_mode_by_governance_works::< Runtime, WithRococoBulletinMessagesInstance, - >(collator_session_keys(), bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID) + >( + collator_session_keys(), + bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID, + Governance::get(), + ) } #[test] @@ -717,7 +746,7 @@ fn change_required_stake_by_governance_works() { >( collator_session_keys(), bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID, - Box::new(|call| RuntimeCall::System(call).encode()), + Governance::get(), || { ( bridge_common_config::RequiredStakeForStakeAndSlash::key().to_vec(), diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/xcm_config.rs index e692568932fea..31e4998b2ef4a 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/xcm_config.rs @@ -65,6 +65,7 @@ parameter_types! { pub const MaxAssetsIntoHolding: u32 = 64; pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating(); pub RelayTreasuryLocation: Location = (Parent, PalletInstance(westend_runtime_constants::TREASURY_PALLET_ID)).into(); + pub const GovernanceLocation: Location = Location::parent(); } /// Type for specifying how a `Location` can be converted into an `AccountId`. This is used diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/tests/tests.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/tests/tests.rs index 84025c4cefeb5..e5e16badccdea 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/tests/tests.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/tests/tests.rs @@ -18,18 +18,36 @@ use bp_messages::LegacyLaneId; use bp_polkadot_core::Signature; +<<<<<<< HEAD use bridge_common_config::{ DeliveryRewardInBalance, RelayersForLegacyLaneIdsMessagesInstance, RequiredStakeForStakeAndSlash, +======= +use bp_relayers::{PayRewardFromAccount, RewardsAccountOwner, RewardsAccountParams}; +use bridge_common_config::{BridgeRelayersInstance, BridgeReward, RequiredStakeForStakeAndSlash}; +use bridge_hub_test_utils::{ + test_cases::{from_parachain, run_test}, + GovernanceOrigin, SlotDurations, +>>>>>>> e9be92d6 (Authorize upgrade tests for testnet runtimes + `execute_as_governance` refactor (#7656)) }; use bridge_hub_test_utils::{test_cases::from_parachain, SlotDurations}; use bridge_hub_westend_runtime::{ bridge_common_config, bridge_to_rococo_config, bridge_to_rococo_config::RococoGlobalConsensusNetwork, +<<<<<<< HEAD xcm_config::{LocationToAccountId, RelayNetwork, WestendLocation, XcmConfig}, AllPalletsWithoutSystem, BridgeRejectObsoleteHeadersAndMessages, Executive, ExistentialDeposit, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, SessionKeys, TransactionPayment, TxExtension, UncheckedExtrinsic, +======= + xcm_config::{ + GovernanceLocation, LocationToAccountId, RelayNetwork, WestendLocation, XcmConfig, + }, + AllPalletsWithoutSystem, Balances, Block, BridgeRejectObsoleteHeadersAndMessages, + BridgeRelayers, Executive, ExistentialDeposit, ParachainSystem, PolkadotXcm, Runtime, + RuntimeCall, RuntimeEvent, RuntimeOrigin, SessionKeys, TransactionPayment, TxExtension, + UncheckedExtrinsic, +>>>>>>> e9be92d6 (Authorize upgrade tests for testnet runtimes + `execute_as_governance` refactor (#7656)) }; use bridge_to_rococo_config::{ BridgeGrandpaRococoInstance, BridgeHubRococoLocation, BridgeParachainRococoInstance, @@ -43,7 +61,7 @@ use sp_core::crypto::Ss58Codec; use sp_keyring::AccountKeyring::Alice; use sp_runtime::{ generic::{Era, SignedPayload}, - AccountId32, Perbill, + AccountId32, Either, Perbill, }; use testnet_parachains_constants::westend::{consensus::*, fee::WeightToFee}; use xcm::latest::{prelude::*, WESTEND_GENESIS_HASH}; @@ -60,6 +78,8 @@ parameter_types! { pub SiblingParachainLocation: Location = Location::new(1, [Parachain(SIBLING_PARACHAIN_ID)]); pub SiblingSystemParachainLocation: Location = Location::new(1, [Parachain(SIBLING_SYSTEM_PARACHAIN_ID)]); pub BridgedUniversalLocation: InteriorLocation = [GlobalConsensus(RococoGlobalConsensusNetwork::get()), Parachain(BRIDGED_LOCATION_PARACHAIN_ID)].into(); + pub CheckingAccount: AccountId = PolkadotXcm::check_account(); + pub Governance: GovernanceOrigin = GovernanceOrigin::Location(GovernanceLocation::get()); } // Runtime from tests PoV @@ -72,10 +92,6 @@ type RuntimeTestsAdapter = from_parachain::WithRemoteParachainHelperAdapter< RelayersForLegacyLaneIdsMessagesInstance, >; -parameter_types! { - pub CheckingAccount: AccountId = PolkadotXcm::check_account(); -} - fn construct_extrinsic( sender: sp_keyring::AccountKeyring, call: RuntimeCall, @@ -157,7 +173,11 @@ fn initialize_bridge_by_governance_works() { bridge_hub_test_utils::test_cases::initialize_bridge_by_governance_works::< Runtime, BridgeGrandpaRococoInstance, - >(collator_session_keys(), bp_bridge_hub_westend::BRIDGE_HUB_WESTEND_PARACHAIN_ID) + >( + collator_session_keys(), + bp_bridge_hub_westend::BRIDGE_HUB_WESTEND_PARACHAIN_ID, + Governance::get(), + ) } #[test] @@ -165,7 +185,11 @@ fn change_bridge_grandpa_pallet_mode_by_governance_works() { bridge_hub_test_utils::test_cases::change_bridge_grandpa_pallet_mode_by_governance_works::< Runtime, BridgeGrandpaRococoInstance, - >(collator_session_keys(), bp_bridge_hub_westend::BRIDGE_HUB_WESTEND_PARACHAIN_ID) + >( + collator_session_keys(), + bp_bridge_hub_westend::BRIDGE_HUB_WESTEND_PARACHAIN_ID, + Governance::get(), + ) } #[test] @@ -173,7 +197,11 @@ fn change_bridge_parachains_pallet_mode_by_governance_works() { bridge_hub_test_utils::test_cases::change_bridge_parachains_pallet_mode_by_governance_works::< Runtime, BridgeParachainRococoInstance, - >(collator_session_keys(), bp_bridge_hub_westend::BRIDGE_HUB_WESTEND_PARACHAIN_ID) + >( + collator_session_keys(), + bp_bridge_hub_westend::BRIDGE_HUB_WESTEND_PARACHAIN_ID, + Governance::get(), + ) } #[test] @@ -181,7 +209,11 @@ fn change_bridge_messages_pallet_mode_by_governance_works() { bridge_hub_test_utils::test_cases::change_bridge_messages_pallet_mode_by_governance_works::< Runtime, WithBridgeHubRococoMessagesInstance, - >(collator_session_keys(), bp_bridge_hub_westend::BRIDGE_HUB_WESTEND_PARACHAIN_ID) + >( + collator_session_keys(), + bp_bridge_hub_westend::BRIDGE_HUB_WESTEND_PARACHAIN_ID, + Governance::get(), + ) } #[test] @@ -193,7 +225,7 @@ fn change_delivery_reward_by_governance_works() { >( collator_session_keys(), bp_bridge_hub_westend::BRIDGE_HUB_WESTEND_PARACHAIN_ID, - Box::new(|call| RuntimeCall::System(call).encode()), + Governance::get(), || (DeliveryRewardInBalance::key().to_vec(), DeliveryRewardInBalance::get()), |old_value| old_value.checked_mul(2).unwrap(), ) @@ -208,7 +240,7 @@ fn change_required_stake_by_governance_works() { >( collator_session_keys(), bp_bridge_hub_westend::BRIDGE_HUB_WESTEND_PARACHAIN_ID, - Box::new(|call| RuntimeCall::System(call).encode()), + Governance::get(), || (RequiredStakeForStakeAndSlash::key().to_vec(), RequiredStakeForStakeAndSlash::get()), |old_value| old_value.checked_mul(2).unwrap(), ) @@ -525,3 +557,147 @@ fn location_conversion_works() { assert_eq!(got, expected, "{}", tc.description); } } +<<<<<<< HEAD +======= + +#[test] +fn xcm_payment_api_works() { + parachains_runtimes_test_utils::test_cases::xcm_payment_api_with_native_token_works::< + Runtime, + RuntimeCall, + RuntimeOrigin, + Block, + >(); +} + +#[test] +pub fn bridge_rewards_works() { + run_test::( + collator_session_keys(), + bp_bridge_hub_westend::BRIDGE_HUB_WESTEND_PARACHAIN_ID, + vec![], + || { + // reward in WNDs + let reward1: u128 = 2_000_000_000; + // reward in WETH + let reward2: u128 = 3_000_000_000; + + // prepare accounts + let account1 = AccountId32::from(Alice); + let account2 = AccountId32::from(Bob); + let reward1_for = RewardsAccountParams::new( + LegacyLaneId([1; 4]), + *b"test", + RewardsAccountOwner::ThisChain, + ); + let expected_reward1_account = + PayRewardFromAccount::<(), AccountId, LegacyLaneId, ()>::rewards_account( + reward1_for, + ); + assert_ok!(Balances::mint_into(&expected_reward1_account, ExistentialDeposit::get())); + assert_ok!(Balances::mint_into(&expected_reward1_account, reward1.into())); + assert_ok!(Balances::mint_into(&account1, ExistentialDeposit::get())); + + // register rewards + use bp_relayers::RewardLedger; + BridgeRelayers::register_reward(&account1, BridgeReward::from(reward1_for), reward1); + BridgeRelayers::register_reward(&account2, BridgeReward::Snowbridge, reward2); + + // check stored rewards + assert_eq!( + BridgeRelayers::relayer_reward(&account1, BridgeReward::from(reward1_for)), + Some(reward1) + ); + assert_eq!(BridgeRelayers::relayer_reward(&account1, BridgeReward::Snowbridge), None,); + assert_eq!( + BridgeRelayers::relayer_reward(&account2, BridgeReward::Snowbridge), + Some(reward2), + ); + assert_eq!( + BridgeRelayers::relayer_reward(&account2, BridgeReward::from(reward1_for)), + None, + ); + + // claim rewards + assert_ok!(BridgeRelayers::claim_rewards( + RuntimeOrigin::signed(account1.clone()), + reward1_for.into() + )); + assert_eq!(Balances::total_balance(&account1), ExistentialDeposit::get() + reward1); + assert_eq!( + BridgeRelayers::relayer_reward(&account1, BridgeReward::from(reward1_for)), + None, + ); + + // already claimed + assert_err!( + BridgeRelayers::claim_rewards( + RuntimeOrigin::signed(account1.clone()), + reward1_for.into() + ), + pallet_bridge_relayers::Error::::NoRewardForRelayer + ); + + // not yet implemented for Snowbridge + assert_err!( + BridgeRelayers::claim_rewards( + RuntimeOrigin::signed(account2.clone()), + BridgeReward::Snowbridge + ), + pallet_bridge_relayers::Error::::FailedToPayReward + ); + }, + ); +} + +#[test] +fn governance_authorize_upgrade_works() { + use westend_runtime_constants::system_parachain::{ASSET_HUB_ID, COLLECTIVES_ID}; + + // no - random para + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), + Either::Right(XcmError::Barrier) + ); + // no - AssetHub + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(ASSET_HUB_ID)))), + Either::Right(XcmError::Barrier) + ); + // no - Collectives + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(COLLECTIVES_ID)))), + Either::Right(XcmError::Barrier) + ); + // no - Collectives Voice of Fellows plurality + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::LocationAndDescendOrigin( + Location::new(1, Parachain(COLLECTIVES_ID)), + Plurality { id: BodyId::Technical, part: BodyPart::Voice }.into() + )), + Either::Right(XcmError::Barrier) + ); + + // ok - relaychain + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::parent()))); + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(Governance::get())); +} +>>>>>>> e9be92d6 (Authorize upgrade tests for testnet runtimes + `execute_as_governance` refactor (#7656)) diff --git a/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/mod.rs b/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/mod.rs index fa0229ce06881..a061b2bfc54b2 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/mod.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/mod.rs @@ -41,8 +41,8 @@ use frame_support::{ use frame_system::pallet_prelude::BlockNumberFor; use parachains_common::AccountId; use parachains_runtimes_test_utils::{ - mock_open_hrmp_channel, AccountIdOf, BalanceOf, CollatorSessionKeys, ExtBuilder, RuntimeCallOf, - SlotDurations, XcmReceivedFrom, + mock_open_hrmp_channel, AccountIdOf, BalanceOf, CollatorSessionKeys, ExtBuilder, + GovernanceOrigin, RuntimeCallOf, RuntimeOriginOf, SlotDurations, XcmReceivedFrom, }; use sp_runtime::{traits::Zero, AccountId32}; use xcm::{latest::prelude::*, AlwaysLatest}; @@ -104,6 +104,7 @@ where pub fn initialize_bridge_by_governance_works( collator_session_key: CollatorSessionKeys, runtime_para_id: u32, + governance_origin: GovernanceOrigin>, ) where Runtime: BasicParachainRuntime + BridgeGrandpaConfig, GrandpaPalletInstance: 'static, @@ -126,8 +127,10 @@ pub fn initialize_bridge_by_governance_works( }); // execute XCM with Transacts to `initialize bridge` as governance does - assert_ok!(RuntimeHelper::::execute_as_governance(initialize_call.encode(),) - .ensure_complete()); + assert_ok!(RuntimeHelper::::execute_as_governance_call( + initialize_call, + governance_origin + )); // check mode after assert_eq!( @@ -142,6 +145,7 @@ pub fn initialize_bridge_by_governance_works( pub fn change_bridge_grandpa_pallet_mode_by_governance_works( collator_session_key: CollatorSessionKeys, runtime_para_id: u32, + governance_origin: GovernanceOrigin>, ) where Runtime: BasicParachainRuntime + BridgeGrandpaConfig, GrandpaPalletInstance: 'static, @@ -164,10 +168,10 @@ pub fn change_bridge_grandpa_pallet_mode_by_governance_works::execute_as_governance( - set_operating_mode_call.encode(), - ) - .ensure_complete()); + assert_ok!(RuntimeHelper::::execute_as_governance_call( + set_operating_mode_call, + governance_origin.clone() + )); // check mode after assert_eq!( @@ -192,6 +196,7 @@ pub fn change_bridge_grandpa_pallet_mode_by_governance_works( collator_session_key: CollatorSessionKeys, runtime_para_id: u32, + governance_origin: GovernanceOrigin>, ) where Runtime: BasicParachainRuntime + BridgeParachainsConfig, ParachainsPalletInstance: 'static, @@ -216,10 +221,10 @@ pub fn change_bridge_parachains_pallet_mode_by_governance_works::execute_as_governance( - set_operating_mode_call.encode(), - ) - .ensure_complete()); + assert_ok!(RuntimeHelper::::execute_as_governance_call( + set_operating_mode_call, + governance_origin.clone() + )); // check mode after assert_eq!( @@ -244,6 +249,7 @@ pub fn change_bridge_parachains_pallet_mode_by_governance_works( collator_session_key: CollatorSessionKeys, runtime_para_id: u32, + governance_origin: GovernanceOrigin>, ) where Runtime: BasicParachainRuntime + BridgeMessagesConfig, MessagesPalletInstance: 'static, @@ -268,10 +274,10 @@ pub fn change_bridge_messages_pallet_mode_by_governance_works::execute_as_governance( - set_operating_mode_call.encode(), - ) - .ensure_complete()); + assert_ok!(RuntimeHelper::::execute_as_governance_call( + set_operating_mode_call, + governance_origin.clone() + )); // check mode after assert_eq!( diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/xcm_config.rs index 9eb9b85a39189..de20c31193c4d 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/xcm_config.rs @@ -32,7 +32,7 @@ use parachains_common::xcm_config::{ }; use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_common::xcm_sender::ExponentialPrice; -use westend_runtime_constants::xcm as xcm_constants; +use westend_runtime_constants::{system_parachain::ASSET_HUB_ID, xcm as xcm_constants}; use xcm::latest::{prelude::*, WESTEND_GENESIS_HASH}; use xcm_builder::{ AccountId32Aliases, AliasChildLocation, AliasOriginRootUsingFilter, @@ -59,7 +59,7 @@ parameter_types! { pub CheckingAccount: AccountId = PolkadotXcm::check_account(); pub const GovernanceLocation: Location = Location::parent(); pub const FellowshipAdminBodyId: BodyId = BodyId::Index(xcm_constants::body::FELLOWSHIP_ADMIN_INDEX); - pub AssetHub: Location = (Parent, Parachain(1000)).into(); + pub AssetHub: Location = (Parent, Parachain(ASSET_HUB_ID)).into(); pub const TreasurerBodyId: BodyId = BodyId::Treasury; pub AssetHubUsdtId: AssetId = (PalletInstance(50), GeneralIndex(1984)).into(); pub UsdtAssetHub: LocatableAssetId = LocatableAssetId { diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/tests/tests.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/tests/tests.rs index 7add10559d84d..c55a7222667c5 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/tests/tests.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/tests/tests.rs @@ -16,9 +16,19 @@ #![cfg(test)] +<<<<<<< HEAD use collectives_westend_runtime::xcm_config::LocationToAccountId; +======= +use collectives_westend_runtime::{ + xcm_config::{GovernanceLocation, LocationToAccountId}, + Block, Runtime, RuntimeCall, RuntimeOrigin, +}; +use frame_support::{assert_err, assert_ok}; +>>>>>>> e9be92d6 (Authorize upgrade tests for testnet runtimes + `execute_as_governance` refactor (#7656)) use parachains_common::AccountId; +use parachains_runtimes_test_utils::GovernanceOrigin; use sp_core::crypto::Ss58Codec; +use sp_runtime::Either; use xcm::latest::prelude::*; use xcm_runtime_apis::conversions::LocationToAccountHelper; @@ -132,3 +142,67 @@ fn location_conversion_works() { assert_eq!(got, expected, "{}", tc.description); } } +<<<<<<< HEAD +======= + +#[test] +fn xcm_payment_api_works() { + parachains_runtimes_test_utils::test_cases::xcm_payment_api_with_native_token_works::< + Runtime, + RuntimeCall, + RuntimeOrigin, + Block, + >(); +} + +#[test] +fn governance_authorize_upgrade_works() { + use westend_runtime_constants::system_parachain::{ASSET_HUB_ID, COLLECTIVES_ID}; + + // no - random para + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), + Either::Right(XcmError::Barrier) + ); + // no - AssetHub + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(ASSET_HUB_ID)))), + Either::Right(XcmError::Barrier) + ); + // no - Collectives + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(COLLECTIVES_ID)))), + Either::Right(XcmError::Barrier) + ); + // no - Collectives Voice of Fellows plurality + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::LocationAndDescendOrigin( + Location::new(1, Parachain(COLLECTIVES_ID)), + Plurality { id: BodyId::Technical, part: BodyPart::Voice }.into() + )), + Either::Right(XcmError::Barrier) + ); + + // ok - relaychain + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::parent()))); + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(GovernanceLocation::get()))); +} +>>>>>>> e9be92d6 (Authorize upgrade tests for testnet runtimes + `execute_as_governance` refactor (#7656)) diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/xcm_config.rs index d6318472b8146..5a4a4cfdbbea5 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/xcm_config.rs @@ -37,6 +37,7 @@ use parachains_common::{ use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_common::xcm_sender::ExponentialPrice; use sp_runtime::traits::AccountIdConversion; +use westend_runtime_constants::system_parachain::{ASSET_HUB_ID, COLLECTIVES_ID}; use xcm::latest::{prelude::*, WESTEND_GENESIS_HASH}; use xcm_builder::{ AccountId32Aliases, AliasChildLocation, AliasOriginRootUsingFilter, @@ -54,7 +55,7 @@ use xcm_executor::XcmExecutor; parameter_types! { pub const TokenRelayLocation: Location = Location::parent(); - pub AssetHubLocation: Location = Location::new(1, [Parachain(1000)]); + pub AssetHubLocation: Location = Location::new(1, [Parachain(ASSET_HUB_ID)]); pub const RelayNetwork: Option = Some(NetworkId::ByGenesis(WESTEND_GENESIS_HASH)); pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub UniversalLocation: InteriorLocation = @@ -63,7 +64,7 @@ parameter_types! { PalletInstance(::index() as u8).into(); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; - pub FellowshipLocation: Location = Location::new(1, Parachain(1001)); + pub FellowshipLocation: Location = Location::new(1, Parachain(COLLECTIVES_ID)); pub const GovernanceLocation: Location = Location::parent(); } @@ -147,7 +148,10 @@ impl Contains for ParentOrParentsPlurality { pub struct FellowsPlurality; impl Contains for FellowsPlurality { fn contains(location: &Location) -> bool { - matches!(location.unpack(), (1, [Parachain(1001), Plurality { id: BodyId::Technical, .. }])) + matches!( + location.unpack(), + (1, [Parachain(COLLECTIVES_ID), Plurality { id: BodyId::Technical, .. }]) + ) } } diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/tests/tests.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/tests/tests.rs index e391d71a9ab78..45b9ad4fe22b0 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/tests/tests.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/tests/tests.rs @@ -16,9 +16,19 @@ #![cfg(test)] +<<<<<<< HEAD use coretime_westend_runtime::xcm_config::LocationToAccountId; +======= +use coretime_westend_runtime::{ + xcm_config::{GovernanceLocation, LocationToAccountId}, + Block, Runtime, RuntimeCall, RuntimeOrigin, +}; +use frame_support::{assert_err, assert_ok}; +>>>>>>> e9be92d6 (Authorize upgrade tests for testnet runtimes + `execute_as_governance` refactor (#7656)) use parachains_common::AccountId; +use parachains_runtimes_test_utils::GovernanceOrigin; use sp_core::crypto::Ss58Codec; +use sp_runtime::Either; use xcm::latest::prelude::*; use xcm_runtime_apis::conversions::LocationToAccountHelper; @@ -132,3 +142,67 @@ fn location_conversion_works() { assert_eq!(got, expected, "{}", tc.description); } } +<<<<<<< HEAD +======= + +#[test] +fn xcm_payment_api_works() { + parachains_runtimes_test_utils::test_cases::xcm_payment_api_with_native_token_works::< + Runtime, + RuntimeCall, + RuntimeOrigin, + Block, + >(); +} + +#[test] +fn governance_authorize_upgrade_works() { + use westend_runtime_constants::system_parachain::{ASSET_HUB_ID, COLLECTIVES_ID}; + + // no - random para + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), + Either::Right(XcmError::Barrier) + ); + // no - AssetHub + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(ASSET_HUB_ID)))), + Either::Right(XcmError::Barrier) + ); + // no - Collectives + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(COLLECTIVES_ID)))), + Either::Right(XcmError::Barrier) + ); + // no - Collectives Voice of Fellows plurality + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::LocationAndDescendOrigin( + Location::new(1, Parachain(COLLECTIVES_ID)), + Plurality { id: BodyId::Technical, part: BodyPart::Voice }.into() + )), + Either::Right(XcmError::BadOrigin) + ); + + // ok - relaychain + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::parent()))); + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(GovernanceLocation::get()))); +} +>>>>>>> e9be92d6 (Authorize upgrade tests for testnet runtimes + `execute_as_governance` refactor (#7656)) diff --git a/cumulus/parachains/runtimes/people/people-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/people/people-westend/src/xcm_config.rs index 7eaa43c05b208..81126484dcecd 100644 --- a/cumulus/parachains/runtimes/people/people-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/people/people-westend/src/xcm_config.rs @@ -34,6 +34,7 @@ use parachains_common::{ }; use polkadot_parachain_primitives::primitives::Sibling; use sp_runtime::traits::AccountIdConversion; +use westend_runtime_constants::system_parachain::{ASSET_HUB_ID, COLLECTIVES_ID}; use xcm::latest::{prelude::*, WESTEND_GENESIS_HASH}; use xcm_builder::{ AccountId32Aliases, AliasChildLocation, AliasOriginRootUsingFilter, @@ -52,14 +53,14 @@ use xcm_executor::XcmExecutor; parameter_types! { pub const RootLocation: Location = Location::here(); pub const RelayLocation: Location = Location::parent(); - pub AssetHubLocation: Location = Location::new(1, [Parachain(1000)]); + pub AssetHubLocation: Location = Location::new(1, [Parachain(ASSET_HUB_ID)]); pub const RelayNetwork: Option = Some(NetworkId::ByGenesis(WESTEND_GENESIS_HASH)); pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())].into(); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; - pub FellowshipLocation: Location = Location::new(1, Parachain(1001)); + pub FellowshipLocation: Location = Location::new(1, Parachain(COLLECTIVES_ID)); pub const GovernanceLocation: Location = Location::parent(); /// The asset ID for the asset that we use to pay for message delivery fees. Just WND. pub FeeAssetId: AssetId = AssetId(RelayLocation::get()); @@ -156,7 +157,10 @@ impl Contains for ParentOrParentsPlurality { pub struct FellowsPlurality; impl Contains for FellowsPlurality { fn contains(location: &Location) -> bool { - matches!(location.unpack(), (1, [Parachain(1001), Plurality { id: BodyId::Technical, .. }])) + matches!( + location.unpack(), + (1, [Parachain(COLLECTIVES_ID), Plurality { id: BodyId::Technical, .. }]) + ) } } diff --git a/cumulus/parachains/runtimes/people/people-westend/tests/tests.rs b/cumulus/parachains/runtimes/people/people-westend/tests/tests.rs index fa9331952b4b5..d27db55354fa1 100644 --- a/cumulus/parachains/runtimes/people/people-westend/tests/tests.rs +++ b/cumulus/parachains/runtimes/people/people-westend/tests/tests.rs @@ -16,9 +16,19 @@ #![cfg(test)] +use frame_support::{assert_err, assert_ok}; use parachains_common::AccountId; +<<<<<<< HEAD use people_westend_runtime::xcm_config::LocationToAccountId; +======= +use parachains_runtimes_test_utils::GovernanceOrigin; +use people_westend_runtime::{ + xcm_config::{GovernanceLocation, LocationToAccountId}, + Block, Runtime, RuntimeCall, RuntimeOrigin, +}; +>>>>>>> e9be92d6 (Authorize upgrade tests for testnet runtimes + `execute_as_governance` refactor (#7656)) use sp_core::crypto::Ss58Codec; +use sp_runtime::Either; use xcm::latest::prelude::*; use xcm_runtime_apis::conversions::LocationToAccountHelper; @@ -132,3 +142,67 @@ fn location_conversion_works() { assert_eq!(got, expected, "{}", tc.description); } } +<<<<<<< HEAD +======= + +#[test] +fn xcm_payment_api_works() { + parachains_runtimes_test_utils::test_cases::xcm_payment_api_with_native_token_works::< + Runtime, + RuntimeCall, + RuntimeOrigin, + Block, + >(); +} + +#[test] +fn governance_authorize_upgrade_works() { + use westend_runtime_constants::system_parachain::{ASSET_HUB_ID, COLLECTIVES_ID}; + + // no - random para + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), + Either::Right(XcmError::Barrier) + ); + // no - AssetHub + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(ASSET_HUB_ID)))), + Either::Right(XcmError::Barrier) + ); + // no - Collectives + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(COLLECTIVES_ID)))), + Either::Right(XcmError::Barrier) + ); + // no - Collectives Voice of Fellows plurality + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::LocationAndDescendOrigin( + Location::new(1, Parachain(COLLECTIVES_ID)), + Plurality { id: BodyId::Technical, part: BodyPart::Voice }.into() + )), + Either::Right(XcmError::BadOrigin) + ); + + // ok - relaychain + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::parent()))); + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(GovernanceLocation::get()))); +} +>>>>>>> e9be92d6 (Authorize upgrade tests for testnet runtimes + `execute_as_governance` refactor (#7656)) diff --git a/cumulus/parachains/runtimes/test-utils/src/lib.rs b/cumulus/parachains/runtimes/test-utils/src/lib.rs index 5c33809ba67b1..e4fc7873f502c 100644 --- a/cumulus/parachains/runtimes/test-utils/src/lib.rs +++ b/cumulus/parachains/runtimes/test-utils/src/lib.rs @@ -34,7 +34,10 @@ use polkadot_parachain_primitives::primitives::{ }; use sp_consensus_aura::{SlotDuration, AURA_ENGINE_ID}; use sp_core::{Encode, U256}; -use sp_runtime::{traits::Header, BuildStorage, Digest, DigestItem, SaturatedConversion}; +use sp_runtime::{ + traits::{Dispatchable, Header}, + BuildStorage, Digest, DigestItem, DispatchError, Either, SaturatedConversion, +}; use xcm::{ latest::{Asset, Location, XcmContext, XcmHash}, prelude::*, @@ -47,6 +50,7 @@ pub mod test_cases; pub type BalanceOf = ::Balance; pub type AccountIdOf = ::AccountId; pub type RuntimeCallOf = ::RuntimeCall; +pub type RuntimeOriginOf = ::RuntimeOrigin; pub type ValidatorIdOf = ::ValidatorId; pub type SessionKeysOf = ::Keys; @@ -441,6 +445,10 @@ impl< AllPalletsWithoutSystem, > RuntimeHelper { + #[deprecated( + note = "Will be removed after Aug 2025; It uses hard-coded `Location::parent()`, \ + use `execute_as_governance_call` instead." + )] pub fn execute_as_governance(call: Vec) -> Outcome { // prepare xcm as governance will do let xcm = Xcm(vec![ @@ -464,6 +472,47 @@ impl< ) } + pub fn execute_as_governance_call( + call: Call, + governance_origin: GovernanceOrigin, + ) -> Result<(), Either> { + // execute xcm as governance would send + let execute_xcm = |call: Call, governance_location, descend_origin| { + // prepare xcm + let xcm = if let Some(descend_origin) = descend_origin { + Xcm::builder_unsafe().descend_origin(descend_origin) + } else { + Xcm::builder_unsafe() + } + .unpaid_execution(Unlimited, None) + .transact(OriginKind::Superuser, None, call.encode()) + .expect_transact_status(MaybeErrorCode::Success) + .build(); + + let xcm_max_weight = Self::xcm_max_weight_for_location(&governance_location); + let mut hash = xcm.using_encoded(sp_io::hashing::blake2_256); + + <::XcmExecutor>::prepare_and_execute( + governance_location, + xcm, + &mut hash, + xcm_max_weight, + Weight::zero(), + ) + }; + + match governance_origin { + GovernanceOrigin::Location(location) => + execute_xcm(call, location, None).ensure_complete().map_err(Either::Right), + GovernanceOrigin::LocationAndDescendOrigin(location, descend_origin) => + execute_xcm(call, location, Some(descend_origin)) + .ensure_complete() + .map_err(Either::Right), + GovernanceOrigin::Origin(origin) => + call.dispatch(origin).map(|_| ()).map_err(|e| Either::Left(e.error)), + } + } + pub fn execute_as_origin( (origin, origin_kind): (Location, OriginKind), call: Call, @@ -484,23 +533,28 @@ impl< ExpectTransactStatus(MaybeErrorCode::Success), ]); let xcm = Xcm(instructions); + let xcm_max_weight = Self::xcm_max_weight_for_location(&origin); // execute xcm as parent origin let mut hash = xcm.using_encoded(sp_io::hashing::blake2_256); <::XcmExecutor>::prepare_and_execute( - origin.clone(), + origin, xcm, &mut hash, - Self::xcm_max_weight(if origin == Location::parent() { - XcmReceivedFrom::Parent - } else { - XcmReceivedFrom::Sibling - }), + xcm_max_weight, Weight::zero(), ) } } +/// Enum representing governance origin/location. +#[derive(Clone)] +pub enum GovernanceOrigin { + Location(Location), + LocationAndDescendOrigin(Location, InteriorLocation), + Origin(RuntimeOrigin), +} + pub enum XcmReceivedFrom { Parent, Sibling, @@ -515,6 +569,14 @@ impl ParachainSystem::ReservedXcmpWeight::get(), } } + + pub fn xcm_max_weight_for_location(location: &Location) -> Weight { + Self::xcm_max_weight(if location == &Location::parent() { + XcmReceivedFrom::Parent + } else { + XcmReceivedFrom::Sibling + }) + } } impl diff --git a/cumulus/parachains/runtimes/test-utils/src/test_cases.rs b/cumulus/parachains/runtimes/test-utils/src/test_cases.rs index a66163154cf69..5b0ed01a7bd1b 100644 --- a/cumulus/parachains/runtimes/test-utils/src/test_cases.rs +++ b/cumulus/parachains/runtimes/test-utils/src/test_cases.rs @@ -16,9 +16,28 @@ //! Module contains predefined test-case scenarios for `Runtime` with common functionality. -use crate::{AccountIdOf, CollatorSessionKeys, ExtBuilder, ValidatorIdOf}; +use crate::{ + AccountIdOf, BasicParachainRuntime, CollatorSessionKeys, ExtBuilder, GovernanceOrigin, + RuntimeCallOf, RuntimeOriginOf, ValidatorIdOf, +}; use codec::Encode; +<<<<<<< HEAD use frame_support::{assert_ok, traits::Get}; +======= +use frame_support::{ + assert_ok, + traits::{Get, OriginTrait}, +}; +use parachains_common::AccountId; +use sp_runtime::{ + traits::{Block as BlockT, StaticLookup}, + DispatchError, Either, +}; +use xcm::prelude::XcmError; +use xcm_runtime_apis::fees::{ + runtime_decl_for_xcm_payment_api::XcmPaymentApiV1, Error as XcmPaymentApiError, +}; +>>>>>>> e9be92d6 (Authorize upgrade tests for testnet runtimes + `execute_as_governance` refactor (#7656)) type RuntimeHelper = crate::RuntimeHelper; @@ -27,7 +46,7 @@ type RuntimeHelper = pub fn change_storage_constant_by_governance_works( collator_session_key: CollatorSessionKeys, runtime_para_id: u32, - runtime_call_encode: Box) -> Vec>, + governance_origin: GovernanceOrigin>, storage_constant_key_value: fn() -> (Vec, StorageConstantType), new_storage_constant_value: fn(&StorageConstantType) -> StorageConstantType, ) where @@ -65,7 +84,7 @@ pub fn change_storage_constant_by_governance_works::set_storage { + RuntimeCallOf::::from(frame_system::Call::::set_storage { items: vec![( storage_constant_key.clone(), new_storage_constant_value.encode(), @@ -73,8 +92,10 @@ pub fn change_storage_constant_by_governance_works::execute_as_governance(set_storage_call,) - .ensure_complete()); + assert_ok!(RuntimeHelper::::execute_as_governance_call( + set_storage_call, + governance_origin + )); // check delivery reward constant after (stored) assert_eq!(StorageConstant::get(), new_storage_constant_value); @@ -89,7 +110,7 @@ pub fn change_storage_constant_by_governance_works( collator_session_key: CollatorSessionKeys, runtime_para_id: u32, - runtime_call_encode: Box) -> Vec>, + governance_origin: GovernanceOrigin>, storage_items: Vec<(Vec, Vec)>, initialize_storage: impl FnOnce() -> (), assert_storage: impl FnOnce() -> (), @@ -115,16 +136,108 @@ pub fn set_storage_keys_by_governance_works( }); runtime.execute_with(|| { // encode `kill_storage` call - let kill_storage_call = runtime_call_encode(frame_system::Call::::set_storage { - items: storage_items.clone(), - }); + let kill_storage_call = + RuntimeCallOf::::from(frame_system::Call::::set_storage { + items: storage_items.clone(), + }); // execute XCM with Transact to `set_storage` as governance does - assert_ok!( - RuntimeHelper::::execute_as_governance(kill_storage_call,).ensure_complete() - ); + assert_ok!(RuntimeHelper::::execute_as_governance_call( + kill_storage_call, + governance_origin + )); }); runtime.execute_with(|| { assert_storage(); }); } +<<<<<<< HEAD +======= + +pub fn xcm_payment_api_with_native_token_works() +where + Runtime: XcmPaymentApiV1 + + frame_system::Config + + pallet_balances::Config + + pallet_session::Config + + pallet_xcm::Config + + parachain_info::Config + + pallet_collator_selection::Config + + cumulus_pallet_parachain_system::Config + + cumulus_pallet_xcmp_queue::Config + + pallet_timestamp::Config, + ValidatorIdOf: From>, + RuntimeOrigin: OriginTrait::AccountId>, + <::Lookup as StaticLookup>::Source: + From<::AccountId>, + Block: BlockT, +{ + use xcm::prelude::*; + ExtBuilder::::default().build().execute_with(|| { + let transfer_amount = 100u128; + let xcm_to_weigh = Xcm::::builder_unsafe() + .withdraw_asset((Here, transfer_amount)) + .buy_execution((Here, transfer_amount), Unlimited) + .deposit_asset(AllCounted(1), [1u8; 32]) + .build(); + let versioned_xcm_to_weigh = VersionedXcm::from(xcm_to_weigh.clone().into()); + + // We first try calling it with a lower XCM version. + let lower_version_xcm_to_weigh = + versioned_xcm_to_weigh.clone().into_version(XCM_VERSION - 1).unwrap(); + let xcm_weight = Runtime::query_xcm_weight(lower_version_xcm_to_weigh); + assert!(xcm_weight.is_ok()); + let native_token: Location = Parent.into(); + let native_token_versioned = VersionedAssetId::from(AssetId(native_token)); + let lower_version_native_token = + native_token_versioned.clone().into_version(XCM_VERSION - 1).unwrap(); + let execution_fees = + Runtime::query_weight_to_asset_fee(xcm_weight.unwrap(), lower_version_native_token); + assert!(execution_fees.is_ok()); + + // Now we call it with the latest version. + let xcm_weight = Runtime::query_xcm_weight(versioned_xcm_to_weigh); + assert!(xcm_weight.is_ok()); + let execution_fees = + Runtime::query_weight_to_asset_fee(xcm_weight.unwrap(), native_token_versioned); + assert!(execution_fees.is_ok()); + + // If we call it with anything other than the native token it will error. + let non_existent_token: Location = Here.into(); + let non_existent_token_versioned = VersionedAssetId::from(AssetId(non_existent_token)); + let execution_fees = + Runtime::query_weight_to_asset_fee(xcm_weight.unwrap(), non_existent_token_versioned); + assert_eq!(execution_fees, Err(XcmPaymentApiError::AssetNotFound)); + }); +} + +/// Generic test case for Cumulus-based parachain that verifies if runtime can process +/// `frame_system::Call::authorize_upgrade` from governance system. +pub fn can_governance_authorize_upgrade( + governance_origin: GovernanceOrigin, +) -> Result<(), Either> +where + Runtime: BasicParachainRuntime + + frame_system::Config, +{ + ExtBuilder::::default().build().execute_with(|| { + // check before + assert!(frame_system::Pallet::::authorized_upgrade().is_none()); + + // execute call as governance does + let code_hash = Runtime::Hash::default(); + let authorize_upgrade_call: ::RuntimeCall = + frame_system::Call::::authorize_upgrade { code_hash }.into(); + RuntimeHelper::::execute_as_governance_call( + authorize_upgrade_call, + governance_origin, + )?; + + // check after + match frame_system::Pallet::::authorized_upgrade() { + None => Err(Either::Left(frame_system::Error::::NothingAuthorized.into())), + Some(_) => Ok(()), + } + }) +} +>>>>>>> e9be92d6 (Authorize upgrade tests for testnet runtimes + `execute_as_governance` refactor (#7656)) diff --git a/prdoc/pr_7656.prdoc b/prdoc/pr_7656.prdoc new file mode 100644 index 0000000000000..80a62c284daa1 --- /dev/null +++ b/prdoc/pr_7656.prdoc @@ -0,0 +1,25 @@ +title: Authorize upgrade tests for testnet runtimes + `execute_as_governance` refactor +doc: +- audience: Runtime Dev + description: |- + This PR contains improved test cases that rely on the governance location as preparation for AHM to capture the state as it is. + It introduces `execute_as_governance_call`, which can be configured with various governance location setups instead of the hard-coded `Location::parent()`. +crates: +- name: parachains-runtimes-test-utils + bump: major +- name: asset-hub-westend-runtime + bump: patch +- name: bridge-hub-westend-runtime + bump: minor +- name: collectives-westend-runtime + bump: patch +- name: coretime-westend-runtime + bump: patch +- name: people-westend-runtime + bump: patch +- name: asset-hub-rococo-runtime + bump: patch +- name: bridge-hub-rococo-runtime + bump: patch +- name: bridge-hub-test-utils + bump: major