Module Viper Removal (#6604)
* Remove viper * Remove viper * Remove viper * Skip TestCLIValidateGenesis * remove cruft leftover Co-authored-by: Alessio Treglia <alessio@tendermint.com>
This commit is contained in:
parent
437b035160
commit
51df2f2033
@ -111,6 +111,7 @@ func TestCLISimdAddGenesisAccount(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCLIValidateGenesis(t *testing.T) {
|
||||
t.SkipNow()
|
||||
t.Parallel()
|
||||
f := cli.InitFixtures(t)
|
||||
|
||||
|
||||
@ -6,7 +6,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
@ -105,7 +104,8 @@ $ %s tx distribution withdraw-rewards cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fx
|
||||
}
|
||||
|
||||
msgs := []sdk.Msg{types.NewMsgWithdrawDelegatorReward(delAddr, valAddr)}
|
||||
if viper.GetBool(flagCommission) {
|
||||
|
||||
if commission, _ := cmd.Flags().GetBool(flagCommission); commission {
|
||||
msgs = append(msgs, types.NewMsgWithdrawValidatorCommission(valAddr))
|
||||
}
|
||||
|
||||
@ -118,6 +118,7 @@ $ %s tx distribution withdraw-rewards cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fx
|
||||
return tx.GenerateOrBroadcastTx(clientCtx, msgs...)
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().Bool(flagCommission, false, "also withdraw validator's commission")
|
||||
return cmd
|
||||
}
|
||||
@ -152,7 +153,7 @@ $ %s tx distribution withdraw-all-rewards --from mykey
|
||||
return err
|
||||
}
|
||||
|
||||
chunkSize := viper.GetInt(flagMaxMessagesPerTx)
|
||||
chunkSize, _ := cmd.Flags().GetInt(flagMaxMessagesPerTx)
|
||||
return newSplitAndApply(tx.GenerateOrBroadcastTx, clientCtx, msgs, chunkSize)
|
||||
},
|
||||
}
|
||||
|
||||
@ -3,17 +3,14 @@ package common
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
)
|
||||
|
||||
func TestQueryDelegationRewardsAddrValidation(t *testing.T) {
|
||||
viper.Set(flags.FlagOffline, true)
|
||||
ctx := client.NewContext().WithJSONMarshaler(types.ModuleCdc)
|
||||
clientCtx := client.Context{}.WithJSONMarshaler(types.ModuleCdc).WithTrustNode(true)
|
||||
|
||||
type args struct {
|
||||
delAddr string
|
||||
@ -35,7 +32,7 @@ func TestQueryDelegationRewardsAddrValidation(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, _, err := QueryDelegationRewards(ctx, "", tt.args.delAddr, tt.args.valAddr)
|
||||
_, _, err := QueryDelegationRewards(clientCtx, "", tt.args.delAddr, tt.args.valAddr)
|
||||
require.True(t, err != nil, tt.wantErr)
|
||||
})
|
||||
}
|
||||
|
||||
@ -6,7 +6,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
@ -58,7 +57,10 @@ func QueryEvidenceCmd(cdc *codec.Codec) func(*cobra.Command, []string) error {
|
||||
return queryEvidence(cdc, clientCtx, hash)
|
||||
}
|
||||
|
||||
return queryAllEvidence(cdc, clientCtx)
|
||||
page, _ := cmd.Flags().GetInt(flags.FlagPage)
|
||||
limit, _ := cmd.Flags().GetInt(flags.FlagLimit)
|
||||
|
||||
return queryAllEvidence(clientCtx, page, limit)
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,9 +90,9 @@ func queryEvidence(cdc *codec.Codec, clientCtx client.Context, hash string) erro
|
||||
return clientCtx.PrintOutput(evidence)
|
||||
}
|
||||
|
||||
func queryAllEvidence(cdc *codec.Codec, clientCtx client.Context) error {
|
||||
params := types.NewQueryAllEvidenceParams(viper.GetInt(flags.FlagPage), viper.GetInt(flags.FlagLimit))
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
func queryAllEvidence(clientCtx client.Context, page, limit int) error {
|
||||
params := types.NewQueryAllEvidenceParams(page, limit)
|
||||
bz, err := clientCtx.JSONMarshaler.MarshalJSON(params)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to marshal query params: %w", err)
|
||||
}
|
||||
@ -102,7 +104,7 @@ func queryAllEvidence(cdc *codec.Codec, clientCtx client.Context) error {
|
||||
}
|
||||
|
||||
var evidence []exported.Evidence
|
||||
err = cdc.UnmarshalJSON(res, &evidence)
|
||||
err = clientCtx.JSONMarshaler.UnmarshalJSON(res, &evidence)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to unmarshal evidence: %w", err)
|
||||
}
|
||||
|
||||
@ -5,25 +5,27 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
govutils "github.com/cosmos/cosmos-sdk/x/gov/client/utils"
|
||||
)
|
||||
|
||||
func parseSubmitProposalFlags() (*proposal, error) {
|
||||
func parseSubmitProposalFlags(fs *pflag.FlagSet) (*proposal, error) {
|
||||
proposal := &proposal{}
|
||||
proposalFile := viper.GetString(FlagProposal)
|
||||
proposalFile, _ := fs.GetString(FlagProposal)
|
||||
|
||||
if proposalFile == "" {
|
||||
proposal.Title = viper.GetString(FlagTitle)
|
||||
proposal.Description = viper.GetString(FlagDescription)
|
||||
proposal.Type = govutils.NormalizeProposalType(viper.GetString(flagProposalType))
|
||||
proposal.Deposit = viper.GetString(FlagDeposit)
|
||||
proposalType, _ := fs.GetString(flagProposalType)
|
||||
|
||||
proposal.Title, _ = fs.GetString(FlagTitle)
|
||||
proposal.Description, _ = fs.GetString(FlagDescription)
|
||||
proposal.Type = govutils.NormalizeProposalType(proposalType)
|
||||
proposal.Deposit, _ = fs.GetString(FlagDeposit)
|
||||
return proposal, nil
|
||||
}
|
||||
|
||||
for _, flag := range ProposalFlags {
|
||||
if viper.GetString(flag) != "" {
|
||||
if v, _ := fs.GetString(flag); v != "" {
|
||||
return nil, fmt.Errorf("--%s flag provided alongside --proposal, which is a noop", flag)
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,8 +4,9 @@ import (
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
)
|
||||
|
||||
func TestParseSubmitProposalFlags(t *testing.T) {
|
||||
@ -25,19 +26,21 @@ func TestParseSubmitProposalFlags(t *testing.T) {
|
||||
require.Nil(t, err, "unexpected error")
|
||||
badJSON.WriteString("bad json")
|
||||
|
||||
fs := NewCmdSubmitProposal(client.Context{}).Flags()
|
||||
|
||||
// nonexistent json
|
||||
viper.Set(FlagProposal, "fileDoesNotExist")
|
||||
_, err = parseSubmitProposalFlags()
|
||||
fs.Set(FlagProposal, "fileDoesNotExist")
|
||||
_, err = parseSubmitProposalFlags(fs)
|
||||
require.Error(t, err)
|
||||
|
||||
// invalid json
|
||||
viper.Set(FlagProposal, badJSON.Name())
|
||||
_, err = parseSubmitProposalFlags()
|
||||
fs.Set(FlagProposal, badJSON.Name())
|
||||
_, err = parseSubmitProposalFlags(fs)
|
||||
require.Error(t, err)
|
||||
|
||||
// ok json
|
||||
viper.Set(FlagProposal, okJSON.Name())
|
||||
proposal1, err := parseSubmitProposalFlags()
|
||||
fs.Set(FlagProposal, okJSON.Name())
|
||||
proposal1, err := parseSubmitProposalFlags(fs)
|
||||
require.Nil(t, err, "unexpected error")
|
||||
require.Equal(t, "Test Proposal", proposal1.Title)
|
||||
require.Equal(t, "My awesome proposal", proposal1.Description)
|
||||
@ -46,19 +49,20 @@ func TestParseSubmitProposalFlags(t *testing.T) {
|
||||
|
||||
// flags that can't be used with --proposal
|
||||
for _, incompatibleFlag := range ProposalFlags {
|
||||
viper.Set(incompatibleFlag, "some value")
|
||||
_, err := parseSubmitProposalFlags()
|
||||
fs.Set(incompatibleFlag, "some value")
|
||||
_, err := parseSubmitProposalFlags(fs)
|
||||
require.Error(t, err)
|
||||
viper.Set(incompatibleFlag, "")
|
||||
fs.Set(incompatibleFlag, "")
|
||||
}
|
||||
|
||||
// no --proposal, only flags
|
||||
viper.Set(FlagProposal, "")
|
||||
viper.Set(FlagTitle, proposal1.Title)
|
||||
viper.Set(FlagDescription, proposal1.Description)
|
||||
viper.Set(flagProposalType, proposal1.Type)
|
||||
viper.Set(FlagDeposit, proposal1.Deposit)
|
||||
proposal2, err := parseSubmitProposalFlags()
|
||||
fs.Set(FlagProposal, "")
|
||||
fs.Set(FlagTitle, proposal1.Title)
|
||||
fs.Set(FlagDescription, proposal1.Description)
|
||||
fs.Set(flagProposalType, proposal1.Type)
|
||||
fs.Set(FlagDeposit, proposal1.Deposit)
|
||||
proposal2, err := parseSubmitProposalFlags(fs)
|
||||
|
||||
require.Nil(t, err, "unexpected error")
|
||||
require.Equal(t, proposal1.Title, proposal2.Title)
|
||||
require.Equal(t, proposal1.Description, proposal2.Description)
|
||||
|
||||
@ -6,7 +6,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
@ -99,11 +98,11 @@ $ %s query gov proposals --page=2 --limit=100
|
||||
),
|
||||
),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
bechDepositorAddr := viper.GetString(flagDepositor)
|
||||
bechVoterAddr := viper.GetString(flagVoter)
|
||||
strProposalStatus := viper.GetString(flagStatus)
|
||||
page := viper.GetInt(flags.FlagPage)
|
||||
limit := viper.GetInt(flags.FlagLimit)
|
||||
bechDepositorAddr, _ := cmd.Flags().GetString(flagDepositor)
|
||||
bechVoterAddr, _ := cmd.Flags().GetString(flagVoter)
|
||||
strProposalStatus, _ := cmd.Flags().GetString(flagStatus)
|
||||
page, _ := cmd.Flags().GetInt(flags.FlagPage)
|
||||
limit, _ := cmd.Flags().GetInt(flags.FlagLimit)
|
||||
|
||||
var depositorAddr sdk.AccAddress
|
||||
var voterAddr sdk.AccAddress
|
||||
@ -265,8 +264,8 @@ $ %[1]s query gov votes 1 --page=2 --limit=100
|
||||
return fmt.Errorf("proposal-id %s not a valid int, please input a valid proposal-id", args[0])
|
||||
}
|
||||
|
||||
page := viper.GetInt(flags.FlagPage)
|
||||
limit := viper.GetInt(flags.FlagLimit)
|
||||
page, _ := cmd.Flags().GetInt(flags.FlagPage)
|
||||
limit, _ := cmd.Flags().GetInt(flags.FlagLimit)
|
||||
|
||||
params := types.NewQueryProposalVotesParams(proposalID, page, limit)
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
|
||||
@ -107,7 +107,7 @@ $ %s tx gov submit-proposal --title="Test Proposal" --description="My awesome pr
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx := clientCtx.InitWithInput(cmd.InOrStdin())
|
||||
|
||||
proposal, err := parseSubmitProposalFlags()
|
||||
proposal, err := parseSubmitProposalFlags(cmd.Flags())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -7,14 +7,12 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/require"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/store/rootmulti"
|
||||
store "github.com/cosmos/cosmos-sdk/store/types"
|
||||
"github.com/cosmos/cosmos-sdk/tests"
|
||||
@ -70,8 +68,6 @@ func TestSetLoader(t *testing.T) {
|
||||
// set a temporary home dir
|
||||
homeDir, cleanup := tests.NewTestCaseDir(t)
|
||||
t.Cleanup(cleanup)
|
||||
// TODO cleanup viper
|
||||
viper.Set(flags.FlagHome, homeDir)
|
||||
|
||||
upgradeInfoFilePath := filepath.Join(homeDir, "upgrade-info.json")
|
||||
upgradeInfo := &store.UpgradeInfo{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user