@@ -2,6 +2,7 @@ package api_test
22
33import (
44 "crypto/tls"
5+ "encoding/json"
56 "flag"
67 "fmt"
78 "net/http"
@@ -298,8 +299,11 @@ func TestInternalSearchHandler(t *testing.T) {
298299 }` )).Expect ().Status (http .StatusOK ).JSON ().Decode (& resp )
299300
300301 assert .NotEqual (t , 0 , len (resp .Data ), "response data should not be empty" )
301- validatorByIndex , ok := resp .Data [0 ].Value .(api_types.SearchValidator )
302- assert .True (t , ok , "response data should be of type SearchValidator" )
302+ jsonbody , err := json .Marshal (resp .Data [0 ].Value )
303+ assert .Nil (t , err , "response data should be convertible to json" )
304+ var validatorByIndex api_types.SearchValidator
305+ err = json .Unmarshal (jsonbody , & validatorByIndex )
306+ assert .Nil (t , err , "response data should be of type SearchValidator" )
303307 assert .Equal (t , uint64 (5 ), validatorByIndex .Index , "validator index should be 5" )
304308
305309 // search for validator by pubkey
@@ -325,8 +329,11 @@ func TestInternalSearchHandler(t *testing.T) {
325329 }` )).Expect ().Status (http .StatusOK ).JSON ().Decode (& resp )
326330
327331 assert .NotEqual (t , 0 , len (resp .Data ), "response data should not be empty" )
328- validatorByPublicKey , ok := resp .Data [0 ].Value .(api_types.SearchValidator )
329- assert .True (t , ok , "response data should be of type SearchValidator" )
332+ jsonbody , err = json .Marshal (resp .Data [0 ].Value )
333+ assert .Nil (t , err , "response data should be convertible to json" )
334+ var validatorByPublicKey api_types.SearchValidator
335+ err = json .Unmarshal (jsonbody , & validatorByPublicKey )
336+ assert .Nil (t , err , "response data should be of type SearchValidator" )
330337 assert .Equal (t , uint64 (5 ), validatorByPublicKey .Index , "validator index should be 5" )
331338
332339 // search for validator by withdawal address
@@ -351,8 +358,11 @@ func TestInternalSearchHandler(t *testing.T) {
351358 }` )).Expect ().Status (http .StatusOK ).JSON ().Decode (& resp )
352359
353360 assert .NotEqual (t , 0 , len (resp .Data ), "response data should not be empty" )
354- validatorsByWithdrawalAddress , ok := resp .Data [0 ].Value .(api_types.SearchValidatorsByWithdrwalCredential )
355- assert .True (t , ok , "response data should be of type SearchValidator" )
361+ jsonbody , err = json .Marshal (resp .Data [0 ].Value )
362+ assert .Nil (t , err , "response data should be convertible to json" )
363+ var validatorsByWithdrawalAddress api_types.SearchValidatorsByWithdrwalCredential
364+ err = json .Unmarshal (jsonbody , & validatorsByWithdrawalAddress )
365+ assert .Nil (t , err , "response data should be of type SearchValidatorsByWithdrwalCredential" )
356366 assert .Greater (t , validatorsByWithdrawalAddress .Count , uint64 (0 ), "returned number of validators should be greater than 0" )
357367}
358368
0 commit comments