@@ -500,12 +500,15 @@ mod test {
500
500
// subscription config
501
501
let committee_count = 1 ;
502
502
503
- // Makes 2 validator subscriptions to the same subnet but at different slots.
504
- // There should be just 1 unsubscription event for the later slot subscription (subscription_slot2).
503
+ // Makes 3 validator subscriptions to the same subnet but at different slots.
504
+ // There should be just 1 unsubscription event for each of the later slots subscriptions
505
+ // (subscription_slot2 and subscription_slot3).
505
506
let subscription_slot1 = 0 ;
506
507
let subscription_slot2 = MIN_PEER_DISCOVERY_SLOT_LOOK_AHEAD + 4 ;
508
+ let subscription_slot3 = subscription_slot2 * 2 ;
507
509
let com1 = MIN_PEER_DISCOVERY_SLOT_LOOK_AHEAD + 4 ;
508
510
let com2 = 0 ;
511
+ let com3 = CHAIN . chain . spec . attestation_subnet_count - com1;
509
512
510
513
// create the attestation service and subscriptions
511
514
let mut subnet_service = get_subnet_service ( ) ;
@@ -532,6 +535,13 @@ mod test {
532
535
true ,
533
536
) ;
534
537
538
+ let sub3 = get_subscription (
539
+ com3,
540
+ current_slot + Slot :: new ( subscription_slot3) ,
541
+ committee_count,
542
+ true ,
543
+ ) ;
544
+
535
545
let subnet_id1 = SubnetId :: compute_subnet :: < MainnetEthSpec > (
536
546
current_slot + Slot :: new ( subscription_slot1) ,
537
547
com1,
@@ -548,12 +558,23 @@ mod test {
548
558
)
549
559
. unwrap ( ) ;
550
560
561
+ let subnet_id3 = SubnetId :: compute_subnet :: < MainnetEthSpec > (
562
+ current_slot + Slot :: new ( subscription_slot3) ,
563
+ com3,
564
+ committee_count,
565
+ & subnet_service. beacon_chain . spec ,
566
+ )
567
+ . unwrap ( ) ;
568
+
551
569
// Assert that subscriptions are different but their subnet is the same
552
570
assert_ne ! ( sub1, sub2) ;
571
+ assert_ne ! ( sub1, sub3) ;
572
+ assert_ne ! ( sub2, sub3) ;
553
573
assert_eq ! ( subnet_id1, subnet_id2) ;
574
+ assert_eq ! ( subnet_id1, subnet_id3) ;
554
575
555
576
// submit the subscriptions
556
- subnet_service. validator_subscriptions ( vec ! [ sub1, sub2] . into_iter ( ) ) ;
577
+ subnet_service. validator_subscriptions ( vec ! [ sub1, sub2, sub3 ] . into_iter ( ) ) ;
557
578
558
579
// Unsubscription event should happen at the end of the slot.
559
580
// We wait for 2 slots, to avoid timeout issues
@@ -590,10 +611,36 @@ mod test {
590
611
// If the permanent and short lived subnets are different, we should get an unsubscription event.
591
612
if !subnet_service. is_subscribed ( & Subnet :: Attestation ( subnet_id1) ) {
592
613
assert_eq ! (
593
- [ expected_subscription, expected_unsubscription] ,
614
+ [
615
+ expected_subscription. clone( ) ,
616
+ expected_unsubscription. clone( ) ,
617
+ ] ,
594
618
second_subscribe_event[ ..]
595
619
) ;
596
620
}
621
+
622
+ let subscription_slot = current_slot + subscription_slot3 - 1 ;
623
+
624
+ let wait_slots = subnet_service
625
+ . beacon_chain
626
+ . slot_clock
627
+ . duration_to_slot ( subscription_slot)
628
+ . unwrap ( )
629
+ . as_millis ( ) as u64
630
+ / SLOT_DURATION_MILLIS ;
631
+
632
+ let no_events = dbg ! ( get_events( & mut subnet_service, None , wait_slots as u32 ) . await ) ;
633
+
634
+ assert_eq ! ( no_events, [ ] ) ;
635
+
636
+ let third_subscribe_event = get_events ( & mut subnet_service, None , 2 ) . await ;
637
+
638
+ if !subnet_service. is_subscribed ( & Subnet :: Attestation ( subnet_id1) ) {
639
+ assert_eq ! (
640
+ [ expected_subscription, expected_unsubscription] ,
641
+ third_subscribe_event[ ..]
642
+ ) ;
643
+ }
597
644
}
598
645
599
646
#[ tokio:: test]
0 commit comments