Skip to content

Commit

Permalink
Use correct directories for commands
Browse files Browse the repository at this point in the history
  • Loading branch information
alpe committed Nov 11, 2020
1 parent cbda602 commit e21e9b1
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion cmd/wasmcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
23 changes: 23 additions & 0 deletions cmd/wasmd/cmd_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
85 changes: 85 additions & 0 deletions cmd/wasmd/genaccounts_test.go
Original file line number Diff line number Diff line change
@@ -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))
}
})
}
}
2 changes: 1 addition & 1 deletion cmd/wasmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit e21e9b1

Please sign in to comment.