@@ -576,6 +576,15 @@ fn make_candidate_backed_event(candidate_receipt: CandidateReceipt) -> Candidate
576
576
)
577
577
}
578
578
579
+ fn make_candidate_included_event ( candidate_receipt : CandidateReceipt ) -> CandidateEvent {
580
+ CandidateEvent :: CandidateIncluded (
581
+ candidate_receipt,
582
+ HeadData ( Vec :: new ( ) ) ,
583
+ CoreIndex ( 0 ) ,
584
+ GroupIndex ( 0 ) ,
585
+ )
586
+ }
587
+
579
588
/// Handle request for approval votes:
580
589
pub async fn handle_approval_vote_request (
581
590
ctx_handle : & mut VirtualOverseer ,
@@ -736,8 +745,10 @@ fn too_many_unconfirmed_statements_are_considered_spam() {
736
745
} ) ;
737
746
}
738
747
739
- #[ test]
740
- fn approval_vote_import_works ( ) {
748
+ fn approval_vote_import_test < F > ( generate_event_factory : F )
749
+ where
750
+ F : FnOnce ( CandidateReceipt ) -> CandidateEvent + Send + ' static ,
751
+ {
741
752
test_harness ( |mut test_state, mut virtual_overseer| {
742
753
Box :: pin ( async move {
743
754
let session = 1 ;
@@ -752,7 +763,7 @@ fn approval_vote_import_works() {
752
763
& mut virtual_overseer,
753
764
session,
754
765
1 ,
755
- vec ! [ make_candidate_backed_event ( candidate_receipt1. clone( ) ) ] ,
766
+ vec ! [ generate_event_factory ( candidate_receipt1. clone( ) ) ] ,
756
767
)
757
768
. await ;
758
769
@@ -836,6 +847,116 @@ fn approval_vote_import_works() {
836
847
} ) ;
837
848
}
838
849
850
+ #[ test]
851
+ fn approval_vote_import_works_for_backed ( ) {
852
+ approval_vote_import_test ( make_candidate_backed_event)
853
+ }
854
+
855
+ #[ test]
856
+ fn approval_vote_import_works_for_included ( ) {
857
+ approval_vote_import_test ( make_candidate_included_event)
858
+ }
859
+
860
+ #[ test]
861
+ fn approval_vote_import_works_for_confirmed ( ) {
862
+ test_harness ( |mut test_state, mut virtual_overseer| {
863
+ Box :: pin ( async move {
864
+ let session = 1 ;
865
+
866
+ test_state. handle_resume_sync ( & mut virtual_overseer, session) . await ;
867
+
868
+ let candidate_receipt1 = make_valid_candidate_receipt ( ) ;
869
+ let candidate_hash1 = candidate_receipt1. hash ( ) ;
870
+
871
+ test_state
872
+ . activate_leaf_at_session ( & mut virtual_overseer, session, 1 , Vec :: new ( ) )
873
+ . await ;
874
+
875
+ let valid_vote1 = test_state
876
+ . issue_backing_statement_with_index ( ValidatorIndex ( 3 ) , candidate_hash1, session)
877
+ . await ;
878
+
879
+ let valid_vote1a = test_state
880
+ . issue_backing_statement_with_index ( ValidatorIndex ( 2 ) , candidate_hash1, session)
881
+ . await ;
882
+
883
+ let invalid_vote1 = test_state
884
+ . issue_explicit_statement_with_index (
885
+ ValidatorIndex ( 1 ) ,
886
+ candidate_hash1,
887
+ session,
888
+ false ,
889
+ )
890
+ . await ;
891
+
892
+ let approval_vote = test_state. issue_approval_vote_with_index (
893
+ ValidatorIndex ( 4 ) ,
894
+ candidate_hash1,
895
+ session,
896
+ ) ;
897
+
898
+ gum:: trace!( "Before sending `ImportStatements`" ) ;
899
+ virtual_overseer
900
+ . send ( FromOrchestra :: Communication {
901
+ msg : DisputeCoordinatorMessage :: ImportStatements {
902
+ candidate_receipt : candidate_receipt1. clone ( ) ,
903
+ session,
904
+ statements : vec ! [
905
+ ( valid_vote1, ValidatorIndex ( 3 ) ) ,
906
+ ( valid_vote1a, ValidatorIndex ( 2 ) ) ,
907
+ ( invalid_vote1, ValidatorIndex ( 1 ) ) ,
908
+ ] ,
909
+ pending_confirmation : None ,
910
+ } ,
911
+ } )
912
+ . await ;
913
+ gum:: trace!( "After sending `ImportStatements`" ) ;
914
+
915
+ let approval_votes = [ ( ValidatorIndex ( 4 ) , approval_vote. into_validator_signature ( ) ) ]
916
+ . into_iter ( )
917
+ . collect ( ) ;
918
+ handle_approval_vote_request ( & mut virtual_overseer, & candidate_hash1, approval_votes)
919
+ . await ;
920
+
921
+ // Participation has to fail, otherwise the dispute will be confirmed.
922
+ participation_missing_availability ( & mut virtual_overseer) . await ;
923
+
924
+ {
925
+ let ( tx, rx) = oneshot:: channel ( ) ;
926
+ virtual_overseer
927
+ . send ( FromOrchestra :: Communication {
928
+ msg : DisputeCoordinatorMessage :: ActiveDisputes ( tx) ,
929
+ } )
930
+ . await ;
931
+
932
+ assert_eq ! ( rx. await . unwrap( ) , vec![ ( session, candidate_hash1) ] ) ;
933
+
934
+ let ( tx, rx) = oneshot:: channel ( ) ;
935
+ virtual_overseer
936
+ . send ( FromOrchestra :: Communication {
937
+ msg : DisputeCoordinatorMessage :: QueryCandidateVotes (
938
+ vec ! [ ( session, candidate_hash1) ] ,
939
+ tx,
940
+ ) ,
941
+ } )
942
+ . await ;
943
+
944
+ let ( _, _, votes) = rx. await . unwrap ( ) . get ( 0 ) . unwrap ( ) . clone ( ) ;
945
+ assert_eq ! ( votes. valid. len( ) , 3 ) ;
946
+ assert ! ( votes. valid. get( & ValidatorIndex ( 4 ) ) . is_some( ) , "Approval vote is missing!" ) ;
947
+ assert_eq ! ( votes. invalid. len( ) , 1 ) ;
948
+ }
949
+
950
+ virtual_overseer. send ( FromOrchestra :: Signal ( OverseerSignal :: Conclude ) ) . await ;
951
+
952
+ // No more messages expected:
953
+ assert ! ( virtual_overseer. try_recv( ) . await . is_none( ) ) ;
954
+
955
+ test_state
956
+ } )
957
+ } ) ;
958
+ }
959
+
839
960
#[ test]
840
961
fn dispute_gets_confirmed_via_participation ( ) {
841
962
test_harness ( |mut test_state, mut virtual_overseer| {
@@ -3036,3 +3157,103 @@ fn disputes_on_not_backed_candidates_are_ignored() {
3036
3157
} )
3037
3158
} ) ;
3038
3159
}
3160
+
3161
+ #[ test]
3162
+ fn my_test ( ) {
3163
+ test_harness ( |mut test_state, mut virtual_overseer| {
3164
+ Box :: pin ( async move {
3165
+ let session = 1 ;
3166
+
3167
+ test_state. handle_resume_sync ( & mut virtual_overseer, session) . await ;
3168
+
3169
+ let candidate_receipt1 = make_valid_candidate_receipt ( ) ;
3170
+ let candidate_hash1 = candidate_receipt1. hash ( ) ;
3171
+
3172
+ test_state
3173
+ . activate_leaf_at_session (
3174
+ & mut virtual_overseer,
3175
+ session,
3176
+ 1 ,
3177
+ vec ! [ make_candidate_included_event( candidate_receipt1. clone( ) ) ] ,
3178
+ )
3179
+ . await ;
3180
+
3181
+ let valid_vote1 = test_state
3182
+ . issue_backing_statement_with_index ( ValidatorIndex ( 3 ) , candidate_hash1, session)
3183
+ . await ;
3184
+
3185
+ let invalid_vote1 = test_state
3186
+ . issue_explicit_statement_with_index (
3187
+ ValidatorIndex ( 1 ) ,
3188
+ candidate_hash1,
3189
+ session,
3190
+ false ,
3191
+ )
3192
+ . await ;
3193
+
3194
+ let approval_vote = test_state. issue_approval_vote_with_index (
3195
+ ValidatorIndex ( 4 ) ,
3196
+ candidate_hash1,
3197
+ session,
3198
+ ) ;
3199
+
3200
+ gum:: trace!( "Before sending `ImportStatements`" ) ;
3201
+ virtual_overseer
3202
+ . send ( FromOrchestra :: Communication {
3203
+ msg : DisputeCoordinatorMessage :: ImportStatements {
3204
+ candidate_receipt : candidate_receipt1. clone ( ) ,
3205
+ session,
3206
+ statements : vec ! [
3207
+ ( valid_vote1, ValidatorIndex ( 3 ) ) ,
3208
+ ( invalid_vote1, ValidatorIndex ( 1 ) ) ,
3209
+ ] ,
3210
+ pending_confirmation : None ,
3211
+ } ,
3212
+ } )
3213
+ . await ;
3214
+ gum:: trace!( "After sending `ImportStatements`" ) ;
3215
+
3216
+ let approval_votes = [ ( ValidatorIndex ( 4 ) , approval_vote. into_validator_signature ( ) ) ]
3217
+ . into_iter ( )
3218
+ . collect ( ) ;
3219
+ handle_approval_vote_request ( & mut virtual_overseer, & candidate_hash1, approval_votes)
3220
+ . await ;
3221
+
3222
+ // Participation has to fail, otherwise the dispute will be confirmed.
3223
+ participation_missing_availability ( & mut virtual_overseer) . await ;
3224
+
3225
+ {
3226
+ let ( tx, rx) = oneshot:: channel ( ) ;
3227
+ virtual_overseer
3228
+ . send ( FromOrchestra :: Communication {
3229
+ msg : DisputeCoordinatorMessage :: ActiveDisputes ( tx) ,
3230
+ } )
3231
+ . await ;
3232
+
3233
+ assert_eq ! ( rx. await . unwrap( ) , vec![ ( session, candidate_hash1) ] ) ;
3234
+
3235
+ let ( tx, rx) = oneshot:: channel ( ) ;
3236
+ virtual_overseer
3237
+ . send ( FromOrchestra :: Communication {
3238
+ msg : DisputeCoordinatorMessage :: QueryCandidateVotes (
3239
+ vec ! [ ( session, candidate_hash1) ] ,
3240
+ tx,
3241
+ ) ,
3242
+ } )
3243
+ . await ;
3244
+
3245
+ let ( _, _, votes) = rx. await . unwrap ( ) . get ( 0 ) . unwrap ( ) . clone ( ) ;
3246
+ assert_eq ! ( votes. valid. len( ) , 2 ) ;
3247
+ assert ! ( votes. valid. get( & ValidatorIndex ( 4 ) ) . is_some( ) , "Approval vote is missing!" ) ;
3248
+ assert_eq ! ( votes. invalid. len( ) , 1 ) ;
3249
+ }
3250
+
3251
+ virtual_overseer. send ( FromOrchestra :: Signal ( OverseerSignal :: Conclude ) ) . await ;
3252
+
3253
+ // No more messages expected:
3254
+ assert ! ( virtual_overseer. try_recv( ) . await . is_none( ) ) ;
3255
+
3256
+ test_state
3257
+ } )
3258
+ } ) ;
3259
+ }
0 commit comments