diff --git a/.gitignore b/.gitignore index 2bf18165980a..83d56ddf8e75 100644 --- a/.gitignore +++ b/.gitignore @@ -26,7 +26,7 @@ artifacts # Data - ideally these don't exist baseapp/data/* client/lcd/keys/* -mytestnet +.testnets # Testing coverage.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 72a86acc4183..5c13f59bec64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,11 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [\#9427](https://github.com/cosmos/cosmos-sdk/pull/9427) Move simapp `FundAccount` and `FundModuleAccount` to `x/bank/testutil` * (client/tx) [\#9421](https://github.com/cosmos/cosmos-sdk/pull/9421/) `BuildUnsignedTx`, `BuildSimTx`, `PrintUnsignedStdTx` functions are moved to the Tx Factory as methods. +* [\#9246](https://github.com/cosmos/cosmos-sdk/pull/9246) The `New` method for the network package now returns an error. + +### CLI Breaking Changes + +* [\#9246](https://github.com/cosmos/cosmos-sdk/pull/9246) Removed the CLI flag `--setup-config-only` from the `testnet` command and added the subcommand `init-files`. ### Improvements * (cli) [\#9593](https://github.com/cosmos/cosmos-sdk/pull/9593) Check if chain-id is blank before verifying signatures in multisign and error. diff --git a/Makefile b/Makefile index 12fbae141aee..9d4d589becc1 100644 --- a/Makefile +++ b/Makefile @@ -475,16 +475,16 @@ proto-update-deps: ### Localnet ### ############################################################################### -# Run a 4-node testnet locally +# Run a 4-node testnet locally via docker compose localnet-start: build-linux localnet-stop $(if $(shell $(DOCKER) inspect -f '{{ .Id }}' cosmossdk/simd-env 2>/dev/null),$(info found image cosmossdk/simd-env),$(MAKE) -C contrib/images simd-env) - if ! [ -f build/node0/simd/config/genesis.json ]; then $(DOCKER) run --rm \ + if ! test -f build/node0/simd/config/genesis.json; then $(DOCKER) run --rm \ --user $(shell id -u):$(shell id -g) \ -v $(BUILDDIR):/simd:Z \ -v /etc/group:/etc/group:ro \ -v /etc/passwd:/etc/passwd:ro \ -v /etc/shadow:/etc/shadow:ro \ - cosmossdk/simd-env testnet --v 4 -o . --starting-ip-address 192.168.10.2 --keyring-backend=test ; fi + cosmossdk/simd-env testnet init-files --v 4 -o . --starting-ip-address 192.168.10.2 --keyring-backend=test ; fi docker-compose up -d localnet-stop: diff --git a/client/context_test.go b/client/context_test.go index 9c2e8d4ab19e..d500bc97783b 100644 --- a/client/context_test.go +++ b/client/context_test.go @@ -105,7 +105,8 @@ func TestCLIQueryConn(t *testing.T) { cfg := network.DefaultConfig() cfg.NumValidators = 1 - n := network.New(t, cfg) + n, err := network.New(t, t.TempDir(), cfg) + require.NoError(t, err) defer n.Cleanup() testClient := testdata.NewQueryClient(n.Validators[0].ClientCtx) diff --git a/client/grpc/tmservice/service_test.go b/client/grpc/tmservice/service_test.go index 3de92411c9f7..abdc6145ad6f 100644 --- a/client/grpc/tmservice/service_test.go +++ b/client/grpc/tmservice/service_test.go @@ -32,11 +32,12 @@ func (s *IntegrationTestSuite) SetupSuite() { cfg.NumValidators = 1 s.cfg = cfg - s.network = network.New(s.T(), cfg) - s.Require().NotNil(s.network) + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) + s.Require().NoError(err) - _, err := s.network.WaitForHeight(1) + _, err = s.network.WaitForHeight(1) s.Require().NoError(err) s.queryClient = tmservice.NewServiceClient(s.network.Validators[0].ClientCtx) diff --git a/client/grpc_query_test.go b/client/grpc_query_test.go index c4d2f024a07b..b63937ac2337 100644 --- a/client/grpc_query_test.go +++ b/client/grpc_query_test.go @@ -27,10 +27,11 @@ type IntegrationTestSuite struct { func (s *IntegrationTestSuite) SetupSuite() { s.T().Log("setting up integration test suite") - s.network = network.New(s.T(), network.DefaultConfig()) - s.Require().NotNil(s.network) + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), network.DefaultConfig()) + s.Require().NoError(err) - _, err := s.network.WaitForHeight(2) + _, err = s.network.WaitForHeight(2) s.Require().NoError(err) } diff --git a/client/rpc/rpc_test.go b/client/rpc/rpc_test.go index adb7dac82d21..c2c18a0d1c6a 100644 --- a/client/rpc/rpc_test.go +++ b/client/rpc/rpc_test.go @@ -23,8 +23,9 @@ type IntegrationTestSuite struct { func (s *IntegrationTestSuite) SetupSuite() { s.T().Log("setting up integration test suite") - s.network = network.New(s.T(), network.DefaultConfig()) - s.Require().NotNil(s.network) + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), network.DefaultConfig()) + s.Require().NoError(err) s.Require().NoError(s.network.WaitForNextBlock()) } diff --git a/server/grpc/grpc_web_test.go b/server/grpc/grpc_web_test.go index fa657ae941ad..8fcdd216be7d 100644 --- a/server/grpc/grpc_web_test.go +++ b/server/grpc/grpc_web_test.go @@ -45,10 +45,12 @@ func (s *GRPCWebTestSuite) SetupSuite() { cfg := network.DefaultConfig() cfg.NumValidators = 1 s.cfg = cfg - s.network = network.New(s.T(), s.cfg) - s.Require().NotNil(s.network) - _, err := s.network.WaitForHeight(2) + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) + s.Require().NoError(err) + + _, err = s.network.WaitForHeight(2) s.Require().NoError(err) s.protoCdc = codec.NewProtoCodec(s.cfg.InterfaceRegistry) diff --git a/server/grpc/server_test.go b/server/grpc/server_test.go index 7f3c7a742cb4..9867f9d08817 100644 --- a/server/grpc/server_test.go +++ b/server/grpc/server_test.go @@ -48,10 +48,12 @@ func (s *IntegrationTestSuite) SetupSuite() { s.app = simapp.Setup(false) s.cfg = network.DefaultConfig() s.cfg.NumValidators = 1 - s.network = network.New(s.T(), s.cfg) - s.Require().NotNil(s.network) - _, err := s.network.WaitForHeight(2) + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) + s.Require().NoError(err) + + _, err = s.network.WaitForHeight(2) s.Require().NoError(err) val0 := s.network.Validators[0] diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index b33a660c87e3..62215c865beb 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -146,7 +146,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { genutilcli.ValidateGenesisCmd(simapp.ModuleBasics), AddGenesisAccountCmd(simapp.DefaultNodeHome), tmcli.NewCompletionCmd(rootCmd, true), - testnetCmd(simapp.ModuleBasics, banktypes.GenesisBalancesIterator{}), + NewTestnetCmd(simapp.ModuleBasics, banktypes.GenesisBalancesIterator{}), debug.Cmd(), config.Cmd(), ) diff --git a/simapp/simd/cmd/testnet.go b/simapp/simd/cmd/testnet.go index 071d9364d0e2..d5c60f0522ea 100644 --- a/simapp/simd/cmd/testnet.go +++ b/simapp/simd/cmd/testnet.go @@ -25,6 +25,7 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/server" srvconfig "github.com/cosmos/cosmos-sdk/server/config" + "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -40,20 +41,78 @@ var ( flagOutputDir = "output-dir" flagNodeDaemonHome = "node-daemon-home" flagStartingIPAddress = "starting-ip-address" + flagEnableLogging = "enable-logging" + flagGRPCAddress = "grpc.address" + flagRPCAddress = "rpc.address" + flagAPIAddress = "api.address" + flagPrintMnemonic = "print-mnemonic" ) +type initArgs struct { + algo string + chainID string + keyringBackend string + minGasPrices string + nodeDaemonHome string + nodeDirPrefix string + numValidators int + outputDir string + startingIPAddress string +} + +type startArgs struct { + algo string + apiAddress string + chainID string + enableLogging bool + grpcAddress string + minGasPrices string + numValidators int + outputDir string + printMnemonic bool + rpcAddress string +} + +func addTestnetFlagsToCmd(cmd *cobra.Command) { + cmd.Flags().Int(flagNumValidators, 4, "Number of validators to initialize the testnet with") + cmd.Flags().StringP(flagOutputDir, "o", "./.testnets", "Directory to store initialization data for the testnet") + cmd.Flags().String(flags.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created") + cmd.Flags().String(server.FlagMinGasPrices, fmt.Sprintf("0.000006%s", sdk.DefaultBondDenom), "Minimum gas prices to accept for transactions; All fees in a tx must meet this minimum (e.g. 0.01photino,0.001stake)") + cmd.Flags().String(flags.FlagKeyAlgorithm, string(hd.Secp256k1Type), "Key signing algorithm to generate keys for") +} + +// NewTestnetCmd creates a root testnet command with subcommands to run an in-process testnet or initialize +// validator configuration files for running a multi-validator testnet in a separate process +func NewTestnetCmd(mbm module.BasicManager, genBalIterator banktypes.GenesisBalancesIterator) *cobra.Command { + testnetCmd := &cobra.Command{ + Use: "testnet", + Short: "subcommands for starting or configuring local testnets", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + testnetCmd.AddCommand(testnetStartCmd()) + testnetCmd.AddCommand(testnetInitFilesCmd(mbm, genBalIterator)) + + return testnetCmd +} + // get cmd to initialize all files for tendermint testnet and application -func testnetCmd(mbm module.BasicManager, genBalIterator banktypes.GenesisBalancesIterator) *cobra.Command { +func testnetInitFilesCmd(mbm module.BasicManager, genBalIterator banktypes.GenesisBalancesIterator) *cobra.Command { cmd := &cobra.Command{ - Use: "testnet", - Short: "Initialize files for a simapp testnet", - Long: `testnet will create "v" number of directories and populate each with -necessary files (private validator, genesis, config, etc.). + Use: "init-files", + Short: "Initialize config directories & files for a multi-validator testnet running locally via separate processes (e.g. Docker Compose or similar)", + Long: `init-files will setup "v" number of directories and populate each with +necessary files (private validator, genesis, config, etc.) for running "v" validator nodes. + +Booting up a network with these validator folders is intended to be used with Docker Compose, +or a similar setup where each node has a manually configurable IP address. Note, strict routability for addresses is turned off in the config file. Example: - simd testnet --v 4 --output-dir ./output --starting-ip-address 192.168.10.2 + simd testnet init-files --v 4 --output-dir ./.testnets --starting-ip-address 192.168.10.2 `, RunE: func(cmd *cobra.Command, _ []string) error { clientCtx, err := client.GetClientQueryContext(cmd) @@ -64,70 +123,97 @@ Example: serverCtx := server.GetServerContextFromCmd(cmd) config := serverCtx.Config - outputDir, _ := cmd.Flags().GetString(flagOutputDir) - keyringBackend, _ := cmd.Flags().GetString(flags.FlagKeyringBackend) - chainID, _ := cmd.Flags().GetString(flags.FlagChainID) - minGasPrices, _ := cmd.Flags().GetString(server.FlagMinGasPrices) - nodeDirPrefix, _ := cmd.Flags().GetString(flagNodeDirPrefix) - nodeDaemonHome, _ := cmd.Flags().GetString(flagNodeDaemonHome) - startingIPAddress, _ := cmd.Flags().GetString(flagStartingIPAddress) - numValidators, _ := cmd.Flags().GetInt(flagNumValidators) - algo, _ := cmd.Flags().GetString(flags.FlagKeyAlgorithm) - - return InitTestnet( - clientCtx, cmd, config, mbm, genBalIterator, outputDir, chainID, minGasPrices, - nodeDirPrefix, nodeDaemonHome, startingIPAddress, keyringBackend, algo, numValidators, - ) + args := initArgs{} + args.outputDir, _ = cmd.Flags().GetString(flagOutputDir) + args.keyringBackend, _ = cmd.Flags().GetString(flags.FlagKeyringBackend) + args.chainID, _ = cmd.Flags().GetString(flags.FlagChainID) + args.minGasPrices, _ = cmd.Flags().GetString(server.FlagMinGasPrices) + args.nodeDirPrefix, _ = cmd.Flags().GetString(flagNodeDirPrefix) + args.nodeDaemonHome, _ = cmd.Flags().GetString(flagNodeDaemonHome) + args.startingIPAddress, _ = cmd.Flags().GetString(flagStartingIPAddress) + args.numValidators, _ = cmd.Flags().GetInt(flagNumValidators) + args.algo, _ = cmd.Flags().GetString(flags.FlagKeyAlgorithm) + + return initTestnetFiles(clientCtx, cmd, config, mbm, genBalIterator, args) + }, } - cmd.Flags().Int(flagNumValidators, 4, "Number of validators to initialize the testnet with") - cmd.Flags().StringP(flagOutputDir, "o", "./mytestnet", "Directory to store initialization data for the testnet") + addTestnetFlagsToCmd(cmd) cmd.Flags().String(flagNodeDirPrefix, "node", "Prefix the directory name for each node with (node results in node0, node1, ...)") cmd.Flags().String(flagNodeDaemonHome, "simd", "Home directory of the node's daemon configuration") cmd.Flags().String(flagStartingIPAddress, "192.168.0.1", "Starting IP address (192.168.0.1 results in persistent peers list ID0@192.168.0.1:46656, ID1@192.168.0.2:46656, ...)") - cmd.Flags().String(flags.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created") - cmd.Flags().String(server.FlagMinGasPrices, fmt.Sprintf("0.000006%s", sdk.DefaultBondDenom), "Minimum gas prices to accept for transactions; All fees in a tx must meet this minimum (e.g. 0.01photino,0.001stake)") cmd.Flags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|test)") - cmd.Flags().String(flags.FlagKeyAlgorithm, string(hd.Secp256k1Type), "Key signing algorithm to generate keys for") return cmd } +// get cmd to start multi validator in-process testnet +func testnetStartCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "start", + Short: "Launch an in-process multi-validator testnet", + Long: `testnet will launch an in-process multi-validator testnet, +and generate "v" directories, populated with necessary validator configuration files +(private validator, genesis, config, etc.). + +Example: + simd testnet --v 4 --output-dir ./.testnets + `, + RunE: func(cmd *cobra.Command, _ []string) error { + + args := startArgs{} + args.outputDir, _ = cmd.Flags().GetString(flagOutputDir) + args.chainID, _ = cmd.Flags().GetString(flags.FlagChainID) + args.minGasPrices, _ = cmd.Flags().GetString(server.FlagMinGasPrices) + args.numValidators, _ = cmd.Flags().GetInt(flagNumValidators) + args.algo, _ = cmd.Flags().GetString(flags.FlagKeyAlgorithm) + args.enableLogging, _ = cmd.Flags().GetBool(flagEnableLogging) + args.rpcAddress, _ = cmd.Flags().GetString(flagRPCAddress) + args.apiAddress, _ = cmd.Flags().GetString(flagAPIAddress) + args.grpcAddress, _ = cmd.Flags().GetString(flagGRPCAddress) + args.printMnemonic, _ = cmd.Flags().GetBool(flagPrintMnemonic) + + return startTestnet(cmd, args) + + }, + } + + addTestnetFlagsToCmd(cmd) + cmd.Flags().Bool(flagEnableLogging, false, "Enable INFO logging of tendermint validator nodes") + cmd.Flags().String(flagRPCAddress, "tcp://0.0.0.0:26657", "the RPC address to listen on") + cmd.Flags().String(flagAPIAddress, "tcp://0.0.0.0:1317", "the address to listen on for REST API") + cmd.Flags().String(flagGRPCAddress, "0.0.0.0:9090", "the gRPC server address to listen on") + cmd.Flags().Bool(flagPrintMnemonic, true, "print mnemonic of first validator to stdout for manual testing") + return cmd +} + const nodeDirPerm = 0755 -// Initialize the testnet -func InitTestnet( +// initTestnetFiles initializes testnet files for a testnet to be run in a separate process +func initTestnetFiles( clientCtx client.Context, cmd *cobra.Command, nodeConfig *tmconfig.Config, mbm module.BasicManager, genBalIterator banktypes.GenesisBalancesIterator, - outputDir, - chainID, - minGasPrices, - nodeDirPrefix, - nodeDaemonHome, - startingIPAddress, - keyringBackend, - algoStr string, - numValidators int, + args initArgs, ) error { - if chainID == "" { - chainID = "chain-" + tmrand.NewRand().Str(6) + if args.chainID == "" { + args.chainID = "chain-" + tmrand.NewRand().Str(6) } - nodeIDs := make([]string, numValidators) - valPubKeys := make([]cryptotypes.PubKey, numValidators) + nodeIDs := make([]string, args.numValidators) + valPubKeys := make([]cryptotypes.PubKey, args.numValidators) simappConfig := srvconfig.DefaultConfig() - simappConfig.MinGasPrices = minGasPrices + simappConfig.MinGasPrices = args.minGasPrices simappConfig.API.Enable = true simappConfig.Telemetry.Enabled = true simappConfig.Telemetry.PrometheusRetentionTime = 60 simappConfig.Telemetry.EnableHostnameLabel = false - simappConfig.Telemetry.GlobalLabels = [][]string{{"chain_id", chainID}} + simappConfig.Telemetry.GlobalLabels = [][]string{{"chain_id", args.chainID}} var ( genAccounts []authtypes.GenesisAccount @@ -137,50 +223,50 @@ func InitTestnet( inBuf := bufio.NewReader(cmd.InOrStdin()) // generate private keys, node IDs, and initial transactions - for i := 0; i < numValidators; i++ { - nodeDirName := fmt.Sprintf("%s%d", nodeDirPrefix, i) - nodeDir := filepath.Join(outputDir, nodeDirName, nodeDaemonHome) - gentxsDir := filepath.Join(outputDir, "gentxs") + for i := 0; i < args.numValidators; i++ { + nodeDirName := fmt.Sprintf("%s%d", args.nodeDirPrefix, i) + nodeDir := filepath.Join(args.outputDir, nodeDirName, args.nodeDaemonHome) + gentxsDir := filepath.Join(args.outputDir, "gentxs") nodeConfig.SetRoot(nodeDir) nodeConfig.RPC.ListenAddress = "tcp://0.0.0.0:26657" if err := os.MkdirAll(filepath.Join(nodeDir, "config"), nodeDirPerm); err != nil { - _ = os.RemoveAll(outputDir) + _ = os.RemoveAll(args.outputDir) return err } nodeConfig.Moniker = nodeDirName - ip, err := getIP(i, startingIPAddress) + ip, err := getIP(i, args.startingIPAddress) if err != nil { - _ = os.RemoveAll(outputDir) + _ = os.RemoveAll(args.outputDir) return err } nodeIDs[i], valPubKeys[i], err = genutil.InitializeNodeValidatorFiles(nodeConfig) if err != nil { - _ = os.RemoveAll(outputDir) + _ = os.RemoveAll(args.outputDir) return err } memo := fmt.Sprintf("%s@%s:26656", nodeIDs[i], ip) genFiles = append(genFiles, nodeConfig.GenesisFile()) - kb, err := keyring.New(sdk.KeyringServiceName(), keyringBackend, nodeDir, inBuf) + kb, err := keyring.New(sdk.KeyringServiceName(), args.keyringBackend, nodeDir, inBuf) if err != nil { return err } keyringAlgos, _ := kb.SupportedAlgorithms() - algo, err := keyring.NewSigningAlgoFromString(algoStr, keyringAlgos) + algo, err := keyring.NewSigningAlgoFromString(args.algo, keyringAlgos) if err != nil { return err } addr, secret, err := server.GenerateSaveCoinKey(kb, nodeDirName, true, algo) if err != nil { - _ = os.RemoveAll(outputDir) + _ = os.RemoveAll(args.outputDir) return err } @@ -228,7 +314,7 @@ func InitTestnet( txFactory := tx.Factory{} txFactory = txFactory. - WithChainID(chainID). + WithChainID(args.chainID). WithMemo(memo). WithKeybase(kb). WithTxConfig(clientCtx.TxConfig) @@ -249,19 +335,19 @@ func InitTestnet( srvconfig.WriteConfigFile(filepath.Join(nodeDir, "config/app.toml"), simappConfig) } - if err := initGenFiles(clientCtx, mbm, chainID, genAccounts, genBalances, genFiles, numValidators); err != nil { + if err := initGenFiles(clientCtx, mbm, args.chainID, genAccounts, genBalances, genFiles, args.numValidators); err != nil { return err } err := collectGenFiles( - clientCtx, nodeConfig, chainID, nodeIDs, valPubKeys, numValidators, - outputDir, nodeDirPrefix, nodeDaemonHome, genBalIterator, + clientCtx, nodeConfig, args.chainID, nodeIDs, valPubKeys, args.numValidators, + args.outputDir, args.nodeDirPrefix, args.nodeDaemonHome, genBalIterator, ) if err != nil { return err } - cmd.PrintErrf("Successfully initialized %d node directories\n", numValidators) + cmd.PrintErrf("Successfully initialized %d node directories\n", args.numValidators) return nil } @@ -401,3 +487,42 @@ func writeFile(name string, dir string, contents []byte) error { return nil } + +// startTestnet starts an in-process testnet +func startTestnet(cmd *cobra.Command, args startArgs) error { + networkConfig := network.DefaultConfig() + + // Default networkConfig.ChainID is random, and we should only override it if chainID provided + // is non-empty + if args.chainID != "" { + networkConfig.ChainID = args.chainID + } + networkConfig.SigningAlgo = args.algo + networkConfig.MinGasPrices = args.minGasPrices + networkConfig.NumValidators = args.numValidators + networkConfig.EnableTMLogging = args.enableLogging + networkConfig.RPCAddress = args.rpcAddress + networkConfig.APIAddress = args.apiAddress + networkConfig.GRPCAddress = args.grpcAddress + networkConfig.PrintMnemonic = args.printMnemonic + networkLogger := network.NewCLILogger(cmd) + + baseDir := fmt.Sprintf("%s/%s", args.outputDir, networkConfig.ChainID) + if _, err := os.Stat(baseDir); !os.IsNotExist(err) { + return fmt.Errorf( + "testnests directory already exists for chain-id '%s': %s, please remove or select a new --chain-id", + networkConfig.ChainID, baseDir) + } + + testnet, err := network.New(networkLogger, baseDir, networkConfig) + if err != nil { + return err + } + + testnet.WaitForHeight(1) + cmd.Println("press the Enter Key to terminate") + fmt.Scanln() // wait for Enter Key + testnet.Cleanup() + + return nil +} diff --git a/simapp/simd/cmd/testnet_test.go b/simapp/simd/cmd/testnet_test.go index da58fd454d82..fae132340745 100644 --- a/simapp/simd/cmd/testnet_test.go +++ b/simapp/simd/cmd/testnet_test.go @@ -36,7 +36,7 @@ func Test_TestnetCmd(t *testing.T) { ctx := context.Background() ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx) ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - cmd := testnetCmd(simapp.ModuleBasics, banktypes.GenesisBalancesIterator{}) + cmd := testnetInitFilesCmd(simapp.ModuleBasics, banktypes.GenesisBalancesIterator{}) cmd.SetArgs([]string{fmt.Sprintf("--%s=test", flags.FlagKeyringBackend), fmt.Sprintf("--output-dir=%s", home)}) err = cmd.ExecuteContext(ctx) require.NoError(t, err) diff --git a/testutil/network/network.go b/testutil/network/network.go index 2f17bca13273..7087e4bd9f46 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -6,16 +6,16 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "net/http" "net/url" "os" "path/filepath" + "strings" "sync" "testing" "time" - "github.com/stretchr/testify/require" + "github.com/spf13/cobra" tmcfg "github.com/tendermint/tendermint/config" tmflags "github.com/tendermint/tendermint/libs/cli/flags" "github.com/tendermint/tendermint/libs/log" @@ -87,10 +87,14 @@ type Config struct { StakingTokens sdk.Int // the amount of tokens each validator has available to stake BondedTokens sdk.Int // the amount of tokens each validator stakes PruningStrategy string // the pruning strategy each validator will have - EnableLogging bool // enable Tendermint logging to STDOUT + EnableTMLogging bool // enable Tendermint logging to STDOUT CleanupDir bool // remove base temporary directory during cleanup SigningAlgo string // signing algorithm for keys - KeyringOptions []keyring.Option + KeyringOptions []keyring.Option // keyring configuration options + RPCAddress string // RPC listen address (including port) + APIAddress string // REST API listen address (including port) + GRPCAddress string // GRPC server listen address (including port) + PrintMnemonic bool // print the mnemonic of first validator as log output for testing } // DefaultConfig returns a sane default configuration suitable for nearly all @@ -118,6 +122,7 @@ func DefaultConfig() Config { CleanupDir: true, SigningAlgo: string(hd.Secp256k1Type), KeyringOptions: []keyring.Option{}, + PrintMnemonic: false, } } @@ -133,7 +138,7 @@ type ( // to create networks. In addition, only the first validator will have a valid // RPC and API server/client. Network struct { - T *testing.T + Logger Logger BaseDir string Validators []*Validator @@ -165,24 +170,46 @@ type ( } ) -// New creates a new Network for integration tests. -func New(t *testing.T, cfg Config) *Network { +// Logger is a network logger interface that exposes testnet-level Log() methods for an in-process testing network +// This is not to be confused with logging that may happen at an individual node or validator level +type Logger interface { + Log(args ...interface{}) + Logf(format string, args ...interface{}) +} + +var _ Logger = (*testing.T)(nil) +var _ Logger = (*CLILogger)(nil) + +type CLILogger struct { + cmd *cobra.Command +} + +func (s CLILogger) Log(args ...interface{}) { + s.cmd.Println(args...) +} + +func (s CLILogger) Logf(format string, args ...interface{}) { + s.cmd.Printf(format, args...) +} + +func NewCLILogger(cmd *cobra.Command) CLILogger { + return CLILogger{cmd} +} + +// New creates a new Network for integration tests or in-process testnets run via the CLI +func New(l Logger, baseDir string, cfg Config) (*Network, error) { // only one caller/test can create and use a network at a time - t.Log("acquiring test network lock") + l.Log("acquiring test network lock") lock.Lock() - baseDir, err := ioutil.TempDir(t.TempDir(), cfg.ChainID) - require.NoError(t, err) - t.Logf("created temporary directory: %s", baseDir) - network := &Network{ - T: t, + Logger: l, BaseDir: baseDir, Validators: make([]*Validator, cfg.NumValidators), Config: cfg, } - t.Log("preparing test network...") + l.Logf("preparing test network with chain-id \"%s\"\n", cfg.ChainID) monikers := make([]string, cfg.NumValidators) nodeIDs := make([]string, cfg.NumValidators) @@ -215,32 +242,56 @@ func New(t *testing.T, cfg Config) *Network { tmCfg.RPC.ListenAddress = "" appCfg.GRPC.Enable = false appCfg.GRPCWeb.Enable = false + apiListenAddr := "" if i == 0 { - apiListenAddr, _, err := server.FreeTCPAddr() - require.NoError(t, err) - appCfg.API.Address = apiListenAddr + if cfg.APIAddress != "" { + apiListenAddr = cfg.APIAddress + } else { + var err error + apiListenAddr, _, err = server.FreeTCPAddr() + if err != nil { + return nil, err + } + } + appCfg.API.Address = apiListenAddr apiURL, err := url.Parse(apiListenAddr) - require.NoError(t, err) + if err != nil { + return nil, err + } apiAddr = fmt.Sprintf("http://%s:%s", apiURL.Hostname(), apiURL.Port()) - rpcAddr, _, err := server.FreeTCPAddr() - require.NoError(t, err) - tmCfg.RPC.ListenAddress = rpcAddr + if cfg.RPCAddress != "" { + tmCfg.RPC.ListenAddress = cfg.RPCAddress + } else { + rpcAddr, _, err := server.FreeTCPAddr() + if err != nil { + return nil, err + } + tmCfg.RPC.ListenAddress = rpcAddr + } - _, grpcPort, err := server.FreeTCPAddr() - require.NoError(t, err) - appCfg.GRPC.Address = fmt.Sprintf("0.0.0.0:%s", grpcPort) + if cfg.GRPCAddress != "" { + appCfg.GRPC.Address = cfg.GRPCAddress + } else { + _, grpcPort, err := server.FreeTCPAddr() + if err != nil { + return nil, err + } + appCfg.GRPC.Address = fmt.Sprintf("0.0.0.0:%s", grpcPort) + } appCfg.GRPC.Enable = true _, grpcWebPort, err := server.FreeTCPAddr() - require.NoError(t, err) + if err != nil { + return nil, err + } appCfg.GRPCWeb.Address = fmt.Sprintf("0.0.0.0:%s", grpcWebPort) appCfg.GRPCWeb.Enable = true } logger := log.NewNopLogger() - if cfg.EnableLogging { + if cfg.EnableTMLogging { logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout)) logger, _ = tmflags.ParseLogLevel("info", logger, tmcfg.DefaultLogLevel) } @@ -252,44 +303,74 @@ func New(t *testing.T, cfg Config) *Network { clientDir := filepath.Join(network.BaseDir, nodeDirName, "simcli") gentxsDir := filepath.Join(network.BaseDir, "gentxs") - require.NoError(t, os.MkdirAll(filepath.Join(nodeDir, "config"), 0755)) - require.NoError(t, os.MkdirAll(clientDir, 0755)) + err := os.MkdirAll(filepath.Join(nodeDir, "config"), 0755) + if err != nil { + return nil, err + } + + err = os.MkdirAll(clientDir, 0755) + if err != nil { + return nil, err + } tmCfg.SetRoot(nodeDir) tmCfg.Moniker = nodeDirName monikers[i] = nodeDirName proxyAddr, _, err := server.FreeTCPAddr() - require.NoError(t, err) + if err != nil { + return nil, err + } tmCfg.ProxyApp = proxyAddr p2pAddr, _, err := server.FreeTCPAddr() - require.NoError(t, err) + if err != nil { + return nil, err + } tmCfg.P2P.ListenAddress = p2pAddr tmCfg.P2P.AddrBookStrict = false tmCfg.P2P.AllowDuplicateIP = true nodeID, pubKey, err := genutil.InitializeNodeValidatorFiles(tmCfg) - require.NoError(t, err) + if err != nil { + return nil, err + } nodeIDs[i] = nodeID valPubKeys[i] = pubKey kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, clientDir, buf, cfg.KeyringOptions...) - require.NoError(t, err) + if err != nil { + return nil, err + } keyringAlgos, _ := kb.SupportedAlgorithms() algo, err := keyring.NewSigningAlgoFromString(cfg.SigningAlgo, keyringAlgos) - require.NoError(t, err) + if err != nil { + return nil, err + } addr, secret, err := server.GenerateSaveCoinKey(kb, nodeDirName, true, algo) - require.NoError(t, err) + if err != nil { + return nil, err + } + + // if PrintMnemonic is set to true, we print the first validator node's secret to the network's logger + // for debugging and manual testing + if cfg.PrintMnemonic && i == 0 { + printMnemonic(l, secret) + } info := map[string]string{"secret": secret} infoBz, err := json.Marshal(info) - require.NoError(t, err) + if err != nil { + return nil, err + } // save private key seed words - require.NoError(t, writeFile(fmt.Sprintf("%v.json", "key_seed"), clientDir, infoBz)) + err = writeFile(fmt.Sprintf("%v.json", "key_seed"), clientDir, infoBz) + if err != nil { + return nil, err + } balances := sdk.NewCoins( sdk.NewCoin(fmt.Sprintf("%stoken", nodeDirName), cfg.AccountTokens), @@ -301,7 +382,9 @@ func New(t *testing.T, cfg Config) *Network { genAccounts = append(genAccounts, authtypes.NewBaseAccount(addr, nil, 0, 0)) commission, err := sdk.NewDecFromStr("0.5") - require.NoError(t, err) + if err != nil { + return nil, err + } createValMsg, err := stakingtypes.NewMsgCreateValidator( sdk.ValAddress(addr), @@ -311,15 +394,22 @@ func New(t *testing.T, cfg Config) *Network { stakingtypes.NewCommissionRates(commission, sdk.OneDec(), sdk.OneDec()), sdk.OneInt(), ) - require.NoError(t, err) + if err != nil { + return nil, err + } p2pURL, err := url.Parse(p2pAddr) - require.NoError(t, err) + if err != nil { + return nil, err + } memo := fmt.Sprintf("%s@%s:%s", nodeIDs[i], p2pURL.Hostname(), p2pURL.Port()) fee := sdk.NewCoins(sdk.NewCoin(fmt.Sprintf("%stoken", nodeDirName), sdk.NewInt(0))) txBuilder := cfg.TxConfig.NewTxBuilder() - require.NoError(t, txBuilder.SetMsgs(createValMsg)) + err = txBuilder.SetMsgs(createValMsg) + if err != nil { + return nil, err + } txBuilder.SetFeeAmount(fee) // Arbitrary fee txBuilder.SetGasLimit(1000000) // Need at least 100386 txBuilder.SetMemo(memo) @@ -332,11 +422,18 @@ func New(t *testing.T, cfg Config) *Network { WithTxConfig(cfg.TxConfig) err = tx.Sign(txFactory, nodeDirName, txBuilder, true) - require.NoError(t, err) + if err != nil { + return nil, err + } txBz, err := cfg.TxConfig.TxJSONEncoder()(txBuilder.GetTx()) - require.NoError(t, err) - require.NoError(t, writeFile(fmt.Sprintf("%v.json", nodeDirName), gentxsDir, txBz)) + if err != nil { + return nil, err + } + err = writeFile(fmt.Sprintf("%v.json", nodeDirName), gentxsDir, txBz) + if err != nil { + return nil, err + } srvconfig.WriteConfigFile(filepath.Join(nodeDir, "config/app.toml"), appCfg) @@ -367,21 +464,30 @@ func New(t *testing.T, cfg Config) *Network { } } - require.NoError(t, initGenFiles(cfg, genAccounts, genBalances, genFiles)) - require.NoError(t, collectGenFiles(cfg, network.Validators, network.BaseDir)) + err := initGenFiles(cfg, genAccounts, genBalances, genFiles) + if err != nil { + return nil, err + } + err = collectGenFiles(cfg, network.Validators, network.BaseDir) + if err != nil { + return nil, err + } - t.Log("starting test network...") + l.Log("starting test network...") for _, v := range network.Validators { - require.NoError(t, startInProcess(cfg, v)) + err := startInProcess(cfg, v) + if err != nil { + return nil, err + } } - t.Log("started test network") + l.Log("started test network") // Ensure we cleanup incase any test was abruptly halted (e.g. SIGINT) as any // defer in a test would not be called. server.TrapSignal(network.Cleanup) - return network + return network, nil } // LatestHeight returns the latest height of the network or an error if the @@ -459,10 +565,10 @@ func (n *Network) WaitForNextBlock() error { func (n *Network) Cleanup() { defer func() { lock.Unlock() - n.T.Log("released test network lock") + n.Logger.Log("released test network lock") }() - n.T.Log("cleaning up test network...") + n.Logger.Log("cleaning up test network...") for _, v := range n.Validators { if v.tmNode != nil && v.tmNode.IsRunning() { @@ -485,5 +591,47 @@ func (n *Network) Cleanup() { _ = os.RemoveAll(n.BaseDir) } - n.T.Log("finished cleaning up test network") + n.Logger.Log("finished cleaning up test network") +} + +// printMnemonic prints a provided mnemonic seed phrase on a network logger +// for debugging and manual testing +func printMnemonic(l Logger, secret string) { + lines := []string{ + "THIS MNEMONIC IS FOR TESTING PURPOSES ONLY", + "DO NOT USE IN PRODUCTION", + "", + strings.Join(strings.Fields(secret)[0:8], " "), + strings.Join(strings.Fields(secret)[8:16], " "), + strings.Join(strings.Fields(secret)[16:24], " "), + } + + lineLengths := make([]int, len(lines)) + for i, line := range lines { + lineLengths[i] = len(line) + } + + maxLineLength := 0 + for _, lineLen := range lineLengths { + if lineLen > maxLineLength { + maxLineLength = lineLen + } + } + + l.Log("\n") + l.Log(strings.Repeat("+", maxLineLength+8)) + for _, line := range lines { + l.Logf("++ %s ++\n", centerText(line, maxLineLength)) + } + l.Log(strings.Repeat("+", maxLineLength+8)) + l.Log("\n") +} + +// centerText centers text across a fixed width, filling either side with whitespace buffers +func centerText(text string, width int) string { + textLen := len(text) + leftBuffer := strings.Repeat(" ", (width-textLen)/2) + rightBuffer := strings.Repeat(" ", (width-textLen)/2+(width-textLen)%2) + + return fmt.Sprintf("%s%s%s", leftBuffer, text, rightBuffer) } diff --git a/testutil/network/network_test.go b/testutil/network/network_test.go index 3e45309f2f12..e13c8c454d28 100644 --- a/testutil/network/network_test.go +++ b/testutil/network/network_test.go @@ -20,10 +20,11 @@ type IntegrationTestSuite struct { func (s *IntegrationTestSuite) SetupSuite() { s.T().Log("setting up integration test suite") - s.network = network.New(s.T(), network.DefaultConfig()) - s.Require().NotNil(s.network) + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), network.DefaultConfig()) + s.Require().NoError(err) - _, err := s.network.WaitForHeight(1) + _, err = s.network.WaitForHeight(1) s.Require().NoError(err) } diff --git a/x/auth/client/rest/rest_test.go b/x/auth/client/rest/rest_test.go index 4d7ebf92687a..a382306e3228 100644 --- a/x/auth/client/rest/rest_test.go +++ b/x/auth/client/rest/rest_test.go @@ -48,12 +48,14 @@ func (s *IntegrationTestSuite) SetupSuite() { cfg := network.DefaultConfig() cfg.NumValidators = 2 - s.cfg = cfg - s.network = network.New(s.T(), cfg) + + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), cfg) + s.Require().NoError(err) kb := s.network.Validators[0].ClientCtx.Keyring - _, _, err := kb.NewMnemonic("newAccount", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1) + _, _, err = kb.NewMnemonic("newAccount", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1) s.Require().NoError(err) account1, _, err := kb.NewMnemonic("newAccount1", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1) diff --git a/x/auth/client/testutil/suite.go b/x/auth/client/testutil/suite.go index 773f8dba1ae9..c285a0841b15 100644 --- a/x/auth/client/testutil/suite.go +++ b/x/auth/client/testutil/suite.go @@ -48,10 +48,12 @@ func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite { func (s *IntegrationTestSuite) SetupSuite() { s.T().Log("setting up integration test suite") - s.network = network.New(s.T(), s.cfg) + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) + s.Require().NoError(err) kb := s.network.Validators[0].ClientCtx.Keyring - _, _, err := kb.NewMnemonic("newAccount", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1) + _, _, err = kb.NewMnemonic("newAccount", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1) s.Require().NoError(err) account1, _, err := kb.NewMnemonic("newAccount1", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1) diff --git a/x/auth/tx/service_test.go b/x/auth/tx/service_test.go index 9a4bc1d40d4b..266c81439f3d 100644 --- a/x/auth/tx/service_test.go +++ b/x/auth/tx/service_test.go @@ -49,14 +49,15 @@ func (s *IntegrationTestSuite) SetupSuite() { cfg := network.DefaultConfig() cfg.NumValidators = 1 - s.cfg = cfg - s.network = network.New(s.T(), cfg) - s.Require().NotNil(s.network) + + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) + s.Require().NoError(err) val := s.network.Validators[0] - _, err := s.network.WaitForHeight(1) + _, err = s.network.WaitForHeight(1) s.Require().NoError(err) s.queryClient = tx.NewServiceClient(val.ClientCtx) diff --git a/x/auth/types/account_retriever_test.go b/x/auth/types/account_retriever_test.go index 1053ffdcbdf6..e756a802daff 100644 --- a/x/auth/types/account_retriever_test.go +++ b/x/auth/types/account_retriever_test.go @@ -13,10 +13,11 @@ func TestAccountRetriever(t *testing.T) { cfg := network.DefaultConfig() cfg.NumValidators = 1 - network := network.New(t, cfg) + network, err := network.New(t, t.TempDir(), cfg) + require.NoError(t, err) defer network.Cleanup() - _, err := network.WaitForHeight(3) + _, err = network.WaitForHeight(3) require.NoError(t, err) val := network.Validators[0] diff --git a/x/auth/vesting/client/testutil/suite.go b/x/auth/vesting/client/testutil/suite.go index f619f31165c8..d76090f3089c 100644 --- a/x/auth/vesting/client/testutil/suite.go +++ b/x/auth/vesting/client/testutil/suite.go @@ -27,9 +27,11 @@ func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite { func (s *IntegrationTestSuite) SetupSuite() { s.T().Log("setting up integration test suite") - s.network = network.New(s.T(), s.cfg) + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) + s.Require().NoError(err) - _, err := s.network.WaitForHeight(1) + _, err = s.network.WaitForHeight(1) s.Require().NoError(err) } diff --git a/x/authz/client/rest/grpc_query_test.go b/x/authz/client/rest/grpc_query_test.go index 3f29323815ab..2de1e713bbca 100644 --- a/x/authz/client/rest/grpc_query_test.go +++ b/x/authz/client/rest/grpc_query_test.go @@ -37,10 +37,12 @@ func (s *IntegrationTestSuite) SetupSuite() { s.T().Log("setting up integration test suite") cfg := network.DefaultConfig() - cfg.NumValidators = 1 s.cfg = cfg - s.network = network.New(s.T(), cfg) + + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), cfg) + s.Require().NoError(err) val := s.network.Validators[0] // Create new account in the keyring. diff --git a/x/authz/client/testutil/tx.go b/x/authz/client/testutil/tx.go index 10932d9bda23..119edec998f0 100644 --- a/x/authz/client/testutil/tx.go +++ b/x/authz/client/testutil/tx.go @@ -38,7 +38,9 @@ func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite { func (s *IntegrationTestSuite) SetupSuite() { s.T().Log("setting up integration test suite") - s.network = network.New(s.T(), s.cfg) + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) + s.Require().NoError(err) val := s.network.Validators[0] diff --git a/x/bank/client/rest/query_test.go b/x/bank/client/rest/query_test.go index a9e43a53db86..ef9e26d5072a 100644 --- a/x/bank/client/rest/query_test.go +++ b/x/bank/client/rest/query_test.go @@ -58,9 +58,10 @@ func (s *IntegrationTestSuite) SetupSuite() { s.Require().NoError(err) genesisState[types.ModuleName] = bankGenesisBz cfg.GenesisState = genesisState - s.cfg = cfg - s.network = network.New(s.T(), cfg) + + s.network, err = network.New(s.T(), s.T().TempDir(), cfg) + s.Require().NoError(err) _, err = s.network.WaitForHeight(2) s.Require().NoError(err) diff --git a/x/bank/client/testutil/suite.go b/x/bank/client/testutil/suite.go index 19be5401c672..da09851701c1 100644 --- a/x/bank/client/testutil/suite.go +++ b/x/bank/client/testutil/suite.go @@ -80,7 +80,8 @@ func (s *IntegrationTestSuite) SetupSuite() { genesisState[types.ModuleName] = bankGenesisBz s.cfg.GenesisState = genesisState - s.network = network.New(s.T(), s.cfg) + s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) + s.Require().NoError(err) _, err = s.network.WaitForHeight(1) s.Require().NoError(err) diff --git a/x/crisis/client/testsuite/suite.go b/x/crisis/client/testsuite/suite.go index d0d82f62120b..c80679a2d4e6 100644 --- a/x/crisis/client/testsuite/suite.go +++ b/x/crisis/client/testsuite/suite.go @@ -27,8 +27,11 @@ func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite { func (s *IntegrationTestSuite) SetupSuite() { s.T().Log("setting up integration test suite") - s.network = network.New(s.T(), s.cfg) - _, err := s.network.WaitForHeight(1) + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) + s.Require().NoError(err) + + _, err = s.network.WaitForHeight(1) s.Require().NoError(err) } diff --git a/x/distribution/client/rest/grpc_query_test.go b/x/distribution/client/rest/grpc_query_test.go index ec8e2a7666dd..d458d4a5a2d8 100644 --- a/x/distribution/client/rest/grpc_query_test.go +++ b/x/distribution/client/rest/grpc_query_test.go @@ -28,11 +28,13 @@ func (s *IntegrationTestSuite) SetupSuite() { cfg := network.DefaultConfig() cfg.NumValidators = 1 - s.cfg = cfg - s.network = network.New(s.T(), cfg) - _, err := s.network.WaitForHeight(1) + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), cfg) + s.Require().NoError(err) + + _, err = s.network.WaitForHeight(1) s.Require().NoError(err) } diff --git a/x/distribution/client/testutil/suite.go b/x/distribution/client/testutil/suite.go index 3dcfca70aa68..3be8d5410aac 100644 --- a/x/distribution/client/testutil/suite.go +++ b/x/distribution/client/testutil/suite.go @@ -50,7 +50,8 @@ func (s *IntegrationTestSuite) SetupTest() { genesisState[minttypes.ModuleName] = mintDataBz s.cfg.GenesisState = genesisState - s.network = network.New(s.T(), s.cfg) + s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) + s.Require().NoError(err) _, err = s.network.WaitForHeight(1) s.Require().NoError(err) diff --git a/x/evidence/client/testutil/suite.go b/x/evidence/client/testutil/suite.go index d12083b64789..32eae04fd5d1 100644 --- a/x/evidence/client/testutil/suite.go +++ b/x/evidence/client/testutil/suite.go @@ -24,9 +24,11 @@ func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite { func (s *IntegrationTestSuite) SetupSuite() { s.T().Log("setting up integration test suite") - s.network = network.New(s.T(), s.cfg) + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) + s.Require().NoError(err) - _, err := s.network.WaitForHeight(1) + _, err = s.network.WaitForHeight(1) s.Require().NoError(err) } diff --git a/x/feegrant/client/testutil/suite.go b/x/feegrant/client/testutil/suite.go index c539cf84766f..74fe155e66ea 100644 --- a/x/feegrant/client/testutil/suite.go +++ b/x/feegrant/client/testutil/suite.go @@ -50,9 +50,11 @@ func (s *IntegrationTestSuite) SetupSuite() { s.T().Skip("skipping test in unit-tests mode.") } - s.network = network.New(s.T(), s.cfg) + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) + s.Require().NoError(err) - _, err := s.network.WaitForHeight(1) + _, err = s.network.WaitForHeight(1) s.Require().NoError(err) val := s.network.Validators[0] diff --git a/x/genutil/client/testutil/suite.go b/x/genutil/client/testutil/suite.go index 4c5c38918506..bc226a2ab100 100644 --- a/x/genutil/client/testutil/suite.go +++ b/x/genutil/client/testutil/suite.go @@ -34,9 +34,11 @@ func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite { func (s *IntegrationTestSuite) SetupSuite() { s.T().Log("setting up integration test suite") - s.network = network.New(s.T(), s.cfg) + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) + s.Require().NoError(err) - _, err := s.network.WaitForHeight(1) + _, err = s.network.WaitForHeight(1) s.Require().NoError(err) } diff --git a/x/gov/client/rest/grpc_query_test.go b/x/gov/client/rest/grpc_query_test.go index 12247aeb9a91..a7806bde2e62 100644 --- a/x/gov/client/rest/grpc_query_test.go +++ b/x/gov/client/rest/grpc_query_test.go @@ -32,9 +32,11 @@ func (s *IntegrationTestSuite) SetupSuite() { s.cfg = network.DefaultConfig() s.cfg.NumValidators = 1 - s.network = network.New(s.T(), s.cfg) + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) + s.Require().NoError(err) - _, err := s.network.WaitForHeight(1) + _, err = s.network.WaitForHeight(1) s.Require().NoError(err) val := s.network.Validators[0] diff --git a/x/gov/client/testutil/deposits.go b/x/gov/client/testutil/deposits.go index 57c3c9363330..a6096eb33ab4 100644 --- a/x/gov/client/testutil/deposits.go +++ b/x/gov/client/testutil/deposits.go @@ -28,9 +28,11 @@ func NewDepositTestSuite(cfg network.Config) *DepositTestSuite { func (s *DepositTestSuite) SetupSuite() { s.T().Log("setting up test suite") - s.network = network.New(s.T(), s.cfg) + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) + s.Require().NoError(err) - _, err := s.network.WaitForHeight(1) + _, err = s.network.WaitForHeight(1) s.Require().NoError(err) s.fees = sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(20))).String() diff --git a/x/gov/client/testutil/suite.go b/x/gov/client/testutil/suite.go index ee2634e3d188..ba1db3ff6272 100644 --- a/x/gov/client/testutil/suite.go +++ b/x/gov/client/testutil/suite.go @@ -33,9 +33,11 @@ func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite { func (s *IntegrationTestSuite) SetupSuite() { s.T().Log("setting up integration test suite") - s.network = network.New(s.T(), s.cfg) + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) + s.Require().NoError(err) - _, err := s.network.WaitForHeight(1) + _, err = s.network.WaitForHeight(1) s.Require().NoError(err) val := s.network.Validators[0] diff --git a/x/mint/client/rest/grpc_query_test.go b/x/mint/client/rest/grpc_query_test.go index fdbb4ff75998..d813d6467b91 100644 --- a/x/mint/client/rest/grpc_query_test.go +++ b/x/mint/client/rest/grpc_query_test.go @@ -45,7 +45,8 @@ func (s *IntegrationTestSuite) SetupSuite() { cfg.GenesisState = genesisState s.cfg = cfg - s.network = network.New(s.T(), cfg) + s.network, err = network.New(s.T(), s.T().TempDir(), cfg) + s.Require().NoError(err) _, err = s.network.WaitForHeight(1) s.Require().NoError(err) diff --git a/x/mint/client/testutil/suite.go b/x/mint/client/testutil/suite.go index 24e74267608c..dd90d2d54333 100644 --- a/x/mint/client/testutil/suite.go +++ b/x/mint/client/testutil/suite.go @@ -44,7 +44,8 @@ func (s *IntegrationTestSuite) SetupSuite() { genesisState[minttypes.ModuleName] = mintDataBz s.cfg.GenesisState = genesisState - s.network = network.New(s.T(), s.cfg) + s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) + s.Require().NoError(err) _, err = s.network.WaitForHeight(1) s.Require().NoError(err) diff --git a/x/params/client/rest/grpc_query_test.go b/x/params/client/rest/grpc_query_test.go index f2c4440e29d5..8de3f2cbd878 100644 --- a/x/params/client/rest/grpc_query_test.go +++ b/x/params/client/rest/grpc_query_test.go @@ -24,11 +24,13 @@ func (s *IntegrationTestSuite) SetupSuite() { cfg := network.DefaultConfig() cfg.NumValidators = 1 - s.cfg = cfg - s.network = network.New(s.T(), cfg) - _, err := s.network.WaitForHeight(1) + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), cfg) + s.Require().NoError(err) + + _, err = s.network.WaitForHeight(1) s.Require().NoError(err) } diff --git a/x/params/client/testutil/suite.go b/x/params/client/testutil/suite.go index e539b8791df6..c38d93b9b66e 100644 --- a/x/params/client/testutil/suite.go +++ b/x/params/client/testutil/suite.go @@ -26,9 +26,11 @@ func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite { func (s *IntegrationTestSuite) SetupSuite() { s.T().Log("setting up integration test suite") - s.network = network.New(s.T(), s.cfg) + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) + s.Require().NoError(err) - _, err := s.network.WaitForHeight(1) + _, err = s.network.WaitForHeight(1) s.Require().NoError(err) } diff --git a/x/slashing/client/rest/grpc_query_test.go b/x/slashing/client/rest/grpc_query_test.go index 39daf06f69c5..0531d1e98ebf 100644 --- a/x/slashing/client/rest/grpc_query_test.go +++ b/x/slashing/client/rest/grpc_query_test.go @@ -28,11 +28,13 @@ func (s *IntegrationTestSuite) SetupSuite() { cfg := network.DefaultConfig() cfg.NumValidators = 1 - s.cfg = cfg - s.network = network.New(s.T(), cfg) - _, err := s.network.WaitForHeight(1) + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), cfg) + s.Require().NoError(err) + + _, err = s.network.WaitForHeight(1) s.Require().NoError(err) } diff --git a/x/slashing/client/testutil/suite.go b/x/slashing/client/testutil/suite.go index cf5cf997b6c3..06bcdca70110 100644 --- a/x/slashing/client/testutil/suite.go +++ b/x/slashing/client/testutil/suite.go @@ -31,9 +31,11 @@ func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite { func (s *IntegrationTestSuite) SetupSuite() { s.T().Log("setting up integration test suite") - s.network = network.New(s.T(), s.cfg) + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) + s.Require().NoError(err) - _, err := s.network.WaitForHeight(1) + _, err = s.network.WaitForHeight(1) s.Require().NoError(err) } diff --git a/x/staking/client/rest/grpc_query_test.go b/x/staking/client/rest/grpc_query_test.go index 55a10194f603..29e95775e29f 100644 --- a/x/staking/client/rest/grpc_query_test.go +++ b/x/staking/client/rest/grpc_query_test.go @@ -35,11 +35,13 @@ func (s *IntegrationTestSuite) SetupSuite() { cfg := network.DefaultConfig() cfg.NumValidators = 2 - s.cfg = cfg - s.network = network.New(s.T(), cfg) - _, err := s.network.WaitForHeight(1) + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), cfg) + s.Require().NoError(err) + + _, err = s.network.WaitForHeight(1) s.Require().NoError(err) unbond, err := sdk.ParseCoinNormalized("10stake") diff --git a/x/staking/client/testutil/suite.go b/x/staking/client/testutil/suite.go index f24a1ad5a234..fc6229ecca43 100644 --- a/x/staking/client/testutil/suite.go +++ b/x/staking/client/testutil/suite.go @@ -43,9 +43,11 @@ func (s *IntegrationTestSuite) SetupSuite() { s.T().Skip("skipping test in unit-tests mode.") } - s.network = network.New(s.T(), s.cfg) + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) + s.Require().NoError(err) - _, err := s.network.WaitForHeight(1) + _, err = s.network.WaitForHeight(1) s.Require().NoError(err) unbond, err := sdk.ParseCoinNormalized("10stake") diff --git a/x/upgrade/client/testutil/suite.go b/x/upgrade/client/testutil/suite.go index 6b559e823c77..bfa7859087d2 100644 --- a/x/upgrade/client/testutil/suite.go +++ b/x/upgrade/client/testutil/suite.go @@ -36,7 +36,10 @@ func (s *IntegrationTestSuite) SetupSuite() { cfg.NumValidators = 1 s.cfg = cfg - s.network = network.New(s.T(), cfg) + + var err error + s.network, err = network.New(s.T(), s.T().TempDir(), cfg) + s.Require().NoError(err) } func (s *IntegrationTestSuite) TearDownSuite() {