@@ -45,10 +45,13 @@ use parachains_runtimes_test_utils::{
4545} ;
4646use sp_core:: H256 ;
4747use 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+ } ;
4952use xcm:: latest:: prelude:: * ;
5053use xcm_builder:: DispatchBlobError ;
51- use xcm_executor:: XcmExecutor ;
54+ use xcm_executor:: { traits :: WeightBounds , XcmExecutor } ;
5255
5356// Re-export test_case from assets
5457pub 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+
760867pub mod test_data {
761868 use super :: * ;
762869 use bp_header_chain:: justification:: GrandpaJustification ;
0 commit comments