From e21e9b143ef231c1abbf3473cf2560c9e2898dd2 Mon Sep 17 00:00:00 2001 From: Alex Peters Date: Wed, 11 Nov 2020 12:08:57 +0100 Subject: [PATCH] Use correct directories for commands --- .circleci/config.yml | 2 +- cmd/wasmcli/main.go | 2 +- cmd/wasmd/cmd_test.go | 23 ++++++++++ cmd/wasmd/genaccounts_test.go | 85 +++++++++++++++++++++++++++++++++++ cmd/wasmd/root.go | 2 +- 5 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 cmd/wasmd/cmd_test.go create mode 100644 cmd/wasmd/genaccounts_test.go diff --git a/.circleci/config.yml b/.circleci/config.yml index 7156f72f72..3578ed096b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ version: 2.1 executors: golang: docker: - - image: circleci/golang:1.14 + - image: circleci/golang:1.15 working_directory: /go/src/github.com/cosmwasm/wasmd commands: diff --git a/cmd/wasmcli/main.go b/cmd/wasmcli/main.go index 9663b15594..1b204b4816 100644 --- a/cmd/wasmcli/main.go +++ b/cmd/wasmcli/main.go @@ -71,7 +71,7 @@ func main() { txCommand(), flags.LineBreak, flags.LineBreak, - keys.Commands(app.DefaultNodeHome), + keys.Commands(app.DefaultCLIHome), flags.LineBreak, //version.Cmd, cli.NewCompletionCmd(rootCmd, true), diff --git a/cmd/wasmd/cmd_test.go b/cmd/wasmd/cmd_test.go new file mode 100644 index 0000000000..2ee3239b0d --- /dev/null +++ b/cmd/wasmd/cmd_test.go @@ -0,0 +1,23 @@ +package main_test + +import ( + "fmt" + "testing" + + wasmd "github.com/CosmWasm/wasmd/cmd/wasmd" + "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" +) + +func TestInitCmd(t *testing.T) { + rootCmd, _ := wasmd.NewRootCmd() + rootCmd.SetArgs([]string{ + "init", // Test the init cmd + "simapp-test", // Moniker + fmt.Sprintf("--%s=%s", cli.FlagOverwrite, "true"), // Overwrite genesis.json, in case it already exists + }) + + err := wasmd.Execute(rootCmd) + require.NoError(t, err) +} diff --git a/cmd/wasmd/genaccounts_test.go b/cmd/wasmd/genaccounts_test.go new file mode 100644 index 0000000000..a8f920b898 --- /dev/null +++ b/cmd/wasmd/genaccounts_test.go @@ -0,0 +1,85 @@ +package main_test + +import ( + "context" + "fmt" + "testing" + + "github.com/spf13/viper" + "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/libs/log" + + wasmd "github.com/CosmWasm/wasmd/cmd/wasmd" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/server" + "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/testutil/testdata" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/x/genutil" + genutiltest "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil" +) + +var testMbm = module.NewBasicManager(genutil.AppModuleBasic{}) + +func TestAddGenesisAccountCmd(t *testing.T) { + _, _, addr1 := testdata.KeyTestPubAddr() + tests := []struct { + name string + addr string + denom string + expectErr bool + }{ + { + name: "invalid address", + addr: "", + denom: "1000atom", + expectErr: true, + }, + { + name: "valid address", + addr: addr1.String(), + denom: "1000atom", + expectErr: false, + }, + { + name: "multiple denoms", + addr: addr1.String(), + denom: "1000atom, 2000stake", + expectErr: false, + }, + } + + for _, tc := range tests { + tc := tc + t.Run(tc.name, func(t *testing.T) { + home := t.TempDir() + logger := log.NewNopLogger() + cfg, err := genutiltest.CreateDefaultTendermintConfig(home) + require.NoError(t, err) + + appCodec, _ := simapp.MakeCodecs() + err = genutiltest.ExecInitCmd(testMbm, home, appCodec) + require.NoError(t, err) + + serverCtx := server.NewContext(viper.New(), cfg, logger) + clientCtx := client.Context{}.WithJSONMarshaler(appCodec).WithHomeDir(home) + + ctx := context.Background() + ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) + ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx) + + cmd := wasmd.AddGenesisAccountCmd(home) + cmd.SetArgs([]string{ + tc.addr, + tc.denom, + fmt.Sprintf("--%s=home", flags.FlagHome)}) + + if tc.expectErr { + require.Error(t, cmd.ExecuteContext(ctx)) + } else { + require.NoError(t, cmd.ExecuteContext(ctx)) + } + }) + } +} diff --git a/cmd/wasmd/root.go b/cmd/wasmd/root.go index e5d290f083..d33eb363a1 100644 --- a/cmd/wasmd/root.go +++ b/cmd/wasmd/root.go @@ -98,7 +98,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig app.EncodingConfig) { genutilcli.MigrateGenesisCmd(), genutilcli.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome), genutilcli.ValidateGenesisCmd(app.ModuleBasics, encodingConfig.TxConfig), - AddGenesisAccountCmd(app.DefaultNodeHome), + AddGenesisAccountCmd(app.DefaultCLIHome), tmcli.NewCompletionCmd(rootCmd, true), // testnetCmd(app.ModuleBasics, banktypes.GenesisBalancesIterator{}), debug.Cmd(),