@@ -585,27 +585,29 @@ mod tests {
585585
586586 assert_eq ! ( contenders. len( ) , 2 ) ;
587587
588- let first_contender = contenders. first ( ) . unwrap ( ) ;
589-
590- let second_contender = contenders. last ( ) . unwrap ( ) ;
588+ // Look up by identity id rather than vec position — see explanatory
589+ // comment in the abstain-only test below.
590+ let identity1_contender = contenders
591+ . iter ( )
592+ . find ( |c| c. identifier == identity1_id. to_vec ( ) )
593+ . expect ( "identity1 in contenders" ) ;
594+ let identity2_contender = contenders
595+ . iter ( )
596+ . find ( |c| c. identifier == identity2_id. to_vec ( ) )
597+ . expect ( "identity2 in contenders" ) ;
591598
592599 assert_eq ! (
593- first_contender . document. as_ref( ) . map( hex:: encode) ,
594- Some ( "00177f2479090a0286a67d6a1f67b563b51518edd6eea0461829f7d630fd65708d29124be7e86f97e959894a67a9cc078c3e0106d4bfcfbf34bc403a4f099925b401000700000187690895980000018769089598000001876908959800077175616e74756d077175616e74756d00046461736800210129124be7e86f97e959894a67a9cc078c3e0106d4bfcfbf34bc403a4f099925b40101 " . to_string( ) )
600+ identity1_contender . document. as_ref( ) . map( hex:: encode) ,
601+ Some ( "0021278016512ff707d45a0aa8893a4b1ba67b08158b31bc2bda11a0addb8ab1f4341e6a8e6c01488a75104a8dbc73501ded5cd23abaf688349a8ab34b1157513201000700000187690895980000018769089598000001876908959800077175616e74756d077175616e74756d000464617368002101341e6a8e6c01488a75104a8dbc73501ded5cd23abaf688349a8ab34b115751320100 " . to_string( ) )
595602 ) ;
596603
597604 assert_eq ! (
598- second_contender . document. as_ref( ) . map( hex:: encode) ,
599- Some ( "00490e212593a1d3cc6ae17bf107ab9cb465175e7877fcf7d085ed2fce27be11d68b8948a6801501bbe0431e3d994dcf71cf5a2a0939fe51b0e600076199aba4fb01000700000187690895980000018769089598000001876908959800077175616e74756d077175616e74756d0004646173680021018b8948a6801501bbe0431e3d994dcf71cf5a2a0939fe51b0e600076199aba4fb0100 " . to_string( ) )
605+ identity2_contender . document. as_ref( ) . map( hex:: encode) ,
606+ Some ( "0010b1d465b94520e76daf018ee6b2740c871d51b7ce9690f60fc7a4a70f1bfd6f3a3c745d6c4d3b88ea52976eaab80dbaa77258885b7b6d8e1edfd00fed72414a01000700000187690895980000018769089598000001876908959800077175616e74756d077175616e74756d0004646173680021013a3c745d6c4d3b88ea52976eaab80dbaa77258885b7b6d8e1edfd00fed72414a0101 " . to_string( ) )
600607 ) ;
601608
602- assert_eq ! ( first_contender. identifier, identity2_id. to_vec( ) ) ;
603-
604- assert_eq ! ( second_contender. identifier, identity1_id. to_vec( ) ) ;
605-
606- assert_eq ! ( first_contender. vote_count, Some ( 0 ) ) ;
607-
608- assert_eq ! ( second_contender. vote_count, Some ( 0 ) ) ;
609+ assert_eq ! ( identity1_contender. vote_count, Some ( 0 ) ) ;
610+ assert_eq ! ( identity2_contender. vote_count, Some ( 0 ) ) ;
609611 }
610612
611613 #[ stack_size( STACK_SIZE ) ]
@@ -945,21 +947,23 @@ mod tests {
945947
946948 assert_eq ! ( contenders. len( ) , 2 ) ;
947949
948- let first_contender = contenders. first ( ) . unwrap ( ) ;
949-
950- let second_contender = contenders. last ( ) . unwrap ( ) ;
951-
952- assert ! ( first_contender. document. is_some( ) ) ;
953-
954- assert ! ( second_contender. document. is_some( ) ) ;
950+ // Look up by identity id rather than vec position — contender ordering
951+ // follows identifier sort, which derives from the asset-lock txid and
952+ // shifts whenever the asset-lock fixture's wire format changes.
953+ let identity1_contender = contenders
954+ . iter ( )
955+ . find ( |c| c. identifier == identity1_id. to_vec ( ) )
956+ . expect ( "identity1 in contenders" ) ;
957+ let identity2_contender = contenders
958+ . iter ( )
959+ . find ( |c| c. identifier == identity2_id. to_vec ( ) )
960+ . expect ( "identity2 in contenders" ) ;
955961
956- assert_eq ! ( first_contender. identifier, identity2_id. to_vec( ) ) ;
962+ assert ! ( identity1_contender. document. is_some( ) ) ;
963+ assert ! ( identity2_contender. document. is_some( ) ) ;
957964
958- assert_eq ! ( second_contender. identifier, identity1_id. to_vec( ) ) ;
959-
960- assert_eq ! ( first_contender. vote_count, Some ( 0 ) ) ;
961-
962- assert_eq ! ( second_contender. vote_count, Some ( 0 ) ) ;
965+ assert_eq ! ( identity1_contender. vote_count, Some ( 0 ) ) ;
966+ assert_eq ! ( identity2_contender. vote_count, Some ( 0 ) ) ;
963967
964968 assert_eq ! ( abstain_vote_tally, Some ( 124 ) ) ;
965969 }
@@ -1306,23 +1310,24 @@ mod tests {
13061310
13071311 assert_eq ! ( contenders. len( ) , 2 ) ;
13081312
1309- let first_contender = contenders. first ( ) . unwrap ( ) ;
1310-
1311- let second_contender = contenders. last ( ) . unwrap ( ) ;
1312-
1313- assert ! ( first_contender. document. is_some( ) ) ;
1314-
1315- assert ! ( second_contender. document. is_some( ) ) ;
1316-
1317- assert_eq ! ( first_contender. identifier, identity2_id. to_vec( ) ) ;
1313+ // Look up by identity id rather than vec position — see explanatory
1314+ // comment in the abstain-only test above.
1315+ let identity1_contender = contenders
1316+ . iter ( )
1317+ . find ( |c| c. identifier == identity1_id. to_vec ( ) )
1318+ . expect ( "identity1 in contenders" ) ;
1319+ let identity2_contender = contenders
1320+ . iter ( )
1321+ . find ( |c| c. identifier == identity2_id. to_vec ( ) )
1322+ . expect ( "identity2 in contenders" ) ;
13181323
1319- assert_eq ! ( second_contender. identifier, identity1_id. to_vec( ) ) ;
1324+ assert ! ( identity1_contender. document. is_some( ) ) ;
1325+ assert ! ( identity2_contender. document. is_some( ) ) ;
13201326
13211327 // All vote counts are weighted, so for evonodes, these are in multiples of 4
13221328
1323- assert_eq ! ( first_contender. vote_count, Some ( 52 ) ) ;
1324-
1325- assert_eq ! ( second_contender. vote_count, Some ( 56 ) ) ;
1329+ assert_eq ! ( identity1_contender. vote_count, Some ( 56 ) ) ;
1330+ assert_eq ! ( identity2_contender. vote_count, Some ( 52 ) ) ;
13261331
13271332 assert_eq ! ( lock_vote_tally, Some ( 16 ) ) ;
13281333
@@ -1686,19 +1691,21 @@ mod tests {
16861691
16871692 assert_eq ! ( contenders. len( ) , 2 ) ;
16881693
1689- let first_contender = contenders. first ( ) . unwrap ( ) ;
1690-
1691- let second_contender = contenders. last ( ) . unwrap ( ) ;
1692-
1693- assert_eq ! ( first_contender. identifier, identity2_id. to_vec( ) ) ;
1694-
1695- assert_eq ! ( second_contender. identifier, identity1_id. to_vec( ) ) ;
1694+ // Look up by identity id rather than vec position — see explanatory
1695+ // comment in the abstain-only test above.
1696+ let identity1_contender = contenders
1697+ . iter ( )
1698+ . find ( |c| c. identifier == identity1_id. to_vec ( ) )
1699+ . expect ( "identity1 in contenders" ) ;
1700+ let identity2_contender = contenders
1701+ . iter ( )
1702+ . find ( |c| c. identifier == identity2_id. to_vec ( ) )
1703+ . expect ( "identity2 in contenders" ) ;
16961704
16971705 // All vote counts are weighted, so for evonodes, these are in multiples of 4
16981706
1699- assert_eq ! ( first_contender. vote_count, Some ( 60 ) ) ;
1700-
1701- assert_eq ! ( second_contender. vote_count, Some ( 4 ) ) ;
1707+ assert_eq ! ( identity1_contender. vote_count, Some ( 4 ) ) ;
1708+ assert_eq ! ( identity2_contender. vote_count, Some ( 60 ) ) ;
17021709
17031710 assert_eq ! ( lock_vote_tally, Some ( 4 ) ) ;
17041711
@@ -2086,21 +2093,23 @@ mod tests {
20862093
20872094 assert_eq ! ( contenders. len( ) , 2 ) ;
20882095
2089- let first_contender = contenders. first ( ) . unwrap ( ) ;
2090-
2091- let second_contender = contenders. last ( ) . unwrap ( ) ;
2092-
2093- assert_eq ! ( first_contender. identifier, identity2_id. to_vec( ) ) ;
2094-
2095- assert_eq ! ( second_contender. identifier, identity1_id. to_vec( ) ) ;
2096+ // Look up by identity id rather than vec position — see explanatory
2097+ // comment in the abstain-only test above.
2098+ let identity1_contender = contenders
2099+ . iter ( )
2100+ . find ( |c| c. identifier == identity1_id. to_vec ( ) )
2101+ . expect ( "identity1 in contenders" ) ;
2102+ let identity2_contender = contenders
2103+ . iter ( )
2104+ . find ( |c| c. identifier == identity2_id. to_vec ( ) )
2105+ . expect ( "identity2 in contenders" ) ;
20962106
20972107 // All vote counts are weighted, so for evonodes, these are in multiples of 4
20982108
20992109 // 19 votes were cast
21002110
2101- assert_eq ! ( first_contender. vote_count, Some ( 60 ) ) ;
2102-
2103- assert_eq ! ( second_contender. vote_count, Some ( 4 ) ) ;
2111+ assert_eq ! ( identity1_contender. vote_count, Some ( 4 ) ) ;
2112+ assert_eq ! ( identity2_contender. vote_count, Some ( 60 ) ) ;
21042113
21052114 assert_eq ! ( lock_vote_tally, Some ( 4 ) ) ;
21062115
@@ -2517,24 +2526,27 @@ mod tests {
25172526
25182527 assert_eq ! ( contenders. len( ) , 2 ) ;
25192528
2520- let first_contender = contenders. first ( ) . unwrap ( ) ;
2521-
2522- let second_contender = contenders. last ( ) . unwrap ( ) ;
2523-
2524- assert_eq ! ( first_contender. identifier, identity2_id. to_vec( ) ) ;
2525-
2526- assert_eq ! ( second_contender. identifier, identity1_id. to_vec( ) ) ;
2529+ // Look up by identity id rather than vec position — see explanatory
2530+ // comment in the abstain-only test above.
2531+ let identity1_contender = contenders
2532+ . iter ( )
2533+ . find ( |c| c. identifier == identity1_id. to_vec ( ) )
2534+ . expect ( "identity1 in contenders" ) ;
2535+ let identity2_contender = contenders
2536+ . iter ( )
2537+ . find ( |c| c. identifier == identity2_id. to_vec ( ) )
2538+ . expect ( "identity2 in contenders" ) ;
25272539
25282540 // All vote counts are weighted, so for evonodes, these are in multiples of 4
25292541
25302542 assert_eq ! (
25312543 (
2532- first_contender . vote_count,
2533- second_contender . vote_count,
2544+ identity1_contender . vote_count,
2545+ identity2_contender . vote_count,
25342546 lock_vote_tally,
25352547 abstain_vote_tally
25362548 ) ,
2537- ( Some ( 64 ) , Some ( 8 ) , Some ( 0 ) , Some ( 0 ) )
2549+ ( Some ( 8 ) , Some ( 64 ) , Some ( 0 ) , Some ( 0 ) )
25382550 ) ;
25392551
25402552 assert_eq ! (
0 commit comments