Skip to content

Commit

Permalink
fix(api): search types testing
Browse files Browse the repository at this point in the history
  • Loading branch information
remoterami committed Dec 23, 2024
1 parent ddb1da3 commit 8e79801
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions backend/pkg/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package api_test

import (
"crypto/tls"
"encoding/json"
"flag"
"fmt"
"net/http"
Expand Down Expand Up @@ -298,8 +299,11 @@ func TestInternalSearchHandler(t *testing.T) {
}`)).Expect().Status(http.StatusOK).JSON().Decode(&resp)

assert.NotEqual(t, 0, len(resp.Data), "response data should not be empty")
validatorByIndex, ok := resp.Data[0].Value.(api_types.SearchValidator)
assert.True(t, ok, "response data should be of type SearchValidator")
jsonbody, err := json.Marshal(resp.Data[0].Value)
assert.True(t, err == nil, "response data should be convertible to json")
var validatorByIndex api_types.SearchValidator
err = json.Unmarshal(jsonbody, &validatorByIndex)
assert.True(t, err == nil, "response data should be of type SearchValidator")
assert.Equal(t, uint64(5), validatorByIndex.Index, "validator index should be 5")

// search for validator by pubkey
Expand All @@ -325,8 +329,11 @@ func TestInternalSearchHandler(t *testing.T) {
}`)).Expect().Status(http.StatusOK).JSON().Decode(&resp)

assert.NotEqual(t, 0, len(resp.Data), "response data should not be empty")
validatorByPublicKey, ok := resp.Data[0].Value.(api_types.SearchValidator)
assert.True(t, ok, "response data should be of type SearchValidator")
jsonbody, err = json.Marshal(resp.Data[0].Value)
assert.True(t, err == nil, "response data should be convertible to json")
var validatorByPublicKey api_types.SearchValidator
err = json.Unmarshal(jsonbody, &validatorByPublicKey)
assert.True(t, err == nil, "response data should be of type SearchValidator")
assert.Equal(t, uint64(5), validatorByPublicKey.Index, "validator index should be 5")

// search for validator by withdawal address
Expand All @@ -351,8 +358,11 @@ func TestInternalSearchHandler(t *testing.T) {
}`)).Expect().Status(http.StatusOK).JSON().Decode(&resp)

assert.NotEqual(t, 0, len(resp.Data), "response data should not be empty")
validatorsByWithdrawalAddress, ok := resp.Data[0].Value.(api_types.SearchValidatorsByWithdrwalCredential)
assert.True(t, ok, "response data should be of type SearchValidator")
jsonbody, err = json.Marshal(resp.Data[0].Value)
assert.True(t, err == nil, "response data should be convertible to json")
var validatorsByWithdrawalAddress api_types.SearchValidatorsByWithdrwalCredential
err = json.Unmarshal(jsonbody, &validatorsByWithdrawalAddress)
assert.True(t, err == nil, "response data should be of type SearchValidatorsByWithdrwalCredential")
assert.Greater(t, validatorsByWithdrawalAddress.Count, uint64(0), "returned number of validators should be greater than 0")
}

Expand Down

0 comments on commit 8e79801

Please sign in to comment.