diff --git a/CHANGELOG.md b/CHANGELOG.md index ae7dc612c24f..e309d113bbab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* [\#11693](https://github.com/cosmos/cosmos-sdk/pull/11693) Add validation for gentx cmd. * [\#11686](https://github.com/cosmos/cosmos-sdk/pull/11686) Update the min required Golang version to `1.17`. * (x/auth/vesting) [\#11652](https://github.com/cosmos/cosmos-sdk/pull/11652) Add util functions for `Period(s)` diff --git a/x/genutil/client/cli/gentx.go b/x/genutil/client/cli/gentx.go index 79e8be4df73a..8d7e7491a626 100644 --- a/x/genutil/client/cli/gentx.go +++ b/x/genutil/client/cli/gentx.go @@ -168,6 +168,10 @@ $ %s gentx my-key-name 1000000stake --home=/path/to/home/dir --keyring-backend=o w := bytes.NewBuffer([]byte{}) clientCtx = clientCtx.WithOutput(w) + if err = msg.ValidateBasic(); err != nil { + return err + } + if err = authclient.PrintUnsignedStdTx(txBldr, clientCtx, []sdk.Msg{msg}); err != nil { return errors.Wrap(err, "failed to print unsigned std tx") } diff --git a/x/genutil/gentx_test.go b/x/genutil/gentx_test.go index 10721c819e12..a38e83551a26 100644 --- a/x/genutil/gentx_test.go +++ b/x/genutil/gentx_test.go @@ -77,29 +77,14 @@ func (suite *GenTxTestSuite) SetupTest() { suite.NoError(err) } -func (suite *GenTxTestSuite) setAccountBalance(balances []banktypes.Balance) json.RawMessage { - bankGenesisState := banktypes.GenesisState{ - Params: banktypes.Params{DefaultSendEnabled: true}, - Balances: []banktypes.Balance{ - { - Address: "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh", - Coins: sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 1000000)}, - }, - { - Address: "cosmos1jv65s3grqf6v6jl3dp4t6c9t9rk99cd88lyufl", - Coins: sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 2059726)}, - }, - { - Address: "cosmos1k5lndq46x9xpejdxq52q3ql3ycrphg4qxlfqn7", - Coins: sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 100000000000000)}, - }, - }, - Supply: sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)}, - } - bankGenesisState.Balances = append(bankGenesisState.Balances, balances...) - for _, balance := range bankGenesisState.Balances { - bankGenesisState.Supply.Add(balance.Coins...) - } +func (suite *GenTxTestSuite) setAccountBalance(addr sdk.AccAddress, amount int64) json.RawMessage { + acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, addr) + suite.app.AccountKeeper.SetAccount(suite.ctx, acc) + + err := simapp.FundAccount(suite.app.BankKeeper, suite.ctx, addr, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, amount)}) + suite.Require().NoError(err) + + bankGenesisState := suite.app.BankKeeper.ExportGenesis(suite.ctx) bankGenesis, err := suite.encodingConfig.Amino.MarshalJSON(bankGenesisState) // TODO switch this to use Marshaler suite.Require().NoError(err) @@ -283,10 +268,11 @@ func (suite *GenTxTestSuite) TestDeliverGenTxs() { { "success", func() { - r := rand.New(rand.NewSource(time.Now().UnixNano())) - msg := banktypes.NewMsgSend(addr1Str, addr2Str, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 1)}) - tx, err := simtestutil.GenSignedMockTx( - r, + _ = suite.setAccountBalance(addr1, 50) + _ = suite.setAccountBalance(addr2, 1) + + msg := banktypes.NewMsgSend(addr1, addr2, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 1)}) + tx, err := helpers.GenTx( suite.encodingConfig.TxConfig, []sdk.Msg{msg}, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 10)},