diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/tests/snowbridge.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/tests/snowbridge.rs index c5f3871c07905..2f64c75114d58 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/tests/snowbridge.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/tests/snowbridge.rs @@ -19,22 +19,30 @@ use bp_asset_hub_westend::ASSET_HUB_WESTEND_PARACHAIN_ID; use bp_bridge_hub_westend::BRIDGE_HUB_WESTEND_PARACHAIN_ID; use bp_polkadot_core::Signature; +use bridge_hub_test_utils::{ExtBuilder, RuntimeHelper}; use bridge_hub_westend_runtime::{ - bridge_to_rococo_config, xcm_config::XcmConfig, AllPalletsWithoutSystem, - BridgeRejectObsoleteHeadersAndMessages, Executive, MessageQueueServiceWeight, Runtime, - RuntimeCall, RuntimeEvent, SessionKeys, SignedExtra, UncheckedExtrinsic, + bridge_to_ethereum_config::EnableRegisterToken, bridge_to_rococo_config, xcm_config::XcmConfig, + AllPalletsWithoutSystem, BridgeRejectObsoleteHeadersAndMessages, Executive, + MessageQueueServiceWeight, Runtime, RuntimeCall, RuntimeEvent, SessionKeys, SignedExtra, + UncheckedExtrinsic, }; use codec::{Decode, Encode}; use cumulus_primitives_core::XcmError::{FailedToTransactAsset, NotHoldingFees}; -use frame_support::parameter_types; +use frame_support::{assert_err, assert_ok, parameter_types}; use parachains_common::{AccountId, AuraId, Balance}; +use snowbridge_core::{outbound::SendError, AssetMetadata}; use snowbridge_pallet_ethereum_client::WeightInfo; use sp_core::H160; -use sp_keyring::AccountKeyring::Alice; +use sp_keyring::AccountKeyring::{Alice, Ferdie}; use sp_runtime::{ generic::{Era, SignedPayload}, + traits::BadOrigin, AccountId32, }; +use xcm::{ + prelude::{GlobalConsensus, Location, Westend}, + VersionedLocation, +}; parameter_types! { pub const DefaultBridgeHubEthereumBaseFee: Balance = 2_750_872_500_000; @@ -200,3 +208,43 @@ fn construct_and_apply_extrinsic( let r = Executive::apply_extrinsic(xt); r.unwrap() } + +#[test] +fn enable_register_token_flag_works() { + ExtBuilder::::default() + .with_collators(collator_session_keys().collators()) + .with_session_keys(collator_session_keys().session_keys()) + .with_para_id(BRIDGE_HUB_WESTEND_PARACHAIN_ID.into()) + .with_tracing() + .build() + .execute_with(|| { + let location: VersionedLocation = + VersionedLocation::from(Location::new(1, [GlobalConsensus(Westend)])); + let metadata: AssetMetadata = AssetMetadata { + name: "wnd".as_bytes().to_vec().try_into().unwrap(), + symbol: "wnd".as_bytes().to_vec().try_into().unwrap(), + decimals: 12, + }; + assert_err!( + >::register_token( + RuntimeHelper::::origin_of(Ferdie.into()), + Box::new(location.clone()), + metadata.clone(), + ), + BadOrigin + ); + assert_ok!(>::set_storage( + RuntimeHelper::::root_origin(), + vec![(EnableRegisterToken::key().to_vec(), true.encode())], + )); + // Send error here means the origin check is passed and register token is enabled + assert_err!( + >::register_token( + RuntimeHelper::::origin_of(Ferdie.into()), + Box::new(location.clone()), + metadata.clone(), + ), + >::Send(SendError::InvalidChannel) + ); + }); +}