Skip to content

Commit

Permalink
Cosmos SDK v0.47 (#359)
Browse files Browse the repository at this point in the history
* chore: update to 0.47

* bump go

* updates

* updates

* feedback

* Fix BroadcastSync for cosmos broadcaster (#360)

* Fix BroadcastSync for cosmos broadcaster

* Fixing docstring

* public grpc, register tmlightclient codecs as no longer by default, attempt base64 decode on key if string value doesn't match for backwards compatibility

Add test for IBC with chains pre/post SDK 47 upgrade

* Bump ibc-go to latest commit

* deps: upgrade to ibc-go/v7 and bump ibctest go mod (#372)

* bumping ibc-go to v7 branch

* bumping ibctest go mod to v7

* chore: align User interface with CosmosWallet and fix issue with broadcast mode sync (#388)

* chore: v0.47 branch merge and bumps (#406)

* Param proposals, balance inquiries, and IBC transfer error handling (#393)

* Extract file writing/copying logic to helpers

* Add ParamChangeProposal

* Update file naming for param change proposal

* Use Code to detect errors in IBC transfers

* Add AllBalances and ParamChangeProposal

* Add support for the Hermes relayer (#396)

* adding some scaffolding for hermes relayer

* chore: updating interface to accept create connection options type

* chore: wip

* wip: adding path map to hermes relayer type

* writing mnemonic file

* correctly reading toml config

* ibc test passing with hermes relayer

* learn ibc test passing with hermes relayer

* adding parse client and connection output

* adding hermes test cases

* remove unused types

* undid import change

* reverted import change

* reverted some unintentional changes

* fix linting error

* adding hermes to conformance matrix

* adding default value for matrix file for CI

* pass absolute value for matrix file

* removed extra part of path

* adding hermes to Labels function

* add capabilities for hermes

* temporarily strip down number of tests to verify hermes relayer

* fixing conformance tests

* fixing channel tests in TestRelayerSetup

* revert to go rly to test

* bump hermes version

* extract json response correctly

* extract json result from stdout

* correct channel parsing json stdout

* set field ClearOnStart to true

* switch back to go relayer as default

* add hermes to the default relayers list

* Update version of ibc-go from v6 to v7 from merge

* Bump sdk and ibc-go

---------

Co-authored-by: bigs <bigswim@gmail.com>
Co-authored-by: Cian Hatton <cianhatton@gmail.com>

* deps: bump SDK to v0.47-rc3 (#414)

Co-authored-by: Carlos Rodriguez <crodveg@gmail.com>

* Consolidate flush command into single command (#417)

* Consolidate flush command into single command

* Updates for hermes

* Bump to rly default with consolidated flush

* Flush with channelID since hermes requires it

* feat: add ReadFile method for reading files from docker fs (#423)

Expose a ReadFile method on ChainNode so that you can read files from the docker filesystem within test cases that exist in downstream repos.

---------

Co-authored-by: Justin Tieri <37750742+jtieri@users.noreply.github.com>

* Add support for genesis sub commands (#384)

* Add support for genesis sub commands

* Remove logging and add some basic documentation for UsingNewGenesisCommand

* Remove UsingNewGenesisCommand from chainspec + add test

---------

Co-authored-by: Julien Robert <julien@rbrt.fr>
Co-authored-by: Cian Hatton <cianhatton@gmail.com>
Co-authored-by: Damian Nolan <damiannolan@gmail.com>
Co-authored-by: Gjermund Garaba <gjermund@garaba.net>
Co-authored-by: bigs <bigswim@gmail.com>
Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
Co-authored-by: Carlos Rodriguez <crodveg@gmail.com>
Co-authored-by: Justin Tieri <37750742+jtieri@users.noreply.github.com>
  • Loading branch information
9 people committed Mar 16, 2023
1 parent 9fc26b8 commit cc5bb34
Show file tree
Hide file tree
Showing 96 changed files with 1,512 additions and 706 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ on:
branches:
- main
paths:
- '**.go'
- '**.mod'
- '**.sum'
- "**.go"
- "**.mod"
- "**.sum"

jobs:
test-unit:
name: unit-tests
runs-on: [self-hosted, linux]
steps:
# Install and setup go
- name: Set up Go 1.18
- name: Set up Go 1.19
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19

- name: checkout interchaintest
uses: actions/checkout@v3
Expand All @@ -38,10 +38,10 @@ jobs:
runs-on: [self-hosted, linux]
steps:
# Install and setup go
- name: Set up Go 1.18
- name: Set up Go 1.19
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19

- name: checkout interchaintest
uses: actions/checkout@v3
Expand All @@ -59,10 +59,10 @@ jobs:
runs-on: [self-hosted, linux]
steps:
# Install and setup go
- name: Set up Go 1.18
- name: Set up Go 1.19
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19

- name: checkout interchaintest
uses: actions/checkout@v3
Expand All @@ -80,10 +80,10 @@ jobs:
runs-on: [self-hosted, linux]
steps:
# Install and setup go
- name: Set up Go 1.18
- name: Set up Go 1.19
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19

- name: checkout interchaintest
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ help: ## Print this help message

.PHONY: interchaintest
interchaintest: gen ## Build interchaintest binary into ./bin
go test -ldflags "-X github.com/strangelove-ventures/interchaintest/v6/internal/version.GitSha=$(shell git describe --always --dirty)" -c -o ./bin/interchaintest ./cmd/interchaintest
go test -ldflags "-X github.com/strangelove-ventures/interchaintest/v7/internal/version.GitSha=$(shell git describe --always --dirty)" -c -o ./bin/interchaintest ./cmd/interchaintest

.PHONY: test
test: ## Run unit tests
Expand Down
46 changes: 39 additions & 7 deletions chain/cosmos/broadcaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ import (
"fmt"
"path"
"testing"
"time"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authTx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/strangelove-ventures/interchaintest/v6/internal/dockerutil"
"github.com/strangelove-ventures/interchaintest/v7/internal/dockerutil"
"github.com/strangelove-ventures/interchaintest/v7/testutil"
)

type ClientContextOpt func(clientContext client.Context) client.Context
Expand All @@ -24,7 +27,6 @@ type FactoryOpt func(factory tx.Factory) tx.Factory
type User interface {
KeyName() string
FormattedAddress() string
FormattedAddressWithPrefix(prefix string) string
}

type Broadcaster struct {
Expand Down Expand Up @@ -77,7 +79,7 @@ func (b *Broadcaster) GetFactory(ctx context.Context, user User) (tx.Factory, er
return tx.Factory{}, err
}

sdkAdd, err := sdk.AccAddressFromBech32(user.FormattedAddressWithPrefix(b.chain.Config().Bech32Prefix))
sdkAdd, err := sdk.AccAddressFromBech32(user.FormattedAddress())
if err != nil {
return tx.Factory{}, err
}
Expand Down Expand Up @@ -112,7 +114,7 @@ func (b *Broadcaster) GetClientContext(ctx context.Context, user User) (client.C
b.keyrings[user] = kr
}

sdkAdd, err := sdk.AccAddressFromBech32(user.FormattedAddressWithPrefix(chain.Config().Bech32Prefix))
sdkAdd, err := sdk.AccAddressFromBech32(user.FormattedAddress())
if err != nil {
return client.Context{}, err
}
Expand Down Expand Up @@ -150,13 +152,13 @@ func (b *Broadcaster) defaultClientContext(fromUser User, sdkAdd sdk.AccAddress)
cn := b.chain.getFullNode()
return cn.CliContext().
WithOutput(b.buf).
WithFrom(fromUser.FormattedAddressWithPrefix(b.chain.Config().Bech32Prefix)).
WithFrom(fromUser.FormattedAddress()).
WithFromAddress(sdkAdd).
WithFromName(fromUser.KeyName()).
WithSkipConfirmation(true).
WithAccountRetriever(authtypes.AccountRetriever{}).
WithKeyring(kr).
WithBroadcastMode(flags.BroadcastBlock).
WithBroadcastMode(flags.BroadcastSync).
WithCodec(b.chain.cfg.EncodingConfig.Codec)

// NOTE: the returned context used to have .WithHomeDir(cn.Home),
Expand Down Expand Up @@ -202,5 +204,35 @@ func BroadcastTx(ctx context.Context, broadcaster *Broadcaster, broadcastingUser
return sdk.TxResponse{}, err
}

return broadcaster.UnmarshalTxResponseBytes(ctx, txBytes)
err = testutil.WaitForCondition(time.Second*30, time.Second*5, func() (bool, error) {
var err error
txBytes, err = broadcaster.GetTxResponseBytes(ctx, broadcastingUser)

if err != nil {
return false, nil
}
return true, nil
})

if err != nil {
return sdk.TxResponse{}, err
}

respWithTxHash, err := broadcaster.UnmarshalTxResponseBytes(ctx, txBytes)
if err != nil {
return sdk.TxResponse{}, err
}

resp, err := authTx.QueryTx(cc, respWithTxHash.TxHash)
if err != nil {
// if we fail to query the tx, it means an error occurred with the original message broadcast.
// we should return this instead.
originalResp, err := broadcaster.UnmarshalTxResponseBytes(ctx, txBytes)
if err != nil {
return sdk.TxResponse{}, err
}
return originalResp, nil
}

return *resp, nil
}
78 changes: 54 additions & 24 deletions chain/cosmos/chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ import (
"time"

"github.com/avast/retry-go/v4"
tmjson "github.com/cometbft/cometbft/libs/json"
"github.com/cometbft/cometbft/p2p"
rpcclient "github.com/cometbft/cometbft/rpc/client"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
coretypes "github.com/cometbft/cometbft/rpc/core/types"
libclient "github.com/cometbft/cometbft/rpc/jsonrpc/client"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/types"
Expand All @@ -28,16 +34,10 @@ import (
dockerclient "github.com/docker/docker/client"
"github.com/docker/docker/errdefs"
"github.com/docker/go-connections/nat"
"github.com/strangelove-ventures/interchaintest/v6/ibc"
"github.com/strangelove-ventures/interchaintest/v6/internal/blockdb"
"github.com/strangelove-ventures/interchaintest/v6/internal/dockerutil"
"github.com/strangelove-ventures/interchaintest/v6/testutil"
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/tendermint/tendermint/p2p"
rpcclient "github.com/tendermint/tendermint/rpc/client"
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
coretypes "github.com/tendermint/tendermint/rpc/core/types"
libclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
"github.com/strangelove-ventures/interchaintest/v7/ibc"
"github.com/strangelove-ventures/interchaintest/v7/internal/blockdb"
"github.com/strangelove-ventures/interchaintest/v7/internal/dockerutil"
"github.com/strangelove-ventures/interchaintest/v7/testutil"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
)
Expand Down Expand Up @@ -136,8 +136,7 @@ func (tn *ChainNode) HostName() string {
}

func (tn *ChainNode) genesisFileContent(ctx context.Context) ([]byte, error) {
fr := dockerutil.NewFileRetriever(tn.logger(), tn.DockerClient, tn.TestName)
gen, err := fr.SingleFileContent(ctx, tn.VolumeName, "config/genesis.json")
gen, err := tn.ReadFile(ctx, "config/genesis.json")
if err != nil {
return nil, fmt.Errorf("getting genesis.json content: %w", err)
}
Expand All @@ -162,8 +161,7 @@ func (tn *ChainNode) copyGentx(ctx context.Context, destVal *ChainNode) error {

relPath := fmt.Sprintf("config/gentx/gentx-%s.json", nid)

fr := dockerutil.NewFileRetriever(tn.logger(), tn.DockerClient, tn.TestName)
gentx, err := fr.SingleFileContent(ctx, tn.VolumeName, relPath)
gentx, err := tn.ReadFile(ctx, relPath)
if err != nil {
return fmt.Errorf("getting gentx content: %w", err)
}
Expand Down Expand Up @@ -240,6 +238,14 @@ func (tn *ChainNode) SetTestConfig(ctx context.Context) error {

a := make(testutil.Toml)
a["minimum-gas-prices"] = tn.Chain.Config().GasPrices

grpc := make(testutil.Toml)

// Enable public GRPC
grpc["address"] = "0.0.0.0:9090"

a["grpc"] = grpc

return testutil.ModifyTomlConfigFile(
ctx,
tn.logger(),
Expand Down Expand Up @@ -522,6 +528,17 @@ func (tn *ChainNode) CopyFile(ctx context.Context, srcPath, dstPath string) erro
return tn.WriteFile(ctx, content, dstPath)
}

// ReadFile reads the contents of a single file at the specified path in the docker filesystem.
// relPath describes the location of the file in the docker volume relative to the home directory.
func (tn *ChainNode) ReadFile(ctx context.Context, relPath string) ([]byte, error) {
fr := dockerutil.NewFileRetriever(tn.logger(), tn.DockerClient, tn.TestName)
gen, err := fr.SingleFileContent(ctx, tn.VolumeName, relPath)
if err != nil {
return nil, fmt.Errorf("failed to read file at %s: %w", relPath, err)
}
return gen, nil
}

// CreateKey creates a key in the keyring backend test for the given node
func (tn *ChainNode) CreateKey(ctx context.Context, name string) error {
tn.lock.Lock()
Expand Down Expand Up @@ -568,7 +585,14 @@ func (tn *ChainNode) AddGenesisAccount(ctx context.Context, address string, gene
ctx, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel()

_, _, err := tn.ExecBin(ctx, "add-genesis-account", address, amount)
var command []string
if tn.Chain.Config().UsingNewGenesisCommand {
command = append(command, "genesis")
}

command = append(command, "add-genesis-account", address, amount)
_, _, err := tn.ExecBin(ctx, command...)

return err
}

Expand All @@ -577,20 +601,28 @@ func (tn *ChainNode) Gentx(ctx context.Context, name string, genesisSelfDelegati
tn.lock.Lock()
defer tn.lock.Unlock()

_, _, err := tn.ExecBin(ctx,
"gentx", valKey, fmt.Sprintf("%d%s", genesisSelfDelegation.Amount.Int64(), genesisSelfDelegation.Denom),
var command []string
if tn.Chain.Config().UsingNewGenesisCommand {
command = append(command, "genesis")
}

command = append(command, "gentx", valKey, fmt.Sprintf("%d%s", genesisSelfDelegation.Amount.Int64(), genesisSelfDelegation.Denom),
"--keyring-backend", keyring.BackendTest,
"--chain-id", tn.Chain.Config().ChainID,
)
"--chain-id", tn.Chain.Config().ChainID)

_, _, err := tn.ExecBin(ctx, command...)
return err
}

// CollectGentxs runs collect gentxs on the node's home folders
func (tn *ChainNode) CollectGentxs(ctx context.Context) error {
command := []string{tn.Chain.Config().Bin, "collect-gentxs",
"--home", tn.HomeDir(),
command := []string{tn.Chain.Config().Bin}
if tn.Chain.Config().UsingNewGenesisCommand {
command = append(command, "genesis")
}

command = append(command, "collect-gentxs", "--home", tn.HomeDir())

tn.lock.Lock()
defer tn.lock.Unlock()

Expand Down Expand Up @@ -1023,9 +1055,7 @@ func (tn *ChainNode) NodeID(ctx context.Context) (string, error) {
// This used to call p2p.LoadNodeKey against the file on the host,
// but because we are transitioning to operating on Docker volumes,
// we only have to tmjson.Unmarshal the raw content.

fr := dockerutil.NewFileRetriever(tn.logger(), tn.DockerClient, tn.TestName)
j, err := fr.SingleFileContent(ctx, tn.VolumeName, "config/node_key.json")
j, err := tn.ReadFile(ctx, "config/node_key.json")
if err != nil {
return "", fmt.Errorf("getting node_key.json content: %w", err)
}
Expand Down
65 changes: 45 additions & 20 deletions chain/cosmos/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,55 @@ package cosmos
import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/simapp"
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
"github.com/cosmos/cosmos-sdk/std"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/cosmos/cosmos-sdk/x/auth"
authTx "github.com/cosmos/cosmos-sdk/x/auth/tx"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
transfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types"
ibctypes "github.com/cosmos/ibc-go/v6/modules/core/types"
)

func DefaultEncoding() simappparams.EncodingConfig {
// core modules
cfg := simappparams.MakeTestEncodingConfig()
std.RegisterLegacyAminoCodec(cfg.Amino)
std.RegisterInterfaces(cfg.InterfaceRegistry)
simapp.ModuleBasics.RegisterLegacyAminoCodec(cfg.Amino)
simapp.ModuleBasics.RegisterInterfaces(cfg.InterfaceRegistry)
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/capability"
"github.com/cosmos/cosmos-sdk/x/consensus"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/cosmos/cosmos-sdk/x/gov"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
"github.com/cosmos/cosmos-sdk/x/mint"
"github.com/cosmos/cosmos-sdk/x/params"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/upgrade"
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"

// external modules
banktypes.RegisterInterfaces(cfg.InterfaceRegistry)
ibctypes.RegisterInterfaces(cfg.InterfaceRegistry)
transfertypes.RegisterInterfaces(cfg.InterfaceRegistry)
transfer "github.com/cosmos/ibc-go/v7/modules/apps/transfer"
ibccore "github.com/cosmos/ibc-go/v7/modules/core"
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
)

return cfg
func DefaultEncoding() testutil.TestEncodingConfig {
return testutil.MakeTestEncodingConfig(
auth.AppModuleBasic{},
genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
bank.AppModuleBasic{},
capability.AppModuleBasic{},
staking.AppModuleBasic{},
mint.AppModuleBasic{},
distr.AppModuleBasic{},
gov.NewAppModuleBasic(
[]govclient.ProposalHandler{
paramsclient.ProposalHandler,
upgradeclient.LegacyProposalHandler,
upgradeclient.LegacyCancelProposalHandler,
},
),
params.AppModuleBasic{},
slashing.AppModuleBasic{},
upgrade.AppModuleBasic{},
consensus.AppModuleBasic{},
transfer.AppModuleBasic{},
ibccore.AppModuleBasic{},
ibctm.AppModuleBasic{},
)
}

func decodeTX(interfaceRegistry codectypes.InterfaceRegistry, txbz []byte) (sdk.Tx, error) {
Expand Down
Loading

0 comments on commit cc5bb34

Please sign in to comment.