Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cosmos SDK v0.47 #359

Merged
merged 18 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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