Skip to content

Commit

Permalink
fix: Add validation on create gentx (backport cosmos#11693) (cosmos#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored and JeancarloBarrios committed Sep 28, 2024
1 parent 6de5884 commit c468d12
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)`

Expand Down
4 changes: 4 additions & 0 deletions x/genutil/client/cli/gentx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
40 changes: 13 additions & 27 deletions x/genutil/gentx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)},
Expand Down

0 comments on commit c468d12

Please sign in to comment.