@@ -2,7 +2,7 @@ use super::*;
22use crate :: metadata_state:: subnet_call_context_manager:: SubnetCallContextManager ;
33use ic_constants:: MAX_INGRESS_TTL ;
44use ic_error_types:: { ErrorCode , UserError } ;
5- use ic_ic00_types:: EcdsaCurve ;
5+ use ic_ic00_types:: { EcdsaCurve , IC_00 } ;
66use ic_registry_routing_table:: CanisterIdRange ;
77use ic_test_utilities:: {
88 mock_time,
@@ -456,15 +456,27 @@ fn system_metadata_split() {
456456 const SUBNET_B : SubnetId = SUBNET_1 ;
457457 const SUBNET_C : SubnetId = SUBNET_2 ;
458458
459- // Ingress history with 2 Received messages, addressed to canisters 1 and 2.
459+ // 2 canisters: we will retain `CANISTER_1` on `SUBNET_A` and split off
460+ // `CANISTER_2` to `SUBNET_B`.
461+ const CANISTER_1 : CanisterId = CanisterId :: from_u64 ( 1 ) ;
462+ const CANISTER_2 : CanisterId = CanisterId :: from_u64 ( 2 ) ;
463+
464+ // Ingress history with 4 Received messages, addressed to canisters 1 and 2;
465+ // `IC_00`; and respectively `SUBNET_A`.
460466 let mut ingress_history = IngressHistoryState :: new ( ) ;
461467 let time = mock_time ( ) ;
462- for i in ( 1 ..=2u64 ) . rev ( ) {
468+ let receivers = [
469+ CANISTER_1 . get ( ) ,
470+ CANISTER_2 . get ( ) ,
471+ IC_00 . get ( ) ,
472+ SUBNET_A . get ( ) ,
473+ ] ;
474+ for ( i, receiver) in receivers. into_iter ( ) . enumerate ( ) . rev ( ) {
463475 ingress_history. insert (
464- message_test_id ( i) ,
476+ message_test_id ( i as u64 ) ,
465477 IngressStatus :: Known {
466- receiver : canister_test_id ( i ) . get ( ) ,
467- user_id : user_test_id ( i) ,
478+ receiver,
479+ user_id : user_test_id ( i as u64 ) ,
468480 time,
469481 state : IngressState :: Received ,
470482 } ,
@@ -473,9 +485,17 @@ fn system_metadata_split() {
473485 ) ;
474486 }
475487
488+ // `CANISTER_1` remains on `SUBNET_A`.
489+ let is_canister_on_subnet_a = |canister_id : & CanisterId | * canister_id == CANISTER_1 ;
490+ // All ingress messages except the one addressed to `CANISTER_2` (including the
491+ // ones for `IC_00` and `SUBNET_A`) should remain on `SUBNET_A` after the split.
492+ let is_receiver_on_subnet_a = |canister_id : & CanisterId | * canister_id != CANISTER_2 ;
493+ // Only ingress messages for `CANISTER_2` should be retained on `SUBNET_B`.
494+ let is_canister_on_subnet_b = |canister_id : & CanisterId | * canister_id == CANISTER_2 ;
495+
476496 let streams = Streams {
477497 streams : btreemap ! { SUBNET_C => Stream :: new( StreamIndexedQueue :: with_begin( 13 . into( ) ) , 14 . into( ) ) } ,
478- responses_size_bytes : btreemap ! { canister_test_id ( 1 ) => 169 } ,
498+ responses_size_bytes : btreemap ! { CANISTER_1 => 169 } ,
479499 } ;
480500
481501 // Use uncommon `SubnetType::VerifiedApplication` to make it more likely to
@@ -503,14 +523,12 @@ fn system_metadata_split() {
503523 // Technically some parts of the `SystemMetadata` (such as `prev_state_hash` and
504524 // `own_subnet_type`) would be replaced during loading. However, we only care
505525 // that `after_split()` does not touch them.
506- let is_canister_on_subnet_a = |canister_id : & CanisterId | * canister_id == canister_test_id ( 0 ) ;
507526 let metadata_a_phase_2 = metadata_a_phase_1. after_split ( is_canister_on_subnet_a) ;
508527
509- // Expect same metadata, but with pruned ingress history, no previous hash and
510- // no split marker.
528+ // Expect same metadata, but with pruned ingress history and no split marker.
511529 expected. ingress_history = expected
512530 . ingress_history
513- . prune_after_split ( is_canister_on_subnet_a ) ;
531+ . prune_after_split ( is_receiver_on_subnet_a ) ;
514532 expected. split_from = None ;
515533 assert_eq ! ( expected, metadata_a_phase_2) ;
516534
@@ -528,10 +546,9 @@ fn system_metadata_split() {
528546 // Technically some parts of the `SystemMetadata` (such as `prev_state_hash` and
529547 // `own_subnet_type`) would be replaced during loading. However, we only care
530548 // that `after_split()` does not touch them.
531- let is_canister_on_subnet_b = |canister_id : & CanisterId | !is_canister_on_subnet_a ( canister_id) ;
532549 let metadata_b_phase_2 = metadata_b_phase_1. after_split ( is_canister_on_subnet_b) ;
533550
534- // Expect pruned ingress history and no previous hash or split marker.
551+ // Expect pruned ingress history and no split marker.
535552 expected. split_from = None ;
536553 expected. ingress_history = expected
537554 . ingress_history
0 commit comments