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

Commit a701215

Browse files
committed
Test for calculating base delivery fee on BridgeHubs
1 parent ebc0ed1 commit a701215

3 files changed

Lines changed: 127 additions & 2 deletions

File tree

parachains/runtimes/bridge-hubs/bridge-hub-kusama/tests/tests.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,12 @@ pub fn complex_relay_extrinsic_works() {
259259
construct_and_apply_extrinsic,
260260
);
261261
}
262+
263+
#[test]
264+
pub fn can_calculate_weight_for_paid_export_message_with_reserve_transfer() {
265+
bridge_hub_test_utils::test_cases::can_calculate_weight_for_paid_export_message_with_reserve_transfer::<
266+
Runtime,
267+
XcmConfig,
268+
WeightToFee,
269+
>();
270+
}

parachains/runtimes/bridge-hubs/bridge-hub-polkadot/tests/tests.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,12 @@ pub fn complex_relay_extrinsic_works() {
259259
construct_and_apply_extrinsic,
260260
);
261261
}
262+
263+
#[test]
264+
pub fn can_calculate_weight_for_paid_export_message_with_reserve_transfer() {
265+
bridge_hub_test_utils::test_cases::can_calculate_weight_for_paid_export_message_with_reserve_transfer::<
266+
Runtime,
267+
XcmConfig,
268+
WeightToFee,
269+
>();
270+
}

parachains/runtimes/bridge-hubs/test-utils/src/test_cases.rs

Lines changed: 109 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ use parachains_runtimes_test_utils::{
4545
};
4646
use sp_core::H256;
4747
use sp_keyring::AccountKeyring::*;
48-
use sp_runtime::{traits::Header as HeaderT, AccountId32};
48+
use sp_runtime::{
49+
traits::{Header as HeaderT, Zero},
50+
AccountId32,
51+
};
4952
use xcm::latest::prelude::*;
5053
use xcm_builder::DispatchBlobError;
51-
use xcm_executor::XcmExecutor;
54+
use xcm_executor::{traits::WeightBounds, XcmExecutor};
5255

5356
// Re-export test_case from assets
5457
pub use asset_test_utils::include_teleports_for_native_asset_works;
@@ -132,6 +135,7 @@ pub fn handle_export_message_from_system_parachain_to_outbound_queue_works<
132135
>,
133136
export_message_instruction: fn() -> Instruction<XcmConfig::RuntimeCall>,
134137
expected_lane_id: LaneId,
138+
// TODO: add paid or unpaid
135139
) where
136140
Runtime: frame_system::Config
137141
+ pallet_balances::Config
@@ -757,6 +761,109 @@ pub fn complex_relay_extrinsic_works<Runtime, XcmConfig, HrmpChannelOpener, GPI,
757761
})
758762
}
759763

764+
pub fn can_calculate_weight_for_paid_export_message_with_reserve_transfer<
765+
Runtime,
766+
XcmConfig,
767+
WeightToFee,
768+
>()
769+
where
770+
Runtime: frame_system::Config + pallet_balances::Config,
771+
XcmConfig: xcm_executor::Config,
772+
WeightToFee: frame_support::weights::WeightToFee<Balance = BalanceOf<Runtime>>,
773+
<WeightToFee as frame_support::weights::WeightToFee>::Balance: From<u128> + Into<u128>,
774+
{
775+
// data here are not relevant for weighing
776+
let mut xcm = Xcm(vec![
777+
WithdrawAsset(MultiAssets::from(vec![MultiAsset {
778+
id: Concrete(MultiLocation { parents: 1, interior: Here }),
779+
fun: Fungible(34333299),
780+
}])),
781+
BuyExecution {
782+
fees: MultiAsset {
783+
id: Concrete(MultiLocation { parents: 1, interior: Here }),
784+
fun: Fungible(34333299),
785+
},
786+
weight_limit: Unlimited,
787+
},
788+
ExportMessage {
789+
network: Polkadot,
790+
destination: X1(Parachain(1000)),
791+
xcm: Xcm(vec![
792+
ReserveAssetDeposited(MultiAssets::from(vec![MultiAsset {
793+
id: Concrete(MultiLocation {
794+
parents: 2,
795+
interior: X1(GlobalConsensus(Kusama)),
796+
}),
797+
fun: Fungible(1000000000000),
798+
}])),
799+
ClearOrigin,
800+
BuyExecution {
801+
fees: MultiAsset {
802+
id: Concrete(MultiLocation {
803+
parents: 2,
804+
interior: X1(GlobalConsensus(Kusama)),
805+
}),
806+
fun: Fungible(1000000000000),
807+
},
808+
weight_limit: Unlimited,
809+
},
810+
DepositAsset {
811+
assets: Wild(AllCounted(1)),
812+
beneficiary: MultiLocation {
813+
parents: 0,
814+
interior: X1(xcm::latest::prelude::AccountId32 {
815+
network: None,
816+
id: [
817+
212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159,
818+
214, 130, 44, 133, 88, 133, 76, 205, 227, 154, 86, 132, 231, 165,
819+
109, 162, 125,
820+
],
821+
}),
822+
},
823+
},
824+
SetTopic([
825+
116, 82, 194, 132, 171, 114, 217, 165, 23, 37, 161, 177, 165, 179, 247, 114,
826+
137, 101, 147, 70, 28, 157, 168, 32, 154, 63, 74, 228, 152, 180, 5, 63,
827+
]),
828+
]),
829+
},
830+
RefundSurplus,
831+
DepositAsset {
832+
assets: Wild(All),
833+
beneficiary: MultiLocation { parents: 1, interior: X1(Parachain(1000)) },
834+
},
835+
SetTopic([
836+
36, 224, 250, 165, 82, 195, 67, 110, 160, 170, 140, 87, 217, 62, 201, 164, 42, 98, 219,
837+
157, 124, 105, 248, 25, 131, 218, 199, 36, 109, 173, 100, 122,
838+
]),
839+
]);
840+
841+
// get weight
842+
let weight = XcmConfig::Weigher::weight(&mut xcm);
843+
assert_ok!(weight);
844+
let weight = weight.unwrap();
845+
// check if sane
846+
let max_expected = Runtime::BlockWeights::get().max_block / 10;
847+
assert!(
848+
weight.all_lte(max_expected),
849+
"calculated weight: {:?}, max_expected: {:?}",
850+
weight,
851+
max_expected
852+
);
853+
854+
// check fee, should not be 0
855+
let estimated_fee = WeightToFee::weight_to_fee(&weight);
856+
assert!(estimated_fee > BalanceOf::<Runtime>::zero());
857+
858+
frame_support::sp_tracing::try_init_simple();
859+
log::error!(
860+
target: "bridges::estimate",
861+
"Estimate fee: {:?} for `ExportMessage` for runtime: {:?}",
862+
estimated_fee,
863+
Runtime::Version::get(),
864+
)
865+
}
866+
760867
pub mod test_data {
761868
use super::*;
762869
use bp_header_chain::justification::GrandpaJustification;

0 commit comments

Comments
 (0)