cosmos-sdk/x/staking/client/cli/tx_test.go

156 lines
4.7 KiB
Go
Raw Normal View History

Merge PR #4159: Module/Genesis Generalization * first commit * gaia cleanup * ... * staking multihooks * missing module function return args * bank module name constant * working, module interface for x/ * got this thing compiling * make test compiles and passes * remove expanded simulation invariants * genesis issue * continued * continued * register crisis routes thought mm * begin blocker to mm * end blocker to mm * empty routes not initialized * move gaia initChainer sanity check to baseapp * remove codecs from module manager * reorging genesis stuff * module manager passed by reference/bugfixes from working last commit int int * move invariant checks from gaia to crisis * typo * basic refactors cmd/gaia/init * working * MultiStakingHooks from types to x/staking/types int * default module manager order of operations from input modules * working * typo * add AppModuleBasic * moduleBasicManager / non-test code compiles * working attempting to get tests passing * make test passes * sim random genesis fix * export bug * ... * genutil module * genutil working * refactored - happy with non-testing code in cmd/ * ... * lint fixes * comment improvement * cli test fix * compile housing * working through compile errors * working gettin' compilin' * non-test code compiles * move testnet to its own module * reworking tests int * bez staging PR 1 comments * concise module function-of names * moved all tests from genesis_test.go to other genutil tests * genaccounts package, add genutil and genaccounts to app.go * docs for genutil genaccounts * genaccounts iterate fn * non-test code with genaccounts/ now compiles * working test compiling * debugging tests * resolved all make test compile errors * test debuggin * resolved all unit tests, introduced param module * cli-test compile fixes * staking initialization bug * code comment improvements, changelog entries * BasicGaiaApp -> ModuleBasics * highlevel explanation in types/module.go * @alexanderbez comment revisions * @fedekunze PR comments * @alexanderbez PR comments (x2) * @cwgoes comments (minor updates) * @fedekunze suggestions * panic on init with multiple validator updates from different modules * initchain panic makes validate genesis fail int * AppModuleGenesis seperation int * test * remove init panic logic in validate genesis replaced with TODO * set maxprocs to match system's GOMAXPROCS * Update circleci * Cap maxprocs in CI to 4 * @alexanderbez recent comments addressed * less blocks in twouble sims int * runsim error output flag * -e on import_export as well * error out int * Try to fix failures * runsim
2019-05-16 08:25:32 -07:00
package cli
import (
"testing"
"github.com/spf13/pflag"
"github.com/stretchr/testify/require"
2020-07-08 10:57:45 -07:00
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func TestPrepareConfigForTxCreateValidator(t *testing.T) {
chainID := "chainID"
ip := "1.1.1.1"
nodeID := "nodeID"
valPubKey, _ := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, "cosmosvalconspub1zcjduepq7jsrkl9fgqk0wj3ahmfr8pgxj6vakj2wzn656s8pehh0zhv2w5as5gd80a")
2020-07-08 10:57:45 -07:00
moniker := "DefaultMoniker"
tests := []struct {
name string
fsModify func(fs *pflag.FlagSet)
expectedCfg TxCreateValidatorConfig
}{
{
name: "all defaults",
fsModify: func(fs *pflag.FlagSet) {
return
},
expectedCfg: TxCreateValidatorConfig{
IP: ip,
ChainID: chainID,
NodeID: nodeID,
TrustNode: true,
PubKey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, valPubKey),
Moniker: moniker,
Amount: "100000000stake",
CommissionRate: "0.1",
CommissionMaxRate: "0.2",
CommissionMaxChangeRate: "0.01",
MinSelfDelegation: "1",
},
},
{
name: "Custom amount",
fsModify: func(fs *pflag.FlagSet) {
fs.Set(FlagAmount, "2000stake")
},
expectedCfg: TxCreateValidatorConfig{
IP: ip,
2020-07-08 10:57:45 -07:00
Moniker: moniker,
ChainID: chainID,
NodeID: nodeID,
TrustNode: true,
PubKey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, valPubKey),
Amount: "2000stake",
CommissionRate: "0.1",
CommissionMaxRate: "0.2",
CommissionMaxChangeRate: "0.01",
MinSelfDelegation: "1",
},
},
{
name: "Custom commission rate",
fsModify: func(fs *pflag.FlagSet) {
fs.Set(FlagCommissionRate, "0.54")
},
expectedCfg: TxCreateValidatorConfig{
IP: ip,
2020-07-08 10:57:45 -07:00
Moniker: moniker,
ChainID: chainID,
NodeID: nodeID,
TrustNode: true,
PubKey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, valPubKey),
Amount: "100000000stake",
CommissionRate: "0.54",
CommissionMaxRate: "0.2",
CommissionMaxChangeRate: "0.01",
MinSelfDelegation: "1",
},
},
{
name: "Custom commission max rate",
fsModify: func(fs *pflag.FlagSet) {
fs.Set(FlagCommissionMaxRate, "0.89")
},
expectedCfg: TxCreateValidatorConfig{
IP: ip,
2020-07-08 10:57:45 -07:00
Moniker: moniker,
ChainID: chainID,
NodeID: nodeID,
TrustNode: true,
PubKey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, valPubKey),
Amount: "100000000stake",
CommissionRate: "0.1",
CommissionMaxRate: "0.89",
CommissionMaxChangeRate: "0.01",
MinSelfDelegation: "1",
},
},
{
name: "Custom commission max change rate",
fsModify: func(fs *pflag.FlagSet) {
fs.Set(FlagCommissionMaxChangeRate, "0.55")
},
expectedCfg: TxCreateValidatorConfig{
IP: ip,
2020-07-08 10:57:45 -07:00
Moniker: moniker,
ChainID: chainID,
NodeID: nodeID,
TrustNode: true,
PubKey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, valPubKey),
Amount: "100000000stake",
CommissionRate: "0.1",
CommissionMaxRate: "0.2",
CommissionMaxChangeRate: "0.55",
MinSelfDelegation: "1",
},
},
{
name: "Custom min self delegations",
fsModify: func(fs *pflag.FlagSet) {
fs.Set(FlagMinSelfDelegation, "0.33")
},
expectedCfg: TxCreateValidatorConfig{
IP: ip,
2020-07-08 10:57:45 -07:00
Moniker: moniker,
ChainID: chainID,
NodeID: nodeID,
TrustNode: true,
PubKey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, valPubKey),
Amount: "100000000stake",
CommissionRate: "0.1",
CommissionMaxRate: "0.2",
CommissionMaxChangeRate: "0.01",
MinSelfDelegation: "0.33",
},
},
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
fs, _ := CreateValidatorMsgFlagSet(ip)
fs.String(flags.FlagName, "", "name of private key with which to sign the gentx")
tc.fsModify(fs)
2020-07-08 10:57:45 -07:00
cvCfg, err := PrepareConfigForTxCreateValidator(fs, moniker, nodeID, chainID, valPubKey)
require.NoError(t, err)
require.Equal(t, tc.expectedCfg, cvCfg)
})
}
}