Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Adjusted test `handle_export_message_from_system_parachain_to_outboun…
Browse files Browse the repository at this point in the history
…d_queue_works` for Paid or Unpaid scenario
  • Loading branch information
bkontur committed Aug 14, 2023
1 parent a701215 commit 3a5dfe2
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use bp_polkadot_core::Signature;
pub use bridge_hub_kusama_runtime::{
bridge_hub_config,
constants::fee::WeightToFee,
xcm_config::{RelayNetwork, XcmConfig},
xcm_config::{KsmRelayLocation, RelayNetwork, XcmConfig},
Balances, BridgeGrandpaPolkadotInstance, BridgeRejectObsoleteHeadersAndMessages,
ExistentialDeposit, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent,
SessionKeys, WithBridgeHubPolkadotMessagesInstance,
Expand Down Expand Up @@ -183,7 +183,10 @@ fn handle_export_message_from_system_parachain_add_to_outbound_queue_works() {
}
}),
|| ExportMessage { network: Polkadot, destination: X1(Parachain(1234)), xcm: Xcm(vec![]) },
bridge_hub_config::ASSET_HUB_KUSAMA_TO_ASSET_HUB_POLKADOT_LANE_ID
bridge_hub_config::ASSET_HUB_KUSAMA_TO_ASSET_HUB_POLKADOT_LANE_ID,
Some((KsmRelayLocation::get(), ExistentialDeposit::get()).into()),
// value should be >= than value generated by `can_calculate_weight_for_paid_export_message_with_reserve_transfer`
Some((KsmRelayLocation::get(), 187806666).into()),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use bp_polkadot_core::Signature;
pub use bridge_hub_polkadot_runtime::{
bridge_hub_config,
constants::fee::WeightToFee,
xcm_config::{RelayNetwork, XcmConfig},
xcm_config::{DotRelayLocation, RelayNetwork, XcmConfig},
Balances, BridgeGrandpaKusamaInstance, BridgeRejectObsoleteHeadersAndMessages,
ExistentialDeposit, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent,
SessionKeys, WithBridgeHubKusamaMessagesInstance,
Expand Down Expand Up @@ -183,7 +183,10 @@ fn handle_export_message_from_system_parachain_add_to_outbound_queue_works() {
}
}),
|| ExportMessage { network: Kusama, destination: X1(Parachain(1234)), xcm: Xcm(vec![]) },
bridge_hub_config::ASSET_HUB_POLKADOT_TO_ASSET_HUB_KUSAMA_LANE_ID
bridge_hub_config::ASSET_HUB_POLKADOT_TO_ASSET_HUB_KUSAMA_LANE_ID,
Some((DotRelayLocation::get(), ExistentialDeposit::get()).into()),
// value should be >= than value generated by `can_calculate_weight_for_paid_export_message_with_reserve_transfer`
Some((DotRelayLocation::get(), 56342000).into()),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ mod bridge_hub_rococo_tests {
}
}),
|| ExportMessage { network: Wococo, destination: X1(Parachain(1234)), xcm: Xcm(vec![]) },
bridge_hub_rococo_config::DEFAULT_XCM_LANE_TO_BRIDGE_HUB_WOCOCO
bridge_hub_rococo_config::DEFAULT_XCM_LANE_TO_BRIDGE_HUB_WOCOCO,
None,
None,
)
}

Expand Down Expand Up @@ -366,7 +368,9 @@ mod bridge_hub_wococo_tests {
}
}),
|| ExportMessage { network: Rococo, destination: X1(Parachain(4321)), xcm: Xcm(vec![]) },
bridge_hub_wococo_config::DEFAULT_XCM_LANE_TO_BRIDGE_HUB_ROCOCO
bridge_hub_wococo_config::DEFAULT_XCM_LANE_TO_BRIDGE_HUB_ROCOCO,
None,
None,
)
}

Expand Down
41 changes: 35 additions & 6 deletions parachains/runtimes/bridge-hubs/test-utils/src/test_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ use sp_runtime::{
};
use xcm::latest::prelude::*;
use xcm_builder::DispatchBlobError;
use xcm_executor::{traits::WeightBounds, XcmExecutor};
use xcm_executor::{
traits::{TransactAsset, WeightBounds},
XcmExecutor,
};

// Re-export test_case from assets
pub use asset_test_utils::include_teleports_for_native_asset_works;
Expand Down Expand Up @@ -135,7 +138,8 @@ pub fn handle_export_message_from_system_parachain_to_outbound_queue_works<
>,
export_message_instruction: fn() -> Instruction<XcmConfig::RuntimeCall>,
expected_lane_id: LaneId,
// TODO: add paid or unpaid
existential_deposit: Option<MultiAsset>,
maybe_paid_export_message: Option<MultiAsset>,
) where
Runtime: frame_system::Config
+ pallet_balances::Config
Expand Down Expand Up @@ -169,10 +173,35 @@ pub fn handle_export_message_from_system_parachain_to_outbound_queue_works<
);

// prepare `ExportMessage`
let xcm = Xcm(vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
export_message_instruction(),
]);
let xcm = if let Some(fee) = maybe_paid_export_message {
// deposit ED to origin (if needed)
if let Some(ed) = existential_deposit {
XcmConfig::AssetTransactor::deposit_asset(
&ed,
&sibling_parachain_location,
&XcmContext::with_message_id([0; 32]),
)
.expect("deposited ed");
}
// deposit fee to origin
XcmConfig::AssetTransactor::deposit_asset(
&fee,
&sibling_parachain_location,
&XcmContext::with_message_id([0; 32]),
)
.expect("deposited fee");

Xcm(vec![
WithdrawAsset(MultiAssets::from(vec![fee.clone()])),
BuyExecution { fees: fee, weight_limit: Unlimited },
export_message_instruction(),
])
} else {
Xcm(vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
export_message_instruction(),
])
};

// execute XCM
let hash = xcm.using_encoded(sp_io::hashing::blake2_256);
Expand Down

0 comments on commit 3a5dfe2

Please sign in to comment.