Skip to content

Commit

Permalink
fix runtime tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alistair-singh committed Dec 18, 2023
1 parent 1d6f03f commit 83650f2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 30 deletions.
19 changes: 8 additions & 11 deletions parachain/pallets/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,18 +618,8 @@ pub mod pallet {
Ok(())
}

/// Checks if the pallet has been initialized.
pub(crate) fn is_initialized() -> bool {
let primary_exists = Channels::<T>::contains_key(PRIMARY_GOVERNANCE_CHANNEL);
let secondary_exists = Channels::<T>::contains_key(SECONDARY_GOVERNANCE_CHANNEL);
primary_exists && secondary_exists
}

/// Initializes agents and channels.
pub(crate) fn initialize(
para_id: ParaId,
asset_hub_para_id: ParaId,
) -> Result<(), DispatchError> {
pub fn initialize(para_id: ParaId, asset_hub_para_id: ParaId) -> Result<(), DispatchError> {
// Asset Hub
let asset_hub_location: MultiLocation =
ParentThen(X1(Parachain(asset_hub_para_id.into()))).into();
Expand Down Expand Up @@ -660,6 +650,13 @@ pub mod pallet {

Ok(())
}

/// Checks if the pallet has been initialized.
pub(crate) fn is_initialized() -> bool {
let primary_exists = Channels::<T>::contains_key(PRIMARY_GOVERNANCE_CHANNEL);
let secondary_exists = Channels::<T>::contains_key(SECONDARY_GOVERNANCE_CHANNEL);
primary_exists && secondary_exists
}
}

impl<T: Config> StaticLookup for Pallet<T> {
Expand Down
17 changes: 1 addition & 16 deletions parachain/runtime/tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod test_cases;
use asset_hub_rococo_runtime::xcm_config::bridging::to_ethereum::DefaultBridgeHubEthereumBaseFee;
use bridge_hub_rococo_runtime::{xcm_config::XcmConfig, Runtime, RuntimeEvent, SessionKeys};
use codec::Decode;
use cumulus_primitives_core::XcmError::{FailedToTransactAsset, NotHoldingFees, Unroutable};
use cumulus_primitives_core::XcmError::{FailedToTransactAsset, NotHoldingFees};
use parachains_common::{AccountId, AuraId};
use sp_core::H160;
use sp_keyring::AccountKeyring::Alice;
Expand Down Expand Up @@ -39,21 +39,6 @@ pub fn transfer_token_to_ethereum_works() {
)
}

#[test]
pub fn transfer_token_from_non_assethub_to_ethereum_unroutable() {
test_cases::send_transfer_token_message_failure::<Runtime, XcmConfig>(
collator_session_keys(),
1013,
1001,
DefaultBridgeHubEthereumBaseFee::get() + 1_000_000_000,
H160::random(),
H160::random(),
// fee not enough
1_000_000_000,
Unroutable,
)
}

#[test]
pub fn unpaid_transfer_token_to_ethereum_fails_with_barrier() {
test_cases::send_unpaid_transfer_token_message::<Runtime, XcmConfig>(
Expand Down
13 changes: 11 additions & 2 deletions parachain/runtime/tests/src/test_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! Module contains predefined test-case scenarios for `Runtime` with bridging capabilities.

use asset_hub_rococo_runtime::xcm_config::bridging::to_ethereum::DefaultBridgeHubEthereumBaseFee;
use bridge_hub_rococo_runtime::EthereumSystem;
use codec::Encode;
use frame_support::{assert_err, assert_ok, traits::fungible::Mutate};
use parachains_runtimes_test_utils::{
Expand Down Expand Up @@ -119,7 +120,8 @@ pub fn send_transfer_token_message_success<Runtime, XcmConfig>(
+ parachain_info::Config
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config
+ snowbridge_outbound_queue::Config,
+ snowbridge_outbound_queue::Config
+ snowbridge_system::Config,
XcmConfig: xcm_executor::Config,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
{
Expand All @@ -130,6 +132,9 @@ pub fn send_transfer_token_message_success<Runtime, XcmConfig>(
.with_tracing()
.build()
.execute_with(|| {
EthereumSystem::initialize(runtime_para_id.into(), assethub_parachain_id.into())
.unwrap();

// fund asset hub sovereign account enough so it can pay fees
initial_fund::<Runtime>(
assethub_parachain_id,
Expand Down Expand Up @@ -257,7 +262,8 @@ pub fn send_transfer_token_message_failure<Runtime, XcmConfig>(
+ parachain_info::Config
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config
+ snowbridge_outbound_queue::Config,
+ snowbridge_outbound_queue::Config
+ snowbridge_system::Config,
XcmConfig: xcm_executor::Config,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
{
Expand All @@ -268,6 +274,9 @@ pub fn send_transfer_token_message_failure<Runtime, XcmConfig>(
.with_tracing()
.build()
.execute_with(|| {
EthereumSystem::initialize(runtime_para_id.into(), assethub_parachain_id.into())
.unwrap();

// fund asset hub sovereign account enough so it can pay fees
initial_fund::<Runtime>(assethub_parachain_id, initial_amount);

Expand Down
2 changes: 1 addition & 1 deletion polkadot-sdk

0 comments on commit 83650f2

Please sign in to comment.