Skip to content

Commit

Permalink
Merge PR cosmos#630: bump lens dep & wire up --coin-type flag
Browse files Browse the repository at this point in the history
* update lens to most recent main branch

* update function parameters on interfaces in `provider.go`

* use `--coin-type` flag in keys cmds

* use default cosmos coin type 118 in `CreateTestKey()`

* add missing parameters and arguments

* fix integration tests to pass appropriate contexts into various function calls

* remove dead code

* fix typo reported in issue cosmos#596
  • Loading branch information
jtieri authored Mar 26, 2022
1 parent 178bb18 commit 83ad18f
Show file tree
Hide file tree
Showing 20 changed files with 309 additions and 261 deletions.
203 changes: 99 additions & 104 deletions _test/relayer_chain_test.go

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions _test/test_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ import (
)

// testClientPair tests that the client for src on dst and dst on src are the only clients on those chains
func testClientPair(t *testing.T, src, dst *relayer.Chain) {
func testClientPair(ctx context.Context, t *testing.T, src, dst *relayer.Chain) {
t.Helper()
testClient(t, src)
testClient(t, dst)
testClient(ctx, t, src)
testClient(ctx, t, dst)
}

// testClient queries client for existence of dst on src
func testClient(t *testing.T, src *relayer.Chain) {
func testClient(ctx context.Context, t *testing.T, src *relayer.Chain) {
t.Helper()

srch, err := src.ChainProvider.QueryLatestHeight(context.Background())
srch, err := src.ChainProvider.QueryLatestHeight(ctx)
require.NoError(t, err)
var (
client *clientypes.QueryClientStateResponse
)
if err = retry.Do(func() error {
client, err = src.ChainProvider.QueryClientStateResponse(srch, src.ClientID())
client, err = src.ChainProvider.QueryClientStateResponse(ctx, srch, src.ClientID())
if err != nil {
srch, _ = src.ChainProvider.QueryLatestHeight(context.Background())
srch, _ = src.ChainProvider.QueryLatestHeight(ctx)
}
return err
}); err != nil {
Expand All @@ -44,29 +44,29 @@ func testClient(t *testing.T, src *relayer.Chain) {
}

// testConnectionPair tests that the only connection on src and dst is between the two chains
func testConnectionPair(t *testing.T, src, dst *relayer.Chain) {
func testConnectionPair(ctx context.Context, t *testing.T, src, dst *relayer.Chain) {
t.Helper()
testConnection(t, src, dst)
testConnection(t, dst, src)
testConnection(ctx, t, src, dst)
testConnection(ctx, t, dst, src)
}

// testConnection tests that the only connection on src has a counterparty that is the connection on dst
func testConnection(t *testing.T, src, dst *relayer.Chain) {
func testConnection(ctx context.Context, t *testing.T, src, dst *relayer.Chain) {
t.Helper()

conns, err := src.ChainProvider.QueryConnections(context.Background())
conns, err := src.ChainProvider.QueryConnections(ctx)
require.NoError(t, err)
require.Equal(t, len(conns), 1)
require.Equal(t, conns[0].ClientId, src.PathEnd.ClientID)
require.Equal(t, conns[0].Counterparty.GetClientID(), dst.PathEnd.ClientID)
require.Equal(t, conns[0].Counterparty.GetConnectionID(), dst.PathEnd.ConnectionID)
require.Equal(t, conns[0].State.String(), "STATE_OPEN")

h, err := src.ChainProvider.QueryLatestHeight(context.Background())
h, err := src.ChainProvider.QueryLatestHeight(ctx)
require.NoError(t, err)

time.Sleep(time.Second * 5)
conn, err := src.ChainProvider.QueryConnection(h, src.ConnectionID())
conn, err := src.ChainProvider.QueryConnection(ctx, h, src.ConnectionID())
require.NoError(t, err)
require.Equal(t, conn.Connection.ClientId, src.PathEnd.ClientID)
require.Equal(t, conn.Connection.GetCounterparty().GetClientID(), dst.PathEnd.ClientID)
Expand All @@ -75,29 +75,29 @@ func testConnection(t *testing.T, src, dst *relayer.Chain) {
}

// testChannelPair tests that the only channel on src and dst is between the two chains
func testChannelPair(t *testing.T, src, dst *relayer.Chain, channelID, portID string) {
func testChannelPair(ctx context.Context, t *testing.T, src, dst *relayer.Chain, channelID, portID string) {
t.Helper()
testChannel(t, src, dst, channelID, portID)
testChannel(t, dst, src, channelID, portID)
testChannel(ctx, t, src, dst, channelID, portID)
testChannel(ctx, t, dst, src, channelID, portID)
}

// testChannel tests that the only channel on src is a counterparty of dst
func testChannel(t *testing.T, src, dst *relayer.Chain, channelID, portID string) {
func testChannel(ctx context.Context, t *testing.T, src, dst *relayer.Chain, channelID, portID string) {
t.Helper()

chans, err := src.ChainProvider.QueryChannels(context.Background())
chans, err := src.ChainProvider.QueryChannels(ctx)
require.NoError(t, err)
require.Equal(t, 1, len(chans))
require.Equal(t, chans[0].Ordering.String(), "ORDER_UNORDERED")
require.Equal(t, chans[0].State.String(), "STATE_OPEN")
require.Equal(t, chans[0].Counterparty.ChannelId, channelID)
require.Equal(t, chans[0].Counterparty.GetPortID(), portID)

h, err := src.ChainProvider.QueryLatestHeight(context.Background())
h, err := src.ChainProvider.QueryLatestHeight(ctx)
require.NoError(t, err)

time.Sleep(time.Second * 5)
ch, err := src.ChainProvider.QueryChannel(h, channelID, portID)
ch, err := src.ChainProvider.QueryChannel(ctx, h, channelID, portID)
require.NoError(t, err)
require.Equal(t, ch.Channel.Ordering.String(), "ORDER_UNORDERED")
require.Equal(t, ch.Channel.State.String(), "STATE_OPEN")
Expand Down
15 changes: 8 additions & 7 deletions cmd/chains.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"context"
"encoding/json"
"fmt"
"net/http"
Expand Down Expand Up @@ -151,7 +152,7 @@ func chainsRegistryList(a *appState) *cobra.Command {
return err
}

chains, err := registry.DefaultChainRegistry().ListChains()
chains, err := registry.DefaultChainRegistry(a.Log).ListChains(cmd.Context())
if err != nil {
return err
}
Expand Down Expand Up @@ -285,7 +286,7 @@ func chainsAddCmd(a *appState) *cobra.Command {
return err
}
default:
if err := addChainsFromRegistry(a, args); err != nil {
if err := addChainsFromRegistry(cmd.Context(), a, args); err != nil {
return err
}
}
Expand Down Expand Up @@ -395,9 +396,9 @@ func addChainFromURL(a *appState, rawurl string) error {
return nil
}

func addChainsFromRegistry(a *appState, chains []string) error {
chainRegistry := registry.DefaultChainRegistry()
allChains, err := chainRegistry.ListChains()
func addChainsFromRegistry(ctx context.Context, a *appState, chains []string) error {
chainRegistry := registry.DefaultChainRegistry(a.Log)
allChains, err := chainRegistry.ListChains(ctx)
if err != nil {
return err
}
Expand All @@ -418,7 +419,7 @@ func addChainsFromRegistry(a *appState, chains []string) error {
continue
}

chainInfo, err := chainRegistry.GetChain(chain)
chainInfo, err := chainRegistry.GetChain(ctx, chain)
if err != nil {
a.Log.Warn(
"Error retrieving chain",
Expand All @@ -428,7 +429,7 @@ func addChainsFromRegistry(a *appState, chains []string) error {
continue
}

chainConfig, err := chainInfo.GetChainConfig()
chainConfig, err := chainInfo.GetChainConfig(ctx)
if err != nil {
a.Log.Warn(
"Error generating chain config",
Expand Down
12 changes: 6 additions & 6 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,12 +656,12 @@ func (c *Config) ValidatePathEnd(ctx context.Context, stderr io.Writer, pe *rela
}

if pe.ClientID != "" {
if err := c.ValidateClient(chain, height, pe); err != nil {
if err := c.ValidateClient(ctx, chain, height, pe); err != nil {
return err
}

if pe.ConnectionID != "" {
if err := c.ValidateConnection(chain, height, pe); err != nil {
if err := c.ValidateConnection(ctx, chain, height, pe); err != nil {
return err
}
}
Expand All @@ -675,12 +675,12 @@ func (c *Config) ValidatePathEnd(ctx context.Context, stderr io.Writer, pe *rela
}

// ValidateClient validates client id in provided pathend
func (c *Config) ValidateClient(chain *relayer.Chain, height int64, pe *relayer.PathEnd) error {
func (c *Config) ValidateClient(ctx context.Context, chain *relayer.Chain, height int64, pe *relayer.PathEnd) error {
if err := pe.Vclient(); err != nil {
return err
}

_, err := chain.ChainProvider.QueryClientStateResponse(height, pe.ClientID)
_, err := chain.ChainProvider.QueryClientStateResponse(ctx, height, pe.ClientID)
if err != nil {
return err
}
Expand All @@ -689,12 +689,12 @@ func (c *Config) ValidateClient(chain *relayer.Chain, height int64, pe *relayer.
}

// ValidateConnection validates connection id in provided pathend
func (c *Config) ValidateConnection(chain *relayer.Chain, height int64, pe *relayer.PathEnd) error {
func (c *Config) ValidateConnection(ctx context.Context, chain *relayer.Chain, height int64, pe *relayer.PathEnd) error {
if err := pe.Vconn(); err != nil {
return err
}

connection, err := chain.ChainProvider.QueryConnection(height, pe.ConnectionID)
connection, err := chain.ChainProvider.QueryConnection(ctx, height, pe.ConnectionID)
if err != nil {
return err
}
Expand Down
14 changes: 12 additions & 2 deletions cmd/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ $ %s k a ibc-2 testkey`, appName, appName, appName)),
return errKeyExists(keyName)
}

ko, err := chain.ChainProvider.AddKey(keyName)
coinType, err := cmd.Flags().GetUint32(flagCoinType)
if err != nil {
return err
}

ko, err := chain.ChainProvider.AddKey(keyName, coinType)
if err != nil {
return fmt.Errorf("failed to add key: %w", err)
}
Expand Down Expand Up @@ -114,7 +119,12 @@ $ %s k r ibc-1 faucet-key "[mnemonic-words]"`, appName, appName)),
return errKeyExists(keyName)
}

address, err := chain.ChainProvider.RestoreKey(keyName, args[2])
coinType, err := cmd.Flags().GetUint32(flagCoinType)
if err != nil {
return err
}

address, err := chain.ChainProvider.RestoreKey(keyName, args[2], coinType)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ $ %s query client ibc-0 ibczeroclient --height 1205`,
return err
}

res, err := chain.ChainProvider.QueryClientStateResponse(height, chain.ClientID())
res, err := chain.ChainProvider.QueryClientStateResponse(cmd.Context(), height, chain.ClientID())
if err != nil {
return err
}
Expand Down Expand Up @@ -640,7 +640,7 @@ $ %s q conn ibc-1 ibconeconn`,
return err
}

res, err := chain.ChainProvider.QueryConnection(height, chain.ConnectionID())
res, err := chain.ChainProvider.QueryConnection(cmd.Context(), height, chain.ConnectionID())
if err != nil {
return err
}
Expand Down Expand Up @@ -742,7 +742,7 @@ $ %s query channel ibc-2 ibctwochannel transfer --height 1205`,
}
}

res, err := chain.ChainProvider.QueryChannel(height, channelID, portID)
res, err := chain.ChainProvider.QueryChannel(cmd.Context(), height, channelID, portID)
if err != nil {
return err
}
Expand Down Expand Up @@ -830,7 +830,7 @@ $ %s q packet-commit ibc-1 ibconechannel transfer 31`,
return err
}

res, err := chain.ChainProvider.QueryPacketCommitment(0, channelID, portID, seq)
res, err := chain.ChainProvider.QueryPacketCommitment(cmd.Context(), 0, channelID, portID, seq)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ $ %s tx channel-close demo-path channel-0 transfer -o 3s`,
return err
}

channel, err := c[src].ChainProvider.QueryChannel(srch, channelID, portID)
channel, err := c[src].ChainProvider.QueryChannel(cmd.Context(), srch, channelID, portID)
if err != nil {
return err
}
Expand Down Expand Up @@ -836,7 +836,7 @@ $ %s tx relay-acks demo-path channel-0 -l 3 -s 6`,
// Use: "upgrade-chain [path-name] [chain-id] [new-unbonding-period] [deposit] [path/to/upgradePlan.json]",
// Short: "upgrade an IBC-enabled network with a given upgrade plan",
// Long: strings.TrimSpace(`Upgrade an IBC-enabled network by providing the chain-id of the
//network being upgraded, the new unbonding period, the proposal deposit and the JSN file of the
//network being upgraded, the new unbonding period, the proposal deposit and the JSON file of the
//upgrade plan without the upgrade client state.`,
// ),
// Args: cobra.ExactArgs(5),
Expand Down
1 change: 1 addition & 0 deletions docs/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ foo := NewFoo(log.With(zap.String("path", path)), path)

Log messages should begin with an uppercase letter and should not end with any punctuation.
Log messages should be constant string literals; dynamic content is to be set as log fields.
Names of log fields should be all lowercase `snake_case` format.

```go
// Do this:
Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ require (
github.com/go-git/go-git/v5 v5.4.2
github.com/gogo/protobuf v1.3.3
github.com/gorilla/mux v1.8.0 // indirect
github.com/spf13/cobra v1.3.0
github.com/spf13/cobra v1.4.0
github.com/spf13/viper v1.10.1
github.com/stretchr/testify v1.7.0
github.com/stretchr/testify v1.7.1
github.com/tendermint/tendermint v0.34.14
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
)

require (
github.com/avast/retry-go/v4 v4.0.3
github.com/cosmos/ibc-go/v3 v3.0.0-rc0
github.com/cosmos/ibc-go/v3 v3.0.0
github.com/jsternberg/zap-logfmt v1.2.0
github.com/ory/dockertest/v3 v3.8.1
github.com/pkg/errors v0.9.1
github.com/strangelove-ventures/lens v0.3.1-0.20220222182620-10a90e9eca45
github.com/strangelove-ventures/lens v0.3.1-0.20220326181038-f6d1dde7392d
go.uber.org/zap v1.21.0
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
)
Expand All @@ -47,7 +47,7 @@ require (
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/coinbase/rosetta-sdk-go v0.7.0 // indirect
github.com/confio/ics23/go v0.6.6 // indirect
github.com/confio/ics23/go v0.7.0 // indirect
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6 // indirect
github.com/cosmos/btcutil v1.0.4 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
Expand Down Expand Up @@ -147,8 +147,8 @@ require (
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/zondax/hid v0.9.0 // indirect
go.etcd.io/bbolt v1.3.5 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect
golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect
golang.org/x/sys v0.0.0-20211210111614-af8b64212486 // indirect
Expand Down
Loading

0 comments on commit 83ad18f

Please sign in to comment.