From 2e055c33869c2efe09f8ca34bd4bcc10a88186ee Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 31 Oct 2022 15:45:02 +0000 Subject: [PATCH] del unfinished tx_test.go --- x/ccv/provider/client/cli/tx_test.go | 223 --------------------------- 1 file changed, 223 deletions(-) delete mode 100644 x/ccv/provider/client/cli/tx_test.go diff --git a/x/ccv/provider/client/cli/tx_test.go b/x/ccv/provider/client/cli/tx_test.go deleted file mode 100644 index 3a430771a0..0000000000 --- a/x/ccv/provider/client/cli/tx_test.go +++ /dev/null @@ -1,223 +0,0 @@ -package cli - -import ( - "fmt" - "os" - "testing" - - "github.com/spf13/pflag" - "github.com/stretchr/testify/require" - - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - flag "github.com/spf13/pflag" -) - -// Return the flagset, particular flags, and a description of defaults -// this is anticipated to be used with the gen-tx -func CreateDesignateConsensusKeyForConsumerChainMsgFlagSet(ipDefault string) *flag.FlagSet { - fsCreateValidator := flag.NewFlagSet("", flag.ContinueOnError) - fsCreateValidator.String(FlagIP, ipDefault, "The node's public IP") - fsCreateValidator.String(FlagNodeID, "", "The node's NodeID") - fsCreateValidator.AddFlagSet(FlagSetPublicKey()) - return fsCreateValidator -} - -type TxCreateValidatorConfig struct { - ChainID string - NodeID string - Moniker string - - Amount string - - CommissionRate string - CommissionMaxRate string - CommissionMaxChangeRate string - MinSelfDelegation string - - PubKey cryptotypes.PubKey - - IP string - Website string - SecurityContact string - Details string - Identity string -} - -func PrepareConfigForTxCreateValidator(flagSet *flag.FlagSet, moniker, nodeID, chainID string, valPubKey cryptotypes.PubKey) (TxCreateValidatorConfig, error) { - c := TxCreateValidatorConfig{} - - ip, err := flagSet.GetString(FlagIP) - if err != nil { - return c, err - } - if ip == "" { - _, _ = fmt.Fprintf(os.Stderr, "couldn't retrieve an external IP; "+ - "the tx's memo field will be unset") - } - c.IP = ip - - website, err := flagSet.GetString(FlagWebsite) - if err != nil { - return c, err - } - c.Website = website - - securityContact, err := flagSet.GetString(FlagSecurityContact) - if err != nil { - return c, err - } - c.SecurityContact = securityContact - - details, err := flagSet.GetString(FlagDetails) - if err != nil { - return c, err - } - c.SecurityContact = details - - identity, err := flagSet.GetString(FlagIdentity) - if err != nil { - return c, err - } - c.Identity = identity - - c.Amount, err = flagSet.GetString(FlagAmount) - if err != nil { - return c, err - } - - c.CommissionRate, err = flagSet.GetString(FlagCommissionRate) - if err != nil { - return c, err - } - - c.CommissionMaxRate, err = flagSet.GetString(FlagCommissionMaxRate) - if err != nil { - return c, err - } - - c.CommissionMaxChangeRate, err = flagSet.GetString(FlagCommissionMaxChangeRate) - if err != nil { - return c, err - } - - c.MinSelfDelegation, err = flagSet.GetString(FlagMinSelfDelegation) - if err != nil { - return c, err - } - - c.NodeID = nodeID - c.PubKey = valPubKey - c.Website = website - c.SecurityContact = securityContact - c.Details = details - c.Identity = identity - c.ChainID = chainID - c.Moniker = moniker - - if c.Amount == "" { - c.Amount = defaultAmount - } - - if c.CommissionRate == "" { - c.CommissionRate = defaultCommissionRate - } - - if c.CommissionMaxRate == "" { - c.CommissionMaxRate = defaultCommissionMaxRate - } - - if c.CommissionMaxChangeRate == "" { - c.CommissionMaxChangeRate = defaultCommissionMaxChangeRate - } - - if c.MinSelfDelegation == "" { - c.MinSelfDelegation = defaultMinSelfDelegation - } - - return c, nil -} - -func TestPrepareConfigForTxCreateValidator(t *testing.T) { - chainID := "chainID" - ip := "1.1.1.1" - nodeID := "nodeID" - privKey := ed25519.GenPrivKey() - valPubKey := privKey.PubKey() - moniker := "DefaultMoniker" - mkTxValCfg := func(amount, commission, commissionMax, commissionMaxChange, minSelfDelegation string) TxCreateValidatorConfig { - return TxC{ - IP: ip, - ChainID: chainID, - NodeID: nodeID, - PubKey: valPubKey, - Moniker: moniker, - Amount: amount, - CommissionRate: commission, - CommissionMaxRate: commissionMax, - CommissionMaxChangeRate: commissionMaxChange, - MinSelfDelegation: minSelfDelegation, - } - } - - tests := []struct { - name string - fsModify func(fs *pflag.FlagSet) - expectedCfg TxCreateValidatorConfig - }{ - { - name: "all defaults", - fsModify: func(fs *pflag.FlagSet) { - return - }, - expectedCfg: mkTxValCfg(defaultAmount, "0.1", "0.2", "0.01", "1"), - }, { - name: "Custom amount", - fsModify: func(fs *pflag.FlagSet) { - fs.Set(FlagAmount, "2000stake") - }, - expectedCfg: mkTxValCfg("2000stake", "0.1", "0.2", "0.01", "1"), - }, { - name: "Custom commission rate", - fsModify: func(fs *pflag.FlagSet) { - fs.Set(FlagCommissionRate, "0.54") - }, - expectedCfg: mkTxValCfg(defaultAmount, "0.54", "0.2", "0.01", "1"), - }, { - name: "Custom commission max rate", - fsModify: func(fs *pflag.FlagSet) { - fs.Set(FlagCommissionMaxRate, "0.89") - }, - expectedCfg: mkTxValCfg(defaultAmount, "0.1", "0.89", "0.01", "1"), - }, { - name: "Custom commission max change rate", - fsModify: func(fs *pflag.FlagSet) { - fs.Set(FlagCommissionMaxChangeRate, "0.55") - }, - expectedCfg: mkTxValCfg(defaultAmount, "0.1", "0.2", "0.55", "1"), - }, - { - name: "Custom min self delegations", - fsModify: func(fs *pflag.FlagSet) { - fs.Set(FlagMinSelfDelegation, "0.33") - }, - expectedCfg: mkTxValCfg(defaultAmount, "0.1", "0.2", "0.01", "0.33"), - }, - } - - for _, tc := range tests { - tc := tc - t.Run(tc.name, func(t *testing.T) { - fs := CreateDesignateConsensusKeyForConsumerChainMsgFlagSet(ip) - fs.String(flags.FlagName, "", "name of private key with which to sign the gentx") - - tc.fsModify(fs) - - cvCfg, err := PrepareConfigForTxCreateValidator(fs, moniker, nodeID, chainID, valPubKey) - require.NoError(t, err) - - require.Equal(t, tc.expectedCfg, cvCfg) - }) - } -}