Skip to content

Commit

Permalink
Fix registry service /keys endpoint (#81)
Browse files Browse the repository at this point in the history
* Fix registry service /keys endpoint, unmarshal with jsonpb instead of json

* Add comments for run-local command

* Upgrade helm chart version
  • Loading branch information
Anmol1696 authored Apr 22, 2023
1 parent 8f64825 commit b3707f5
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion charts/devnet/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.22
version: 0.1.23

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
2 changes: 1 addition & 1 deletion charts/devnet/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Returns a comma seperated list of urls for the RPC address
Returns a comma seperated list of urls for the Exposer address
*/}}
{{- define "devnet.chains.exposer.addrs" -}}
{{- $port := ($.Values.exposer.ports.rest | default "8081") }}
{{- $port := ($.Values.exposer.ports.rest | toString | default "8081") }}
{{- $values := list -}}
{{- range $chain := .Values.chains -}}
{{- $values = printf "http://%s-genesis.$(NAMESPACE).svc.cluster.local:%s" $chain.name $port | append $values -}}
Expand Down
11 changes: 11 additions & 0 deletions registry/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,21 @@ build:

run:
bazel run //$(BINARY_NAME):$(BINARY_NAME) -- \
--http-port "8001" --grpc-port "9001" \
--chain-registry $(CURDIR)/testdata/ \
--chain-client-ids "osmosis-1,juno-0" \
--chain-client-rpcs "https://rpc.osmosis.zone:443,https://rpc.juno.strange.love:443"

# Assumes a local starship cluster is running
# Uses tests/config.yaml as the base config
run-local:
bazel run //$(BINARY_NAME):$(BINARY_NAME) -- \
--http-port "8001" --grpc-port "9001" \
--chain-registry $(CURDIR)/testdata/ \
--chain-client-ids "osmosis-1,cosmoshub-4" \
--chain-client-rpcs "http://localhost:26653,http://localhost:26657" \
--chain-client-exposer "http://localhost:38083,http://localhost:38087"

## Docker commands
docker-build:
bazel build //$(BINARY_NAME):image
Expand Down
12 changes: 3 additions & 9 deletions registry/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package main

import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"strings"
Expand All @@ -14,6 +12,7 @@ import (
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
"github.com/golang/protobuf/jsonpb"
lens "github.com/strangelove-ventures/lens/client"
"github.com/strangelove-ventures/lens/client/query"
"go.uber.org/zap"
Expand Down Expand Up @@ -152,13 +151,8 @@ func (c *ChainClient) GetChainKeys(ctx context.Context) (*pb.Keys, error) {
return nil, err
}

respData, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}

var keys *pb.Keys
err = json.Unmarshal(respData, keys)
keys := &pb.Keys{}
err = jsonpb.Unmarshal(resp.Body, keys)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions tests/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ chains:
rest: 1313
rpc: 26653
exposer: 38083
- name: cosmoshub-1
- name: cosmoshub-4
type: cosmos
numValidators: 2
ports:
Expand All @@ -20,7 +20,7 @@ relayers:
replicas: 1
chains:
- osmosis-1
- cosmoshub-1
- cosmoshub-4

explorer:
enabled: true
Expand Down
18 changes: 18 additions & 0 deletions tests/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,21 @@ func (s *TestSuite) TestRegistry_ListIBC() {
// assert results to expected values
s.Assert().Len(respIBC.Data, len(s.config.Relayers)*2, "number of ibc information should be double the number of relayers")
}

func (s *TestSuite) TestRegistry_GetChainKeys() {
s.T().Log("runing test for /chains/{chain}/keys endpoint for registry")

for _, chain := range s.config.Chains {
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("/chains/%s/keys", chain.Name), nil)
s.Require().NoError(err)

respKeys := &pb.Keys{}
s.MakeRegistryRequest(req, respKeys)

// assert results to expected values
s.Assert().Len(respKeys.Genesis, 1)
s.Assert().Len(respKeys.Validators, 4)
s.Assert().Len(respKeys.Keys, 3)
s.Assert().Len(respKeys.Relayers, 2)
}
}

0 comments on commit b3707f5

Please sign in to comment.