CLI/Tests: Remove Fixtures (#6799)
* remove fixtures * setup tests * update x/mint * cli: update x/staking commands * tests: convert x/staking CLI tests * tests: fix x/auth CLI tests * cli updates * fix buiild * fix build * Update x/gov/client/cli/cli_test.go Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com> * remove GenerateOrBroadcastTx * move TestCLIQueryConn Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com>
This commit is contained in:
co-authored by
Amaury Martiny
Federico Kunze
parent
6e7ce48b31
commit
0ccc48d2a3
+177
-17
@@ -1,30 +1,190 @@
|
||||
// +build cli_test
|
||||
|
||||
package cli_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
tmcli "github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/tests/cli"
|
||||
"github.com/cosmos/cosmos-sdk/x/mint/client/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
testnet "github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/mint/client/cli"
|
||||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||
)
|
||||
|
||||
func TestCLIMintQueries(t *testing.T) {
|
||||
t.SkipNow() // TODO: Bring back once viper is refactored.
|
||||
t.Parallel()
|
||||
f := cli.InitFixtures(t)
|
||||
type IntegrationTestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
proc := f.SDStart()
|
||||
t.Cleanup(func() { proc.Stop(false) })
|
||||
cfg testnet.Config
|
||||
network *testnet.Network
|
||||
}
|
||||
|
||||
params := testutil.QueryMintingParams(f)
|
||||
require.NotEmpty(t, params)
|
||||
func (s *IntegrationTestSuite) SetupSuite() {
|
||||
s.T().Log("setting up integration test suite")
|
||||
|
||||
inflation := testutil.QueryInflation(f)
|
||||
require.False(t, inflation.IsZero())
|
||||
cfg := testnet.DefaultConfig()
|
||||
genesisState := cfg.GenesisState
|
||||
cfg.NumValidators = 1
|
||||
|
||||
annualProvisions := testutil.QueryAnnualProvisions(f)
|
||||
require.False(t, annualProvisions.IsZero())
|
||||
var mintData minttypes.GenesisState
|
||||
s.Require().NoError(cfg.Codec.UnmarshalJSON(genesisState[minttypes.ModuleName], &mintData))
|
||||
|
||||
inflation := sdk.MustNewDecFromStr("1.0")
|
||||
mintData.Minter.Inflation = inflation
|
||||
mintData.Params.InflationMin = inflation
|
||||
mintData.Params.InflationMax = inflation
|
||||
|
||||
mintDataBz, err := cfg.Codec.MarshalJSON(mintData)
|
||||
s.Require().NoError(err)
|
||||
genesisState[minttypes.ModuleName] = mintDataBz
|
||||
cfg.GenesisState = genesisState
|
||||
|
||||
s.cfg = cfg
|
||||
s.network = testnet.New(s.T(), cfg)
|
||||
|
||||
_, err = s.network.WaitForHeight(1)
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TearDownSuite() {
|
||||
s.T().Log("tearing down integration test suite")
|
||||
s.network.Cleanup()
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestGetCmdQueryParams() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectedOutput string
|
||||
}{
|
||||
{
|
||||
"default output",
|
||||
[]string{fmt.Sprintf("--%s=1", flags.FlagHeight)},
|
||||
`{"mint_denom":"stake","inflation_rate_change":"0.130000000000000000","inflation_max":"1.000000000000000000","inflation_min":"1.000000000000000000","goal_bonded":"0.670000000000000000","blocks_per_year":"6311520"}`,
|
||||
},
|
||||
{
|
||||
"text output",
|
||||
[]string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=text", tmcli.OutputFlag)},
|
||||
`blocks_per_year: "6311520"
|
||||
goal_bonded: "0.670000000000000000"
|
||||
inflation_max: "1.000000000000000000"
|
||||
inflation_min: "1.000000000000000000"
|
||||
inflation_rate_change: "0.130000000000000000"
|
||||
mint_denom: stake`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.GetCmdQueryParams()
|
||||
_, out := testutil.ApplyMockIO(cmd)
|
||||
|
||||
clientCtx := val.ClientCtx.WithOutput(out)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
|
||||
|
||||
out.Reset()
|
||||
cmd.SetArgs(tc.args)
|
||||
|
||||
s.Require().NoError(cmd.ExecuteContext(ctx))
|
||||
s.Require().Equal(tc.expectedOutput, strings.TrimSpace(out.String()))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestGetCmdQueryInflation() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectedOutput string
|
||||
}{
|
||||
{
|
||||
"default output",
|
||||
[]string{fmt.Sprintf("--%s=1", flags.FlagHeight)},
|
||||
`"1.000000000000000000"`,
|
||||
},
|
||||
{
|
||||
"text output",
|
||||
[]string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=text", tmcli.OutputFlag)},
|
||||
`"1.000000000000000000"`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.GetCmdQueryInflation()
|
||||
_, out := testutil.ApplyMockIO(cmd)
|
||||
|
||||
clientCtx := val.ClientCtx.WithOutput(out)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
|
||||
|
||||
out.Reset()
|
||||
cmd.SetArgs(tc.args)
|
||||
|
||||
s.Require().NoError(cmd.ExecuteContext(ctx))
|
||||
s.Require().Equal(tc.expectedOutput, strings.TrimSpace(out.String()))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestGetCmdQueryAnnualProvisions() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectedOutput string
|
||||
}{
|
||||
{
|
||||
"default output",
|
||||
[]string{fmt.Sprintf("--%s=1", flags.FlagHeight)},
|
||||
`"500000000.000000000000000000"`,
|
||||
},
|
||||
{
|
||||
"text output",
|
||||
[]string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=text", tmcli.OutputFlag)},
|
||||
`"500000000.000000000000000000"`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.GetCmdQueryAnnualProvisions()
|
||||
_, out := testutil.ApplyMockIO(cmd)
|
||||
|
||||
clientCtx := val.ClientCtx.WithOutput(out)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
|
||||
|
||||
out.Reset()
|
||||
cmd.SetArgs(tc.args)
|
||||
|
||||
s.Require().NoError(cmd.ExecuteContext(ctx))
|
||||
s.Require().Equal(tc.expectedOutput, strings.TrimSpace(out.String()))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntegrationTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(IntegrationTestSuite))
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ func GetCmdQueryParams() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintOutput(res.Params)
|
||||
return clientCtx.PrintOutput(res.GetParams())
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user