@@ -964,6 +964,87 @@ impl ApiTester {
964964 self
965965 }
966966
967+ pub async fn test_beacon_states_validator_identities ( self ) -> Self {
968+ for state_id in self . interesting_state_ids ( ) {
969+ for validator_indices in self . interesting_validator_indices ( ) {
970+ let state_opt = state_id. state ( & self . chain ) . ok ( ) ;
971+ let validators: Vec < Validator > = match state_opt. as_ref ( ) {
972+ Some ( ( state, _execution_optimistic, _finalized) ) => {
973+ state. validators ( ) . clone ( ) . to_vec ( )
974+ }
975+ None => vec ! [ ] ,
976+ } ;
977+
978+ let validator_index_ids = validator_indices
979+ . iter ( )
980+ . cloned ( )
981+ . map ( ValidatorId :: Index )
982+ . collect :: < Vec < ValidatorId > > ( ) ;
983+
984+ let validator_pubkey_ids = validator_indices
985+ . iter ( )
986+ . cloned ( )
987+ . map ( |i| {
988+ ValidatorId :: PublicKey (
989+ validators
990+ . get ( i as usize )
991+ . map_or ( PublicKeyBytes :: empty ( ) , |val| val. pubkey ) ,
992+ )
993+ } )
994+ . collect :: < Vec < ValidatorId > > ( ) ;
995+
996+ let result_index_ids = self
997+ . client
998+ . post_beacon_states_validator_identities ( state_id. 0 , validator_index_ids)
999+ . await
1000+ . unwrap ( )
1001+ . map ( |res| res. data ) ;
1002+ let result_pubkey_ids = self
1003+ . client
1004+ . post_beacon_states_validator_identities ( state_id. 0 , validator_pubkey_ids)
1005+ . await
1006+ . unwrap ( )
1007+ . map ( |res| res. data ) ;
1008+
1009+ let expected = state_opt. map ( |( state, _execution_optimistic, _finalized) | {
1010+ // If validator_indices is empty, return identities for all validators
1011+ if validator_indices. is_empty ( ) {
1012+ state
1013+ . validators ( )
1014+ . iter ( )
1015+ . enumerate ( )
1016+ . map ( |( index, validator) | ValidatorIdentityData {
1017+ index : index as u64 ,
1018+ pubkey : validator. pubkey ,
1019+ activation_epoch : validator. activation_epoch ,
1020+ } )
1021+ . collect ( )
1022+ } else {
1023+ let mut validators = Vec :: with_capacity ( validator_indices. len ( ) ) ;
1024+
1025+ for i in validator_indices {
1026+ if i < state. validators ( ) . len ( ) as u64 {
1027+ // access each validator, and then transform the data into ValidatorIdentityData
1028+ let validator = state. validators ( ) . get ( i as usize ) . unwrap ( ) ;
1029+ validators. push ( ValidatorIdentityData {
1030+ index : i,
1031+ pubkey : validator. pubkey ,
1032+ activation_epoch : validator. activation_epoch ,
1033+ } ) ;
1034+ }
1035+ }
1036+
1037+ validators
1038+ }
1039+ } ) ;
1040+
1041+ assert_eq ! ( result_index_ids, expected, "{:?}" , state_id) ;
1042+ assert_eq ! ( result_pubkey_ids, expected, "{:?}" , state_id) ;
1043+ }
1044+ }
1045+ self
1046+ }
1047+
9671048 pub async fn test_beacon_states_validators ( self ) -> Self {
9681049 for state_id in self . interesting_state_ids ( ) {
9691050 for statuses in self . interesting_validator_statuses ( ) {
@@ -6685,6 +6766,8 @@ async fn beacon_get_state_info() {
66856766 . await
66866767 . test_beacon_states_validator_balances ( )
66876768 . await
6769+ . test_beacon_states_validator_identities ( )
6770+ . await
66886771 . test_beacon_states_committees ( )
66896772 . await
66906773 . test_beacon_states_validator_id ( )
0 commit comments