@@ -71,7 +71,16 @@ impl CertificatesHashMigrator {
71
71
old_previous_hash
72
72
} ;
73
73
74
- let new_hash = certificate. compute_hash ( ) ;
74
+ let new_hash = {
75
+ let computed_hash = certificate. compute_hash ( ) ;
76
+ // return none if the hash did not change to trigger an error
77
+ ( computed_hash != certificate. hash ) . then_some ( computed_hash)
78
+ }
79
+ . ok_or ( format ! (
80
+ "Hash did not change for certificate {:?}, hash: {}" ,
81
+ certificate. beacon, certificate. hash
82
+ ) ) ?;
83
+
75
84
old_and_new_hashes. insert ( certificate. hash . clone ( ) , new_hash. clone ( ) ) ;
76
85
77
86
if certificate. is_genesis ( ) {
@@ -555,4 +564,26 @@ mod test {
555
564
)
556
565
. await ;
557
566
}
567
+
568
+ #[ tokio:: test]
569
+ async fn should_fail_if_any_hash_doesnt_change ( ) {
570
+ let connection = Arc :: new ( Mutex :: new ( connection_without_foreign_key_support ( ) ) ) ;
571
+ let certificate = {
572
+ let mut cert = dummy_genesis ( "whatever" , 1 , 2 ) ;
573
+ cert. hash = cert. compute_hash ( ) ;
574
+ cert
575
+ } ;
576
+ fill_certificates_and_signed_entities_in_db ( connection. clone ( ) , & [ ( certificate, None ) ] )
577
+ . await
578
+ . unwrap ( ) ;
579
+
580
+ let migrator = CertificatesHashMigrator :: new (
581
+ CertificateRepository :: new ( connection. clone ( ) ) ,
582
+ Arc :: new ( SignedEntityStoreAdapter :: new ( connection. clone ( ) ) ) ,
583
+ ) ;
584
+ migrator
585
+ . migrate ( )
586
+ . await
587
+ . expect_err ( "Migration should fail if an hash doesnt change" ) ;
588
+ }
558
589
}
0 commit comments