@@ -154,6 +154,7 @@ impl<T: Config<I>, I: Instance> MessageDispatch<T::AccountId, T::MessageId> for
154154 ) ;
155155 Self :: deposit_event ( RawEvent :: MessageRejected ( source_chain, id) ) ;
156156 return MessageDispatchResult {
157+ dispatch_result : false ,
157158 unspent_weight : 0 ,
158159 dispatch_fee_paid_during_dispatch : false ,
159160 } ;
@@ -163,6 +164,7 @@ impl<T: Config<I>, I: Instance> MessageDispatch<T::AccountId, T::MessageId> for
163164 // verify spec version
164165 // (we want it to be the same, because otherwise we may decode Call improperly)
165166 let mut dispatch_result = MessageDispatchResult {
167+ dispatch_result : false ,
166168 unspent_weight : message. weight ,
167169 dispatch_fee_paid_during_dispatch : false ,
168170 } ;
@@ -303,6 +305,7 @@ impl<T: Config<I>, I: Instance> MessageDispatch<T::AccountId, T::MessageId> for
303305 log:: trace!( target: "runtime::bridge-dispatch" , "Message being dispatched is: {:.4096?}" , & call) ;
304306 let result = call. dispatch ( origin) ;
305307 let actual_call_weight = extract_actual_weight ( & result, & dispatch_info) ;
308+ dispatch_result. dispatch_result = result. is_ok ( ) ;
306309 dispatch_result. unspent_weight = message. weight . saturating_sub ( actual_call_weight) ;
307310
308311 log:: trace!(
@@ -573,6 +576,7 @@ mod tests {
573576 System :: set_block_number ( 1 ) ;
574577 let result = Dispatch :: dispatch ( SOURCE_CHAIN_ID , TARGET_CHAIN_ID , id, Ok ( message) , |_, _| unreachable ! ( ) ) ;
575578 assert_eq ! ( result. unspent_weight, weight) ;
579+ assert ! ( !result. dispatch_result) ;
576580
577581 assert_eq ! (
578582 System :: events( ) ,
@@ -601,6 +605,7 @@ mod tests {
601605 System :: set_block_number ( 1 ) ;
602606 let result = Dispatch :: dispatch ( SOURCE_CHAIN_ID , TARGET_CHAIN_ID , id, Ok ( message) , |_, _| unreachable ! ( ) ) ;
603607 assert_eq ! ( result. unspent_weight, 7 ) ;
608+ assert ! ( !result. dispatch_result) ;
604609
605610 assert_eq ! (
606611 System :: events( ) ,
@@ -633,6 +638,7 @@ mod tests {
633638 System :: set_block_number ( 1 ) ;
634639 let result = Dispatch :: dispatch ( SOURCE_CHAIN_ID , TARGET_CHAIN_ID , id, Ok ( message) , |_, _| unreachable ! ( ) ) ;
635640 assert_eq ! ( result. unspent_weight, weight) ;
641+ assert ! ( !result. dispatch_result) ;
636642
637643 assert_eq ! (
638644 System :: events( ) ,
@@ -683,6 +689,7 @@ mod tests {
683689 System :: set_block_number ( 1 ) ;
684690 let result = Dispatch :: dispatch ( SOURCE_CHAIN_ID , TARGET_CHAIN_ID , id, Ok ( message) , |_, _| unreachable ! ( ) ) ;
685691 assert_eq ! ( result. unspent_weight, weight) ;
692+ assert ! ( !result. dispatch_result) ;
686693
687694 assert_eq ! (
688695 System :: events( ) ,
@@ -711,6 +718,7 @@ mod tests {
711718 System :: set_block_number ( 1 ) ;
712719 let result = Dispatch :: dispatch ( SOURCE_CHAIN_ID , TARGET_CHAIN_ID , id, Ok ( message) , |_, _| unreachable ! ( ) ) ;
713720 assert_eq ! ( result. unspent_weight, weight) ;
721+ assert ! ( !result. dispatch_result) ;
714722
715723 assert_eq ! (
716724 System :: events( ) ,
@@ -739,12 +747,13 @@ mod tests {
739747 System :: set_block_number ( 1 ) ;
740748 let result = Dispatch :: dispatch ( SOURCE_CHAIN_ID , TARGET_CHAIN_ID , id, Ok ( message) , |_, _| Err ( ( ) ) ) ;
741749 assert_eq ! ( result. unspent_weight, weight) ;
750+ assert ! ( !result. dispatch_result) ;
742751
743752 assert_eq ! (
744753 System :: events( ) ,
745754 vec![ EventRecord {
746755 phase: Phase :: Initialization ,
747- event: Event :: call_dispatch ( call_dispatch:: Event :: <TestRuntime >:: MessageDispatchPaymentFailed (
756+ event: Event :: Dispatch ( call_dispatch:: Event :: <TestRuntime >:: MessageDispatchPaymentFailed (
748757 SOURCE_CHAIN_ID ,
749758 id,
750759 AccountIdConverter :: convert( derive_account_id:: <AccountId >(
@@ -771,12 +780,13 @@ mod tests {
771780 System :: set_block_number ( 1 ) ;
772781 let result = Dispatch :: dispatch ( SOURCE_CHAIN_ID , TARGET_CHAIN_ID , id, Ok ( message) , |_, _| Ok ( ( ) ) ) ;
773782 assert ! ( result. dispatch_fee_paid_during_dispatch) ;
783+ assert ! ( result. dispatch_result) ;
774784
775785 assert_eq ! (
776786 System :: events( ) ,
777787 vec![ EventRecord {
778788 phase: Phase :: Initialization ,
779- event: Event :: call_dispatch ( call_dispatch:: Event :: <TestRuntime >:: MessageDispatched (
789+ event: Event :: Dispatch ( call_dispatch:: Event :: <TestRuntime >:: MessageDispatched (
780790 SOURCE_CHAIN_ID ,
781791 id,
782792 Ok ( ( ) )
@@ -787,6 +797,34 @@ mod tests {
787797 } ) ;
788798 }
789799
800+ #[ test]
801+ fn should_return_dispatch_failed_flag_if_dispatch_happened_but_failed ( ) {
802+ new_test_ext ( ) . execute_with ( || {
803+ let id = [ 0 ; 4 ] ;
804+
805+ let call = Call :: System ( <frame_system:: Call < TestRuntime > >:: set_heap_pages ( 1 ) ) ;
806+ let message = prepare_target_message ( call) ;
807+
808+ System :: set_block_number ( 1 ) ;
809+ let result = Dispatch :: dispatch ( SOURCE_CHAIN_ID , TARGET_CHAIN_ID , id, Ok ( message) , |_, _| unreachable ! ( ) ) ;
810+ assert ! ( !result. dispatch_fee_paid_during_dispatch) ;
811+ assert ! ( !result. dispatch_result) ;
812+
813+ assert_eq ! (
814+ System :: events( ) ,
815+ vec![ EventRecord {
816+ phase: Phase :: Initialization ,
817+ event: Event :: Dispatch ( call_dispatch:: Event :: <TestRuntime >:: MessageDispatched (
818+ SOURCE_CHAIN_ID ,
819+ id,
820+ Err ( sp_runtime:: DispatchError :: BadOrigin )
821+ ) ) ,
822+ topics: vec![ ] ,
823+ } ] ,
824+ ) ;
825+ } )
826+ }
827+
790828 #[ test]
791829 fn should_dispatch_bridge_message_from_root_origin ( ) {
792830 new_test_ext ( ) . execute_with ( || {
@@ -796,6 +834,7 @@ mod tests {
796834 System :: set_block_number ( 1 ) ;
797835 let result = Dispatch :: dispatch ( SOURCE_CHAIN_ID , TARGET_CHAIN_ID , id, Ok ( message) , |_, _| unreachable ! ( ) ) ;
798836 assert ! ( !result. dispatch_fee_paid_during_dispatch) ;
837+ assert ! ( result. dispatch_result) ;
799838
800839 assert_eq ! (
801840 System :: events( ) ,
@@ -823,6 +862,7 @@ mod tests {
823862 System :: set_block_number ( 1 ) ;
824863 let result = Dispatch :: dispatch ( SOURCE_CHAIN_ID , TARGET_CHAIN_ID , id, Ok ( message) , |_, _| unreachable ! ( ) ) ;
825864 assert ! ( !result. dispatch_fee_paid_during_dispatch) ;
865+ assert ! ( result. dispatch_result) ;
826866
827867 assert_eq ! (
828868 System :: events( ) ,
@@ -850,6 +890,7 @@ mod tests {
850890 System :: set_block_number ( 1 ) ;
851891 let result = Dispatch :: dispatch ( SOURCE_CHAIN_ID , TARGET_CHAIN_ID , id, Ok ( message) , |_, _| unreachable ! ( ) ) ;
852892 assert ! ( !result. dispatch_fee_paid_during_dispatch) ;
893+ assert ! ( result. dispatch_result) ;
853894
854895 assert_eq ! (
855896 System :: events( ) ,
0 commit comments