@@ -397,7 +397,7 @@ mod application_lookup_tests {
397397
398398 assert_eq ! (
399399 storage. lookup_application_number_with_origin( & origin) ,
400- expected_old ,
400+ expected_new ,
401401 "Unexpected result from lookup_application_number_with_origin for origin {}" ,
402402 origin
403403 ) ;
@@ -484,41 +484,47 @@ mod application_lookup_tests {
484484
485485 // These origins have hash prefix collisions with 8-byte hash but not with full SHA-256.
486486 // Example taken from https://github.com/yugt/sha256-prefix-collision
487- let origin1 = "08RTz8" . to_string ( ) ;
488- let origin2 = "4iRDWF" . to_string ( ) ;
487+ let origin0 = "08RTz8" . to_string ( ) ;
488+ let origin1 = "4iRDWF" . to_string ( ) ;
489489
490490 // Smoke test: these are indeed distinct origins.
491- assert_ne ! ( origin1 , origin2 ) ;
491+ assert_ne ! ( origin0 , origin1 ) ;
492492 // However, the SHA256 prefix is the same.
493493 assert_eq ! (
494- StorableOriginHash :: from_origin( & origin1 ) ,
495- StorableOriginHash :: from_origin( & origin2 )
494+ StorableOriginHash :: from_origin( & origin0 ) ,
495+ StorableOriginHash :: from_origin( & origin1 )
496496 ) ;
497497 // But the entire SHA256 sum is different.
498498 assert_ne ! (
499- StorableOriginSha256 :: from_origin( & origin1 ) ,
500- StorableOriginSha256 :: from_origin( & origin2 )
499+ StorableOriginSha256 :: from_origin( & origin0 ) ,
500+ StorableOriginSha256 :: from_origin( & origin1 )
501501 ) ;
502502
503+ assert_application_lookup ( & storage, & origin1, None , None ) ;
504+ assert_application_lookup ( & storage, & origin0, None , None ) ;
505+
503506 // Test what happens if we insert both origins
504- let app_num1 = storage. lookup_or_insert_application_number_with_origin ( & origin1) ;
505- let app_num2 = storage. lookup_or_insert_application_number_with_origin ( & origin2) ;
507+ let app_num0 = storage. lookup_or_insert_application_number_with_origin ( & origin0) ;
506508
507- // Should get the same application number, as we do not yet detect collisions (since the
508- // source of truth is still the old lookup map).
509- // TODO[ID-352]: This assertion should be changed to `assert_ne`.
510- assert_eq ! ( app_num1, app_num2) ;
511- assert_eq ! ( app_num1, 0 ) ;
509+ assert_application_lookup ( & storage, & origin1, None , Some ( 0 ) ) ;
510+ assert_application_lookup ( & storage, & origin0, Some ( 0 ) , Some ( 0 ) ) ;
512511
513- // Both should be stored correctly in new SHA-256 map
512+ let app_num1 = storage . lookup_or_insert_application_number_with_origin ( & origin1 ) ;
514513
515- assert_application_lookup ( & storage, & origin1, Some ( 0 ) , Some ( 0 ) ) ;
516- assert_application_lookup ( & storage, & origin2, None , Some ( 0 ) ) ;
514+ // Should get the different application numbers, as we prevented the collision by using
515+ // the full SHA-256, not just a 8-byte prefix thereof.
516+ assert_eq ! ( app_num0, 0 ) ;
517+ assert_eq ! ( app_num1, 1 ) ;
518+
519+ // Both should be stored correctly in new SHA-256 map, but the collision in the old map
520+ // would cause the application to be overwritten (hence we expect app ID 1 for origin0).
521+ assert_application_lookup ( & storage, & origin1, Some ( 1 ) , Some ( 1 ) ) ;
522+ assert_application_lookup ( & storage, & origin0, Some ( 0 ) , Some ( 1 ) ) ;
517523
518524 // Applications should be stored with correct origins
525+ let stored_app0 = storage. stable_application_memory . get ( & app_num0) . unwrap ( ) ;
519526 let stored_app1 = storage. stable_application_memory . get ( & app_num1) . unwrap ( ) ;
520-
521- // The first origin took place, not the second one
527+ assert_eq ! ( stored_app0. origin, origin0) ;
522528 assert_eq ! ( stored_app1. origin, origin1) ;
523529 }
524530
0 commit comments