Skip to content

Commit

Permalink
Add can_governance_authorize_upgrade test for all system chains
Browse files Browse the repository at this point in the history
  • Loading branch information
bkontur committed Feb 21, 2025
1 parent e006cfc commit 5002a12
Show file tree
Hide file tree
Showing 10 changed files with 290 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -265,17 +266,17 @@ impl Contains<Location> 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)])
)
}
}

pub struct AmbassadorEntities;
impl Contains<Location> for AmbassadorEntities {
fn contains(location: &Location) -> bool {
matches!(location.unpack(), (1, [Parachain(1001), PalletInstance(74)]))
matches!(location.unpack(), (1, [Parachain(COLLECTIVES_ID), PalletInstance(74)]))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

//! Tests for the Westmint (Westend Assets Hub) chain.
use asset_hub_westend_runtime::xcm_config::GovernanceLocation;
use asset_hub_westend_runtime::{
xcm_config,
xcm_config::{
Expand All @@ -37,7 +38,7 @@ use asset_test_utils::{
use codec::{Decode, Encode};
use cumulus_primitives_utility::ChargeWeightInFungibles;
use frame_support::{
assert_noop, assert_ok,
assert_err, assert_noop, assert_ok,
traits::{
fungible::{Inspect, Mutate},
fungibles::{
Expand All @@ -47,9 +48,11 @@ use frame_support::{
weights::{Weight, WeightToFee as WeightToFeeT},
};
use parachains_common::{AccountId, AssetIdForTrustBackedAssets, AuraId, Balance};
use parachains_runtimes_test_utils::GovernanceOrigin;
use sp_consensus_aura::SlotDuration;
use sp_core::crypto::Ss58Codec;
use sp_runtime::traits::MaybeEquivalence;
use sp_runtime::Either;
use std::{convert::Into, ops::Mul};
use testnet_parachains_constants::westend::{consensus::*, currency::UNITS, fee::WeightToFee};
use xcm::latest::{
Expand Down Expand Up @@ -1512,3 +1515,54 @@ fn xcm_payment_api_works() {
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())));
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use bridge_hub_test_utils::{
test_cases::{from_parachain, run_test},
SlotDurations,
};
use bridge_hub_westend_runtime::xcm_config::GovernanceLocation;
use bridge_hub_westend_runtime::{
bridge_common_config, bridge_to_rococo_config,
bridge_to_rococo_config::RococoGlobalConsensusNetwork,
Expand All @@ -48,12 +49,13 @@ use frame_support::{
},
};
use parachains_common::{AccountId, AuraId, Balance};
use parachains_runtimes_test_utils::GovernanceOrigin;
use sp_consensus_aura::SlotDuration;
use sp_core::crypto::Ss58Codec;
use sp_keyring::Sr25519Keyring::{Alice, Bob};
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};
Expand Down Expand Up @@ -624,3 +626,54 @@ pub fn bridge_rewards_works() {
},
);
}

#[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())));
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,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,
Expand All @@ -58,7 +58,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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@
use collectives_westend_runtime::{
xcm_config::LocationToAccountId, Block, Runtime, RuntimeCall, RuntimeOrigin,
};
use collectives_westend_runtime::xcm_config::GovernanceLocation;
use frame_support::{assert_err, assert_ok};
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;

Expand Down Expand Up @@ -144,3 +148,54 @@ fn xcm_payment_api_works() {
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())));
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -55,7 +56,7 @@ use xcm_executor::XcmExecutor;
parameter_types! {
pub const RootLocation: Location = Location::here();
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<NetworkId> = Some(NetworkId::ByGenesis(WESTEND_GENESIS_HASH));
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
pub UniversalLocation: InteriorLocation =
Expand All @@ -64,7 +65,7 @@ parameter_types! {
PalletInstance(<Broker as PalletInfoAccess>::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();
}

Expand Down Expand Up @@ -148,7 +149,7 @@ impl Contains<Location> for ParentOrParentsPlurality {
pub struct FellowsPlurality;
impl Contains<Location> 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, .. }]))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@

#![cfg(test)]

use coretime_westend_runtime::xcm_config::GovernanceLocation;
use coretime_westend_runtime::{
xcm_config::LocationToAccountId, Block, Runtime, RuntimeCall, RuntimeOrigin,
};
use frame_support::{assert_err, assert_ok};
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;

Expand Down Expand Up @@ -144,3 +148,54 @@ fn xcm_payment_api_works() {
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())));
}
Loading

0 comments on commit 5002a12

Please sign in to comment.