wormhole/wormchain/x/wormhole/client/cli/query_config_test.go

68 lines
1.7 KiB
Go

package cli_test
import (
"fmt"
"testing"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/stretchr/testify/require"
tmcli "github.com/tendermint/tendermint/libs/cli"
"google.golang.org/grpc/status"
"github.com/wormhole-foundation/wormchain/testutil/network"
"github.com/wormhole-foundation/wormchain/x/wormhole/client/cli"
"github.com/wormhole-foundation/wormchain/x/wormhole/types"
)
func networkWithConfigObjects(t *testing.T) (*network.Network, types.Config) {
t.Helper()
cfg := network.DefaultConfig()
state := types.GenesisState{}
require.NoError(t, cfg.Codec.UnmarshalJSON(cfg.GenesisState[types.ModuleName], &state))
state.Config = &types.Config{}
buf, err := cfg.Codec.MarshalJSON(&state)
require.NoError(t, err)
cfg.GenesisState[types.ModuleName] = buf
return network.New(t, cfg), *state.Config
}
func TestShowConfig(t *testing.T) {
net, obj := networkWithConfigObjects(t)
ctx := net.Validators[0].ClientCtx
common := []string{
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
}
for _, tc := range []struct {
desc string
args []string
err error
obj types.Config
}{
{
desc: "get",
args: common,
obj: obj,
},
} {
tc := tc
t.Run(tc.desc, func(t *testing.T) {
var args []string
args = append(args, tc.args...)
out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdShowConfig(), args)
if tc.err != nil {
stat, ok := status.FromError(tc.err)
require.True(t, ok)
require.ErrorIs(t, stat.Err(), tc.err)
} else {
require.NoError(t, err)
var resp types.QueryGetConfigResponse
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
require.NotNil(t, resp.Config)
require.Equal(t, tc.obj, resp.Config)
}
})
}
}