@@ -19,12 +19,12 @@ use emulated_integration_tests_common::xcm_emulator::ConvertLocation;
1919use frame_support:: pallet_prelude:: TypeInfo ;
2020use hex_literal:: hex;
2121use rococo_westend_system_emulated_network:: BridgeHubRococoParaSender as BridgeHubRococoSender ;
22- use snowbridge_core:: outbound:: OperatingMode ;
22+ use snowbridge_core:: { outbound:: OperatingMode , Channel , ChannelId } ;
2323use snowbridge_pallet_inbound_queue_fixtures:: {
2424 register_token:: make_register_token_message,
2525 register_token_with_insufficient_fee:: make_register_token_with_infufficient_fee_message,
26- send_token :: make_send_token_message , send_token_to_penpal :: make_send_token_to_penpal_message ,
27- InboundQueueFixture ,
26+ send_call_to_penpal :: make_send_call_to_penpal_message , send_token :: make_send_token_message ,
27+ send_token_to_penpal :: make_send_token_to_penpal_message , InboundQueueFixture ,
2828} ;
2929use snowbridge_pallet_system;
3030use snowbridge_router_primitives:: inbound:: {
@@ -42,6 +42,10 @@ const TREASURY_ACCOUNT: [u8; 32] =
4242const WETH : [ u8 ; 20 ] = hex ! ( "87d1f7fdfEe7f651FaBc8bFCB6E086C278b77A7d" ) ;
4343const ETHEREUM_DESTINATION_ADDRESS : [ u8 ; 20 ] = hex ! ( "44a57ee2f2FCcb85FDa2B0B18EBD0D8D2333700e" ) ;
4444const XCM_FEE : u128 = 40_000_000_000 ;
45+ const XCM_WEIGHT : Weight = Weight :: from_parts ( 40_000_000 , 8_000 ) ;
46+ const INSUFFICIENT_XCM_FEE : u128 = 1_000 ;
47+ const INSUFFICIENT_XCM_WEIGHT : Weight = Weight :: from_parts ( 1_000 , 1_000 ) ;
48+ const INSUFFICIENT_FUND : u128 = 1_000 ;
4549
4650#[ derive( Encode , Decode , Debug , PartialEq , Eq , Clone , TypeInfo ) ]
4751pub enum ControlCall {
@@ -545,6 +549,101 @@ fn transact_from_ethereum_to_penpal() {
545549 let sovereign_of_sender = blake2_256 ( & ( b"AccountKey20" , sender) . encode ( ) ) ;
546550 println ! ( "sovereign account of the sender: {:#?}" , hex:: encode( sovereign_of_sender. clone( ) ) ) ;
547551 PenpalA :: fund_accounts ( vec ! [ ( sovereign_of_sender. into( ) , INITIAL_FUND ) ] ) ;
552+ BridgeHubRococo :: fund_para_sovereign ( PenpalA :: para_id ( ) . into ( ) , INITIAL_FUND ) ;
553+
554+ BridgeHubRococo :: execute_with ( || {
555+ type RuntimeEvent = <BridgeHubRococo as Chain >:: RuntimeEvent ;
556+ type Runtime = <BridgeHubRococo as Chain >:: Runtime ;
557+
558+ let agent_id = snowbridge_pallet_system:: agent_id_of :: < Runtime > ( & Location :: new (
559+ 1 ,
560+ [ Parachain ( PenpalA :: para_id ( ) . into ( ) ) ] ,
561+ ) )
562+ . unwrap ( ) ;
563+ snowbridge_pallet_system:: Agents :: < Runtime > :: insert ( agent_id, ( ) ) ;
564+ let channel_id: ChannelId = PenpalA :: para_id ( ) . into ( ) ;
565+ snowbridge_pallet_system:: Channels :: < Runtime > :: insert (
566+ channel_id,
567+ Channel { agent_id, para_id : PenpalA :: para_id ( ) } ,
568+ ) ;
569+
570+ // Construct Send call to penpal message and sent to inbound queue
571+ send_inbound_message ( make_send_call_to_penpal_message ( ) ) . unwrap ( ) ;
572+
573+ assert_expected_events ! (
574+ BridgeHubRococo ,
575+ vec![
576+ RuntimeEvent :: XcmpQueue ( cumulus_pallet_xcmp_queue:: Event :: XcmpMessageSent { .. } ) => { } ,
577+ ]
578+ ) ;
579+ } ) ;
580+
581+ PenpalA :: execute_with ( || {
582+ type RuntimeEvent = <PenpalA as Chain >:: RuntimeEvent ;
583+ // Check that system event remarked on PenPal
584+ assert_expected_events ! (
585+ PenpalA ,
586+ vec![
587+ RuntimeEvent :: System ( frame_system:: Event :: Remarked { .. } ) => { } ,
588+ ]
589+ ) ;
590+ } ) ;
591+ }
592+
593+ #[ test]
594+ fn transact_from_ethereum_to_penpal_insufficient_fee ( ) {
595+ // Fund sender on penpal so that it can pay execution fees.
596+ let sender: H160 = hex ! ( "90A987B944Cb1dCcE5564e5FDeCD7a54D3de27Fe" ) . into ( ) ;
597+ let sovereign_of_sender = blake2_256 ( & ( b"AccountKey20" , sender) . encode ( ) ) ;
598+ println ! ( "sovereign account of the sender: {:#?}" , hex:: encode( sovereign_of_sender. clone( ) ) ) ;
599+ PenpalA :: fund_accounts ( vec ! [ ( sovereign_of_sender. into( ) , INITIAL_FUND ) ] ) ;
600+
601+ BridgeHubRococo :: execute_with ( || {
602+ type RuntimeEvent = <BridgeHubRococo as Chain >:: RuntimeEvent ;
603+
604+ let message_id: H256 = [ 1 ; 32 ] . into ( ) ;
605+ let message = VersionedMessage :: V1 ( MessageV1 {
606+ chain_id : CHAIN_ID ,
607+ command : Command :: Transact {
608+ sender,
609+ fee : INSUFFICIENT_XCM_FEE ,
610+ weight_at_most : XCM_WEIGHT ,
611+ origin_kind : OriginKind :: SovereignAccount ,
612+ payload : hex ! ( "00071468656c6c6f" ) . to_vec ( ) ,
613+ } ,
614+ } ) ;
615+ // Convert the message to XCM
616+ let ( xcm, _) = EthereumInboundQueue :: do_convert ( message_id, message) . unwrap ( ) ;
617+ // Send the XCM
618+ let _ = EthereumInboundQueue :: send_xcm ( xcm, PenpalA :: para_id ( ) . into ( ) ) . unwrap ( ) ;
619+
620+ assert_expected_events ! (
621+ BridgeHubRococo ,
622+ vec![
623+ RuntimeEvent :: XcmpQueue ( cumulus_pallet_xcmp_queue:: Event :: XcmpMessageSent { .. } ) => { } ,
624+ ]
625+ ) ;
626+ } ) ;
627+
628+ PenpalA :: execute_with ( || {
629+ type RuntimeEvent = <PenpalA as Chain >:: RuntimeEvent ;
630+ // Check xcm execution fails on PenPal
631+ assert_expected_events ! (
632+ PenpalA ,
633+ vec![
634+ RuntimeEvent :: MessageQueue ( pallet_message_queue:: Event :: Processed { success: false , .. } ) => { } ,
635+ ]
636+ ) ;
637+ } ) ;
638+ }
639+
640+ #[ test]
641+ fn transact_from_ethereum_to_penpal_sender_insufficient_fund ( ) {
642+ // Fund sender on penpal so that it can pay execution fees.
643+ let sender: H160 = hex ! ( "90A987B944Cb1dCcE5564e5FDeCD7a54D3de27Fe" ) . into ( ) ;
644+ let sovereign_of_sender = blake2_256 ( & ( b"AccountKey20" , sender) . encode ( ) ) ;
645+ println ! ( "sovereign account of the sender: {:#?}" , hex:: encode( sovereign_of_sender. clone( ) ) ) ;
646+ PenpalA :: fund_accounts ( vec ! [ ( sovereign_of_sender. into( ) , INSUFFICIENT_FUND ) ] ) ;
548647
549648 BridgeHubRococo :: execute_with ( || {
550649 type RuntimeEvent = <BridgeHubRococo as Chain >:: RuntimeEvent ;
@@ -555,7 +654,7 @@ fn transact_from_ethereum_to_penpal() {
555654 command : Command :: Transact {
556655 sender,
557656 fee : XCM_FEE ,
558- weight_at_most : Weight :: from_parts ( 40_000_000 , 8_000 ) ,
657+ weight_at_most : XCM_WEIGHT ,
559658 origin_kind : OriginKind :: SovereignAccount ,
560659 payload : hex ! ( "00071468656c6c6f" ) . to_vec ( ) ,
561660 } ,
@@ -575,11 +674,58 @@ fn transact_from_ethereum_to_penpal() {
575674
576675 PenpalA :: execute_with ( || {
577676 type RuntimeEvent = <PenpalA as Chain >:: RuntimeEvent ;
578- // Check that system event remarked on PenPal
677+ // Check xcm execution fails on PenPal
579678 assert_expected_events ! (
580679 PenpalA ,
581680 vec![
582- RuntimeEvent :: System ( frame_system:: Event :: Remarked { .. } ) => { } ,
681+ RuntimeEvent :: MessageQueue ( pallet_message_queue:: Event :: Processed { success: false , .. } ) => { } ,
682+ ]
683+ ) ;
684+ } ) ;
685+ }
686+
687+ #[ test]
688+ fn transact_from_ethereum_to_penpal_insufficient_weight ( ) {
689+ // Fund sender on penpal so that it can pay execution fees.
690+ let sender: H160 = hex ! ( "90A987B944Cb1dCcE5564e5FDeCD7a54D3de27Fe" ) . into ( ) ;
691+ let sovereign_of_sender = blake2_256 ( & ( b"AccountKey20" , sender) . encode ( ) ) ;
692+ println ! ( "sovereign account of the sender: {:#?}" , hex:: encode( sovereign_of_sender. clone( ) ) ) ;
693+ PenpalA :: fund_accounts ( vec ! [ ( sovereign_of_sender. into( ) , INITIAL_FUND ) ] ) ;
694+
695+ BridgeHubRococo :: execute_with ( || {
696+ type RuntimeEvent = <BridgeHubRococo as Chain >:: RuntimeEvent ;
697+
698+ let message_id: H256 = [ 1 ; 32 ] . into ( ) ;
699+ let message = VersionedMessage :: V1 ( MessageV1 {
700+ chain_id : CHAIN_ID ,
701+ command : Command :: Transact {
702+ sender,
703+ fee : XCM_FEE ,
704+ weight_at_most : INSUFFICIENT_XCM_WEIGHT ,
705+ origin_kind : OriginKind :: SovereignAccount ,
706+ payload : hex ! ( "00071468656c6c6f" ) . to_vec ( ) ,
707+ } ,
708+ } ) ;
709+ // Convert the message to XCM
710+ let ( xcm, _) = EthereumInboundQueue :: do_convert ( message_id, message) . unwrap ( ) ;
711+ // Send the XCM
712+ let _ = EthereumInboundQueue :: send_xcm ( xcm, PenpalA :: para_id ( ) . into ( ) ) . unwrap ( ) ;
713+
714+ assert_expected_events ! (
715+ BridgeHubRococo ,
716+ vec![
717+ RuntimeEvent :: XcmpQueue ( cumulus_pallet_xcmp_queue:: Event :: XcmpMessageSent { .. } ) => { } ,
718+ ]
719+ ) ;
720+ } ) ;
721+
722+ PenpalA :: execute_with ( || {
723+ type RuntimeEvent = <PenpalA as Chain >:: RuntimeEvent ;
724+ // Check xcm execution fails on PenPal
725+ assert_expected_events ! (
726+ PenpalA ,
727+ vec![
728+ RuntimeEvent :: MessageQueue ( pallet_message_queue:: Event :: Processed { success: false , .. } ) => { } ,
583729 ]
584730 ) ;
585731 } ) ;
0 commit comments