Skip to content

Commit

Permalink
edit rpc endpoints using command (#1292)
Browse files Browse the repository at this point in the history
* edit rpc endpoints using command

* Update to search for tests recursively
  • Loading branch information
vimystic committed Oct 12, 2023
1 parent 200d0fb commit cb4708b
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/interchaintest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ jobs:
id: set-matrix
run: |
# Run the command and convert its output to a JSON array
TESTS=$(cd interchaintest && go test -list ^TestScenario | grep -v "^ok " | jq -R -s -c 'split("\n")[:-1]')
TESTS=$(cd interchaintest && go test -list ^TestScenario ./... | grep -v "^ok " | jq -R -s -c 'split("\n")[:-1]')
echo "matrix=${TESTS}" >> $GITHUB_OUTPUT
# Note : This job will not start until prepare-scenario-matrix completes sucessfully
Expand Down
13 changes: 13 additions & 0 deletions cmd/appstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,16 @@ func (a *appState) useKey(chainName, key string) error {
return nil
})
}

func (a *appState) useRpcAddr(chainName string, rpcAddr string) error {

_, exists := a.config.Chains[chainName]
if !exists {
return fmt.Errorf("chain %s not found in config", chainName)
}

return a.performConfigLockingOperation(context.Background(), func() error {
a.config.Chains[chainName].ChainProvider.SetRpcAddr(rpcAddr)
return nil
})
}
29 changes: 29 additions & 0 deletions cmd/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,35 @@ func chainsCmd(a *appState) *cobra.Command {
chainsAddrCmd(a),
chainsAddDirCmd(a),
cmdChainsConfigure(a),
cmdChainsUseRpcAddr(a),
)

return cmd
}

func cmdChainsUseRpcAddr(a *appState) *cobra.Command {
cmd := &cobra.Command{
Use: "set-rpc-addr chain_name valid_rpc_url",
Aliases: []string{"rpc"},
Short: "Sets chain's rpc address",
Args: withUsage(cobra.ExactArgs(2)),
Example: strings.TrimSpace(fmt.Sprintf(`
$ %s chains set-rpc-addr ibc-0 https://abc.xyz.com:443
$ %s ch set-rpc-addr ibc-0 https://abc.xyz.com:443`, appName, appName)),
RunE: func(cmd *cobra.Command, args []string) error {
chainName := args[0]
rpc_address := args[1]
if !isValidURL(rpc_address) {
return invalidRpcAddr(rpc_address)
}

return a.useRpcAddr(chainName, rpc_address)
},
}

return cmd
}

func chainsAddrCmd(a *appState) *cobra.Command {
cmd := &cobra.Command{
Use: "address chain_name",
Expand Down Expand Up @@ -513,3 +537,8 @@ func addChainsFromRegistry(ctx context.Context, a *appState, forceAdd, testnet b
)
return nil
}

func isValidURL(str string) bool {
u, err := url.Parse(str)
return err == nil && u.Scheme != "" && u.Host != ""
}
4 changes: 4 additions & 0 deletions cmd/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ func errChainNotFound(chainName string) error {
return fmt.Errorf("chain with name \"%s\" not found in config. consider running `rly chains add %s`", chainName, chainName)
}

func invalidRpcAddr(rpcAddr string) error {
return fmt.Errorf("rpc-addr %s is not valid", rpcAddr)
}

var (
errMultipleAddFlags = errors.New("expected either --file/-f OR --url/u, found multiple")
errInvalidTestnetFlag = errors.New("cannot use --testnet with --file/-f OR --url/u, must be used alone")
Expand Down
7 changes: 7 additions & 0 deletions relayer/chains/cosmos/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@ func (cc *CosmosProvider) Sprint(toPrint proto.Message) (string, error) {
return string(out), nil
}

// SetPCAddr sets the rpc-addr for the chain.
// It will fail if the rpcAddr is invalid(not a url).
func (cc *CosmosProvider) SetRpcAddr(rpcAddr string) error {
cc.PCfg.RPCAddr = rpcAddr
return nil
}

// Init initializes the keystore, RPC client, amd light client provider.
// Once initialization is complete an attempt to query the underlying node's tendermint version is performed.
// NOTE: Init must be called after creating a new instance of CosmosProvider.
Expand Down
7 changes: 7 additions & 0 deletions relayer/chains/penumbra/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ func (cc *PenumbraProvider) Sprint(toPrint proto.Message) (string, error) {
return string(out), nil
}

// SetPCAddr sets the rpc-addr for the chain.
// It will fail if the rpcAddr is invalid(not a url).
func (cc *PenumbraProvider) SetRpcAddr(rpcAddr string) error {
cc.PCfg.RPCAddr = rpcAddr
return nil
}

// Init initializes the keystore, RPC client, amd light client provider.
// Once initialization is complete an attempt to query the underlying node's tendermint version is performed.
// NOTE: Init must be called after creating a new instance of CosmosProvider.
Expand Down
2 changes: 2 additions & 0 deletions relayer/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ type ChainProvider interface {
TrustingPeriod(ctx context.Context) (time.Duration, error)
WaitForNBlocks(ctx context.Context, n int64) error
Sprint(toPrint proto.Message) (string, error)

SetRpcAddr(rpcAddr string) error
}

// Do we need intermediate types? i.e. can we use the SDK types for both substrate and cosmos?
Expand Down

0 comments on commit cb4708b

Please sign in to comment.