From cb4708babe0c36339e747fc7a9c4998317e2d62e Mon Sep 17 00:00:00 2001 From: vimystic <122659254+vimystic@users.noreply.github.com> Date: Thu, 12 Oct 2023 10:56:12 -0600 Subject: [PATCH] edit rpc endpoints using command (#1292) * edit rpc endpoints using command * Update to search for tests recursively --- .github/workflows/interchaintest.yml | 2 +- cmd/appstate.go | 13 +++++++++++++ cmd/chains.go | 29 ++++++++++++++++++++++++++++ cmd/errors.go | 4 ++++ relayer/chains/cosmos/provider.go | 7 +++++++ relayer/chains/penumbra/provider.go | 7 +++++++ relayer/provider/provider.go | 2 ++ 7 files changed, 63 insertions(+), 1 deletion(-) diff --git a/.github/workflows/interchaintest.yml b/.github/workflows/interchaintest.yml index 5a9fd18a3..9d9d1165d 100644 --- a/.github/workflows/interchaintest.yml +++ b/.github/workflows/interchaintest.yml @@ -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 diff --git a/cmd/appstate.go b/cmd/appstate.go index 5017df85e..738e9af40 100644 --- a/cmd/appstate.go +++ b/cmd/appstate.go @@ -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 + }) +} diff --git a/cmd/chains.go b/cmd/chains.go index aa66ed235..d39396412 100644 --- a/cmd/chains.go +++ b/cmd/chains.go @@ -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", @@ -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 != "" +} diff --git a/cmd/errors.go b/cmd/errors.go index d7a94dee8..5d763645d 100644 --- a/cmd/errors.go +++ b/cmd/errors.go @@ -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") diff --git a/relayer/chains/cosmos/provider.go b/relayer/chains/cosmos/provider.go index 3c7ff47fc..a8041466d 100644 --- a/relayer/chains/cosmos/provider.go +++ b/relayer/chains/cosmos/provider.go @@ -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. diff --git a/relayer/chains/penumbra/provider.go b/relayer/chains/penumbra/provider.go index 92918b3d0..fc680a41e 100644 --- a/relayer/chains/penumbra/provider.go +++ b/relayer/chains/penumbra/provider.go @@ -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. diff --git a/relayer/provider/provider.go b/relayer/provider/provider.go index 2bce8c2c4..d5bd7abd7 100644 --- a/relayer/provider/provider.go +++ b/relayer/provider/provider.go @@ -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?