@@ -19,7 +19,7 @@ use near_sdk::{
19
19
test_utils:: VMContextBuilder , testing_env, AccountId , CurveType , NearToken , PublicKey ,
20
20
VMContext ,
21
21
} ;
22
- use std:: { collections :: HashSet , time:: Duration } ;
22
+ use std:: time:: Duration ;
23
23
24
24
const SECOND : Duration = Duration :: from_secs ( 1 ) ;
25
25
const NANOS_IN_SECOND : u64 = SECOND . as_nanos ( ) as u64 ;
@@ -65,7 +65,6 @@ impl TestSetup {
65
65
. unwrap ( ) ;
66
66
}
67
67
68
- /// Try to submit attestation and return Result for testing failures
69
68
fn try_submit_attestation_for_node (
70
69
& mut self ,
71
70
node_id : & NodeId ,
@@ -94,7 +93,6 @@ impl TestSetup {
94
93
}
95
94
}
96
95
97
- /// Get NodeIds created from the existing participants
98
96
fn get_participant_node_ids ( & self ) -> Vec < NodeId > {
99
97
self . participants_list
100
98
. iter ( )
@@ -105,8 +103,7 @@ impl TestSetup {
105
103
. collect ( )
106
104
}
107
105
108
- /// Helper to create attestation with hash constraints
109
- fn create_hash_attestation ( hash : [ u8 ; 32 ] ) -> Attestation {
106
+ fn create_attestation_with_hash_constraint ( hash : [ u8 ; 32 ] ) -> Attestation {
110
107
Attestation :: Mock ( MockAttestation :: WithConstraints {
111
108
mpc_docker_image_hash : Some ( hash) ,
112
109
launcher_docker_compose_hash : None ,
@@ -535,23 +532,22 @@ fn nodes_can_start_with_old_valid_hashes_during_grace_period() {
535
532
let test_time_1 = deployment_times[ 2 ] + 3 * NANOS_IN_SECOND ;
536
533
set_system_time ( test_time_1) ;
537
534
538
- let allowed_set : HashSet < _ > = test_setup
535
+ let allowed_hashes : [ _ ; 3 ] = test_setup
539
536
. contract
540
537
. allowed_code_hashes ( )
541
- . iter ( )
542
- . map ( |h| * * h)
543
- . collect ( ) ;
544
- let expected_set: HashSet < _ > = hashes. into_iter ( ) . collect ( ) ;
538
+ . try_into ( )
539
+ . unwrap ( ) ;
540
+ let expected_hashes = [ hash_v1. into ( ) , hash_v2. into ( ) , hash_v3. into ( ) ] ;
545
541
546
- assert_eq ! ( allowed_set , expected_set ) ;
542
+ assert_eq ! ( allowed_hashes , expected_hashes ) ;
547
543
548
544
// Use existing participant nodes for testing different hash versions
549
545
let node_ids = test_setup. get_participant_node_ids ( ) ;
550
546
551
547
// Test that nodes can submit attestations with all hash versions at T=10s
552
548
// All attestations should succeed during grace period (current time: T=10s)
553
549
for ( node, & hash) in node_ids. iter ( ) . zip ( hashes. iter ( ) ) {
554
- let attestation = TestSetup :: create_hash_attestation ( hash) ;
550
+ let attestation = TestSetup :: create_attestation_with_hash_constraint ( hash) ;
555
551
test_setup. submit_attestation_for_node ( node, attestation) ;
556
552
}
557
553
@@ -563,20 +559,21 @@ fn nodes_can_start_with_old_valid_hashes_during_grace_period() {
563
559
// but at T=20s it has expired and should be filtered out by allowed_code_hashes()
564
560
set_system_time ( v1_expiry_time + NANOS_IN_SECOND ) ; // T=20s
565
561
566
- // Verify that only non-expired hashes remain valid at T=20s
567
- // hash_v1 should have already expired, so only hash_v2 and hash_v3 should be allowed
568
- let allowed_after_v1_expiry = test_setup. contract . allowed_code_hashes ( ) ;
569
- let allowed_set_after_v1_expiry: HashSet < _ > =
570
- allowed_after_v1_expiry. iter ( ) . map ( |h| * * h) . collect ( ) ;
571
- let expected_set_after_v1_expiry: HashSet < _ > = [ hash_v2, hash_v3] . into_iter ( ) . collect ( ) ;
562
+ // T=20s: hash_v1 is expired. Verify that only hash_v2 and hash_v3 are allowed.
563
+ let allowed_after_v1_expiry: [ _ ; 2 ] = test_setup
564
+ . contract
565
+ . allowed_code_hashes ( )
566
+ . try_into ( )
567
+ . unwrap ( ) ;
568
+ let expected_after_v1_expiry = [ hash_v2. into ( ) , hash_v3. into ( ) ] ;
572
569
573
570
assert_eq ! (
574
- allowed_set_after_v1_expiry , expected_set_after_v1_expiry ,
571
+ allowed_after_v1_expiry , expected_after_v1_expiry ,
575
572
"Only hash_v2 and hash_v3 should remain valid at T=20s (hash_v1 expired)"
576
573
) ;
577
574
578
575
// Verify that submitting attestation with expired hash_v1 now fails
579
- let expired_attestation = TestSetup :: create_hash_attestation ( hash_v1) ;
576
+ let expired_attestation = TestSetup :: create_attestation_with_hash_constraint ( hash_v1) ;
580
577
let result = test_setup. try_submit_attestation_for_node ( & node_ids[ 0 ] , expired_attestation) ;
581
578
assert ! (
582
579
result. is_err( ) ,
@@ -586,11 +583,8 @@ fn nodes_can_start_with_old_valid_hashes_during_grace_period() {
586
583
// Test late-joining nodes at current time T=20s (after hash_v1 expired)
587
584
// Only hash_v2 and hash_v3 should be valid for new nodes
588
585
// Reuse existing node_ids (nodes 2 and 3 since hash_v1 expired)
589
- for ( node, & hash) in node_ids[ 1 ..]
590
- . iter ( )
591
- . zip ( expected_set_after_v1_expiry. iter ( ) )
592
- {
593
- let late_attestation = TestSetup :: create_hash_attestation ( hash) ;
586
+ for ( node, hash) in node_ids[ 1 ..] . iter ( ) . zip ( expected_after_v1_expiry. iter ( ) ) {
587
+ let late_attestation = TestSetup :: create_attestation_with_hash_constraint ( * * hash) ;
594
588
test_setup. submit_attestation_for_node ( node, late_attestation) ;
595
589
}
596
590
@@ -604,7 +598,7 @@ fn nodes_can_start_with_old_valid_hashes_during_grace_period() {
604
598
605
599
// Verify that only the latest hash is now accepted
606
600
// Reuse the third node (index 2) for final validation
607
- let final_attestation = TestSetup :: create_hash_attestation ( hash_v3) ;
601
+ let final_attestation = TestSetup :: create_attestation_with_hash_constraint ( hash_v3) ;
608
602
// This should succeed since hash_v3 is the only remaining valid hash
609
603
test_setup. submit_attestation_for_node ( & node_ids[ 2 ] , final_attestation) ;
610
604
}
0 commit comments