@@ -299,3 +299,47 @@ macro_rules! generate_owned_bridge_module_tests {
299
299
}
300
300
} ;
301
301
}
302
+
303
+ #[ cfg( test) ]
304
+ mod tests {
305
+ use codec:: Encode ;
306
+ use sp_application_crypto:: sp_core:: { hexdisplay, hexdisplay:: HexDisplay } ;
307
+ use xcm:: VersionedXcm ;
308
+
309
+ fn print_xcm < RuntimeCall > ( xcm : & VersionedXcm < RuntimeCall > ) {
310
+ println ! ( "-----------------" ) ;
311
+ println ! ( "xcm (plain): {:?}" , xcm) ;
312
+ println ! ( "xcm (bytes): {:?}" , xcm. encode( ) ) ;
313
+ println ! ( "xcm (hex): {:?}" , hexdisplay:: HexDisplay :: from( & xcm. encode( ) ) ) ;
314
+ }
315
+
316
+ fn as_hex < RuntimeCall > ( xcm : & VersionedXcm < RuntimeCall > ) -> String {
317
+ HexDisplay :: from ( & xcm. encode ( ) ) . to_string ( )
318
+ }
319
+
320
+ pub type RuntimeCall = ( ) ;
321
+
322
+ #[ test]
323
+ fn generate_versioned_xcm_message_hex_bytes ( ) {
324
+ let xcm: xcm:: v2:: Xcm < RuntimeCall > = xcm:: v2:: Xcm ( vec ! [ xcm:: v2:: Instruction :: Trap ( 43 ) ] ) ;
325
+ let xcm: VersionedXcm < RuntimeCall > = From :: from ( xcm) ;
326
+ print_xcm ( & xcm) ;
327
+ assert_eq ! ( "020419ac" , format!( "{}" , as_hex( & xcm) ) ) ;
328
+
329
+ let xcm: xcm:: v3:: Xcm < RuntimeCall > = vec ! [ xcm:: v3:: Instruction :: Trap ( 43 ) ] . into ( ) ;
330
+ let xcm: VersionedXcm < RuntimeCall > = From :: from ( xcm) ;
331
+ print_xcm ( & xcm) ;
332
+ assert_eq ! ( "030419ac" , format!( "{}" , as_hex( & xcm) ) ) ;
333
+
334
+ let xcm: xcm:: v3:: Xcm < RuntimeCall > = vec ! [
335
+ xcm:: v3:: Instruction :: ClearError ,
336
+ xcm:: v3:: Instruction :: ClearTopic ,
337
+ xcm:: v3:: Instruction :: ClearTransactStatus ,
338
+ xcm:: v3:: Instruction :: Trap ( 43 ) ,
339
+ ]
340
+ . into ( ) ;
341
+ let xcm: VersionedXcm < RuntimeCall > = From :: from ( xcm) ;
342
+ print_xcm ( & xcm) ;
343
+ assert_eq ! ( "0310172c2319ac" , format!( "{}" , as_hex( & xcm) ) ) ;
344
+ }
345
+ }
0 commit comments