@@ -744,9 +744,8 @@ pub mod validator_message {
744744
745745 use primitives:: {
746746 balances:: UncheckedState ,
747- config:: GANACHE_CONFIG ,
748747 sentry:: validator_messages:: ValidatorMessagesCreateRequest ,
749- test_util:: { ADVERTISER , DUMMY_CAMPAIGN , IDS , LEADER } ,
748+ test_util:: { ADVERTISER , CAMPAIGNS , IDS , LEADER } ,
750749 validator:: {
751750 ApproveState , Heartbeat , MessageType , MessageTypes , NewState , RejectState ,
752751 } ,
@@ -757,34 +756,25 @@ pub mod validator_message {
757756 async fn post_validator_messages ( ) {
758757 let app_guard = setup_dummy_app ( ) . await ;
759758 let app = Extension ( Arc :: new ( app_guard. app . clone ( ) ) ) ;
760- let config = GANACHE_CONFIG . clone ( ) ;
761759 let all_message_types: [ MessageType ; 4 ] = [
762760 MessageType :: NewState ,
763761 MessageType :: ApproveState ,
764762 MessageType :: RejectState ,
765763 MessageType :: Heartbeat ,
766764 ] ;
767765
768- let channel_context = Extension (
769- app. config
770- . find_chain_of ( DUMMY_CAMPAIGN . channel . token )
771- . expect ( "Dummy channel Token should be present in config!" )
772- . with ( DUMMY_CAMPAIGN . channel ) ,
773- ) ;
774-
775- let chain_context = config
776- . find_chain_of ( DUMMY_CAMPAIGN . channel . token )
777- . expect ( "Campaign's Channel.token should be set in config" ) ;
766+ let channel_context = Extension ( CAMPAIGNS [ 0 ] . clone ( ) . of_channel ( ) ) ;
778767
779768 insert_channel ( & app. pool , & channel_context)
780769 . await
781770 . expect ( "should insert channel" ) ;
771+
782772 // Case when the request is not sent by a channel validator
783773 {
784774 let auth = Auth {
785775 era : 0 ,
786776 uid : IDS [ & ADVERTISER ] ,
787- chain : chain_context . chain . clone ( ) ,
777+ chain : channel_context . chain . clone ( ) ,
788778 } ;
789779
790780 let req = ValidatorMessagesCreateRequest { messages : vec ! [ ] } ;
@@ -795,17 +785,19 @@ pub mod validator_message {
795785 channel_context. clone ( ) ,
796786 Json ( req) ,
797787 )
798- . await ;
788+ . await
789+ . expect_err ( "We expect an error to be returned" ) ;
799790
800- assert ! ( matches! ( res, Err ( ResponseError :: Unauthorized ) ) ) ;
791+ assert_eq ! ( res, ResponseError :: Unauthorized ) ;
801792 }
793+
802794 // Cases where we insert validator messages
803795 // Case with 0 messages
804796 {
805797 let auth = Auth {
806798 era : 0 ,
807799 uid : IDS [ & LEADER ] ,
808- chain : chain_context . chain . clone ( ) ,
800+ chain : channel_context . chain . clone ( ) ,
809801 } ;
810802
811803 let req = ValidatorMessagesCreateRequest { messages : vec ! [ ] } ;
@@ -836,17 +828,17 @@ pub mod validator_message {
836828 let auth = Auth {
837829 era : 0 ,
838830 uid : IDS [ & LEADER ] ,
839- chain : chain_context . chain . clone ( ) ,
831+ chain : channel_context . chain . clone ( ) ,
840832 } ;
841833
842- let message = Heartbeat {
834+ let message = MessageTypes :: Heartbeat ( Heartbeat {
843835 signature : String :: new ( ) ,
844836 state_root : String :: new ( ) ,
845837 timestamp : Utc :: now ( ) ,
846- } ;
838+ } ) ;
847839
848840 let req = ValidatorMessagesCreateRequest {
849- messages : vec ! [ MessageTypes :: Heartbeat ( message. clone( ) ) ] ,
841+ messages : vec ! [ message. clone( ) ] ,
850842 } ;
851843
852844 create_validator_messages (
@@ -869,14 +861,14 @@ pub mod validator_message {
869861 . expect ( "should get messages" ) ;
870862 let inner_messages: Vec < MessageTypes > =
871863 messages. into_iter ( ) . map ( |m| m. msg . clone ( ) ) . collect ( ) ;
872- assert_eq ! ( inner_messages, vec![ MessageTypes :: Heartbeat ( message) ] ) ;
864+ assert_eq ! ( inner_messages, vec![ message] ) ;
873865 }
874866 // Case with 4 messages (one of each type, heartbeat is already inserted)
875867 {
876868 let auth = Auth {
877869 era : 0 ,
878870 uid : IDS [ & LEADER ] ,
879- chain : chain_context . chain . clone ( ) ,
871+ chain : channel_context . chain . clone ( ) ,
880872 } ;
881873
882874 let state_root =
@@ -888,31 +880,31 @@ pub mod validator_message {
888880 . expect ( "should unlock" )
889881 . sign ( & state_root. clone ( ) )
890882 . expect ( "should sign" ) ;
891- let new_state: NewState < UncheckedState > = NewState {
883+ let new_state = MessageTypes :: NewState ( NewState {
892884 state_root : state_root. clone ( ) ,
893885 signature : signature. clone ( ) ,
894- balances : Balances :: new ( ) ,
895- } ;
886+ balances : Balances :: < UncheckedState > :: new ( ) ,
887+ } ) ;
896888
897- let approve_state = ApproveState {
889+ let approve_state = MessageTypes :: ApproveState ( ApproveState {
898890 state_root : state_root. clone ( ) ,
899891 signature : signature. clone ( ) ,
900892 is_healthy : true ,
901- } ;
893+ } ) ;
902894
903- let reject_state = RejectState {
895+ let reject_state = MessageTypes :: RejectState ( RejectState {
904896 state_root,
905897 signature : signature. clone ( ) ,
906898 timestamp : Utc :: now ( ) ,
907899 reason : "rejected" . to_string ( ) ,
908900 balances : None ,
909- } ;
901+ } ) ;
910902
911903 let req = ValidatorMessagesCreateRequest {
912904 messages : vec ! [
913- MessageTypes :: NewState ( new_state. clone( ) ) ,
914- MessageTypes :: ApproveState ( approve_state. clone( ) ) ,
915- MessageTypes :: RejectState ( reject_state. clone( ) ) ,
905+ new_state. clone( ) ,
906+ approve_state. clone( ) ,
907+ reject_state. clone( ) ,
916908 ] ,
917909 } ;
918910
0 commit comments