Skip to content

Commit

Permalink
feat: add GenSignedMockTx (cosmos#13557)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Oct 16, 2022
1 parent 6f309d2 commit 0622dd4
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 50 deletions.
72 changes: 39 additions & 33 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,22 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

### Features

* [#13557](https://github.com/cosmos/cosmos-sdk/pull/#13557) - Add `GenSignedMockTx`. This can be used as workaround for #12437 revertion. `v0.46+` contains as well a `GenSignedMockTx` that behaves the same way.

## v0.45.9 - 2022-10-14

ATTENTION:

This is a security release for the
[Dragonberry security advisory](https://forum.cosmos.network/t/ibc-security-advisory-dragonberry/7702).
This is a security release for the [Dragonberry security advisory](https://forum.cosmos.network/t/ibc-security-advisory-dragonberry/7702).

All users should upgrade immediately.

Users *must* add a replace directive in their go.mod for the
new `ics23` package in the SDK:

```
replace (
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23
)
Users *must* add a replace directive in their go.mod for thenew `ics23` package in the SDK:

```go
replace github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
```

### Features
Expand All @@ -66,18 +65,22 @@ replace (
* [#13323](https://github.com/cosmos/cosmos-sdk/pull/13323) Ensure `withdraw_rewards` rewards are emitted from all actions that result in rewards being withdrawn.
* [#13321](https://github.com/cosmos/cosmos-sdk/pull/13321) Add flag to disable fast node migration and usage.
* (store) [#13326](https://github.com/cosmos/cosmos-sdk/pull/13326) Implementation of ADR-038 file StreamingService, backport #8664.
* (store) [#13540](https://github.com/cosmos/cosmos-sdk/pull/13540) Default fastnode migration to false to prevent suprises. Operators must enable it, unless they have it enabled already.
* (store) [#13540](https://github.com/cosmos/cosmos-sdk/pull/13540) Default fastnode migration to false to prevent suprises. Operators must enable it, unless they have it enabled already.

### API Breaking Changes

* (cli) [#13089](https://github.com/cosmos/cosmos-sdk/pull/13089) Fix rollback command don't actually delete multistore versions, added method `RollbackToVersion` to interface `CommitMultiStore` and added method `CommitMultiStore` to `Application` interface.

### Bug Fixes

* [#...](https://github.com/cosmos/cosmos-sdk/pull/) Implement dragonberry security patch.
* For applying the patch please refer to the [RELEASE NOTES](./RELEASE_NOTES.md)
* Implement dragonberry security patch.
* For applying the patch please refer to the [RELEASE NOTES](./RELEASE_NOTES.md)
* (store) [#13459](https://github.com/cosmos/cosmos-sdk/pull/13459) Don't let state listener observe the uncommitted writes.

### Notes

Reverted #12437 due to API breaking changes.

## v0.45.8 - 2022-08-25

### Improvements
Expand Down Expand Up @@ -112,6 +115,9 @@ replace (
### Bug Fixes

* (x/mint) [#12384](https://github.com/cosmos/cosmos-sdk/pull/12384) Ensure `GoalBonded` must be positive when performing `x/mint` parameter validation.
* (simapp) [#12437](https://github.com/cosmos/cosmos-sdk/pull/12437) fix the non-determinstic behavior in simulations caused by `GenTx` and check
empty coins slice before it is used to create `banktype.MsgSend`.
* (x/capability) [#12818](https://github.com/cosmos/cosmos-sdk/pull/12818) Use fixed length hex for pointer at FwdCapabilityKey.

## [v0.45.6](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.45.6) - 2022-06-28

Expand Down Expand Up @@ -278,7 +284,7 @@ replace (

### Improvements

* (types) [\#10630](https://github.com/cosmos/cosmos-sdk/pull/10630) Add an `Events` field to the `TxResponse` type that captures _all_ events emitted by a transaction, unlike `Logs` which only contains events emitted during message execution.
* (types) [\#10630](https://github.com/cosmos/cosmos-sdk/pull/10630) Add an `Events` field to the `TxResponse` type that captures *all* events emitted by a transaction, unlike `Logs` which only contains events emitted during message execution.
* (x/upgrade) [\#10532](https://github.com/cosmos/cosmos-sdk/pull/10532) Add `keeper.DumpUpgradeInfoWithInfoToDisk` to include `Plan.Info` in the upgrade-info file.
* (store) [\#10544](https://github.com/cosmos/cosmos-sdk/pull/10544) Use the new IAVL iterator structure which significantly improves iterator performance.

Expand Down Expand Up @@ -1288,7 +1294,7 @@ by the new key store:
* `file`: use encrypted file-based store.
* `kwallet`: use [KDE Wallet](https://utils.kde.org/projects/kwalletmanager/) service.
* `pass`: use the [pass](https://www.passwordstore.org/) command line password manager.
* `test`: use password-less key store. _For testing purposes only. Use it at your own risk._
* `test`: use password-less key store. *For testing purposes only. Use it at your own risk.*
* (keys) [\#5097](https://github.com/cosmos/cosmos-sdk/pull/5097) New `keys migrate` command to assist users migrate their keys
to the new keyring.
* (keys) [\#5366](https://github.com/cosmos/cosmos-sdk/pull/5366) `keys list` now accepts a `--list-names` option to list key names only, whilst the `keys delete`
Expand Down Expand Up @@ -2782,7 +2788,7 @@ BUG FIXES

## 0.25.0

_October 24th, 2018_
*October 24th, 2018*

BREAKING CHANGES

Expand Down Expand Up @@ -3029,7 +3035,7 @@ BUG FIXES
## 0.24.2
_August 22nd, 2018_
*August 22nd, 2018*
BUG FIXES
Expand All @@ -3038,7 +3044,7 @@ BUG FIXES
## 0.24.1
_August 21st, 2018_
*August 21st, 2018*
BUG FIXES
Expand All @@ -3047,7 +3053,7 @@ BUG FIXES
## 0.24.0
_August 13th, 2018_
*August 13th, 2018*
BREAKING CHANGES
Expand Down Expand Up @@ -3163,7 +3169,7 @@ BUG FIXES

## 0.23.1

_July 27th, 2018_
*July 27th, 2018*

BUG FIXES

Expand All @@ -3173,7 +3179,7 @@ BUG FIXES

## 0.23.0

_July 25th, 2018_
*July 25th, 2018*

BREAKING CHANGES

Expand All @@ -3196,7 +3202,7 @@ BUG FIXES
## 0.22.0
_July 16th, 2018_
*July 16th, 2018*
BREAKING CHANGES
Expand All @@ -3215,7 +3221,7 @@ BUG FIXES
## 0.21.1
_July 14th, 2018_
*July 14th, 2018*
BUG FIXES
Expand All @@ -3224,7 +3230,7 @@ BUG FIXES
## 0.21.0
_July 13th, 2018_
*July 13th, 2018*
BREAKING CHANGES
Expand Down Expand Up @@ -3255,7 +3261,7 @@ BUG FIXES
## 0.20.0
_July 10th, 2018_
*July 10th, 2018*
BREAKING CHANGES
Expand Down Expand Up @@ -3398,7 +3404,7 @@ BUG FIXES

## 0.19.0

_June 13, 2018_
*June 13, 2018*

BREAKING CHANGES

Expand Down Expand Up @@ -3438,7 +3444,7 @@ FEATURES
## 0.18.0
_June 9, 2018_
*June 9, 2018*
BREAKING CHANGES
Expand Down Expand Up @@ -3503,45 +3509,45 @@ BUG FIXES
## 0.17.5
_June 5, 2018_
*June 5, 2018*
Update to Tendermint v0.19.9 (Fix evidence reactor, mempool deadlock, WAL panic,
memory leak)
## 0.17.4
_May 31, 2018_
*May 31, 2018*
Update to Tendermint v0.19.7 (WAL fixes and more)
## 0.17.3
_May 29, 2018_
*May 29, 2018*
Update to Tendermint v0.19.6 (fix fast-sync halt)
## 0.17.5
_June 5, 2018_
*June 5, 2018*
Update to Tendermint v0.19.9 (Fix evidence reactor, mempool deadlock, WAL panic,
memory leak)
## 0.17.4
_May 31, 2018_
*May 31, 2018*
Update to Tendermint v0.19.7 (WAL fixes and more)
## 0.17.3
_May 29, 2018_
*May 29, 2018*
Update to Tendermint v0.19.6 (fix fast-sync halt)
## 0.17.2
_May 20, 2018_
*May 20, 2018*
Update to Tendermint v0.19.5 (reduce WAL use, bound the mempool and some rpcs, improve logging)
Expand Down
5 changes: 2 additions & 3 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# Cosmos SDK v0.45.9 Release Notes

This is a security release for the
[Dragonberry security advisory](https://forum.cosmos.network/t/ibc-security-advisory-dragonberry/7702).
This is a security release for the [Dragonberry security advisory](https://forum.cosmos.network/t/ibc-security-advisory-dragonberry/7702).
Please upgrade ASAP.

Next to this, we have also included a few minor bugfixes.

Chains must add the following to their go.mod for the application:

```go
replace github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23
replace github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23 v0.8.0
```

Bumping the SDK version should be smooth, however, feel free to tag core devs to review your upgrading PR:
Expand Down
9 changes: 6 additions & 3 deletions simapp/helpers/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ const (

// GenTx generates a signed mock transaction.
func GenTx(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accNums, accSeqs []uint64, priv ...cryptotypes.PrivKey) (sdk.Tx, error) {
sigs := make([]signing.SignatureV2, len(priv))

// create a random length memo
r := rand.New(rand.NewSource(time.Now().UnixNano()))
return GenSignedMockTx(r, gen, msgs, feeAmt, gas, chainID, accNums, accSeqs, priv...)
}

// GenSignedMockTx generates a signed mock transaction.
func GenSignedMockTx(r *rand.Rand, gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accNums, accSeqs []uint64, priv ...cryptotypes.PrivKey) (sdk.Tx, error) {
sigs := make([]signing.SignatureV2, len(priv))

memo := simulation.RandStringOfLength(r, simulation.RandIntBetween(r, 0, 100))

Expand Down
7 changes: 5 additions & 2 deletions simapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"math/rand"
"strconv"
"testing"
"time"
Expand Down Expand Up @@ -325,7 +326,8 @@ func SignCheckDeliver(
t *testing.T, txCfg client.TxConfig, app *bam.BaseApp, header tmproto.Header, msgs []sdk.Msg,
chainID string, accNums, accSeqs []uint64, expSimPass, expPass bool, priv ...cryptotypes.PrivKey,
) (sdk.GasInfo, *sdk.Result, error) {
tx, err := helpers.GenTx(
tx, err := helpers.GenSignedMockTx(
rand.New(rand.NewSource(time.Now().UnixNano())),
txCfg,
msgs,
sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)},
Expand Down Expand Up @@ -375,7 +377,8 @@ func GenSequenceOfTxs(txGen client.TxConfig, msgs []sdk.Msg, accNums []uint64, i
txs := make([]sdk.Tx, numToGenerate)
var err error
for i := 0; i < numToGenerate; i++ {
txs[i], err = helpers.GenTx(
txs[i], err = helpers.GenSignedMockTx(
rand.New(rand.NewSource(time.Now().UnixNano())),
txGen,
msgs,
sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)},
Expand Down
13 changes: 10 additions & 3 deletions x/authz/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ func SimulateMsgGrant(ak authz.AccountKeeper, bk authz.BankKeeper, _ keeper.Keep
return simtypes.NoOpMsg(authz.ModuleName, TypeMsgGrant, err.Error()), nil, err
}
txCfg := simappparams.MakeTestEncodingConfig().TxConfig
tx, err := helpers.GenTx(
tx, err := helpers.GenSignedMockTx(
r,
txCfg,
[]sdk.Msg{msg},
fees,
Expand Down Expand Up @@ -182,7 +183,8 @@ func SimulateMsgRevoke(ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Kee
msg := authz.NewMsgRevoke(granterAddr, granteeAddr, a.MsgTypeURL())
txCfg := simappparams.MakeTestEncodingConfig().TxConfig
account := ak.GetAccount(ctx, granterAddr)
tx, err := helpers.GenTx(
tx, err := helpers.GenSignedMockTx(
r,
txCfg,
[]sdk.Msg{&msg},
fees,
Expand Down Expand Up @@ -241,6 +243,10 @@ func SimulateMsgExec(ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keepe

granterspendableCoins := bk.SpendableCoins(ctx, granterAddr)
coins := simtypes.RandSubsetCoins(r, granterspendableCoins)
// if coins slice is empty, we can not create valid banktype.MsgSend
if len(coins) == 0 {
return simtypes.NoOpMsg(authz.ModuleName, TypeMsgExec, "empty coins slice"), nil, nil
}
// Check send_enabled status of each sent coin denom
if err := bk.IsSendEnabledCoins(ctx, coins...); err != nil {
return simtypes.NoOpMsg(authz.ModuleName, TypeMsgExec, err.Error()), nil, nil
Expand Down Expand Up @@ -272,7 +278,8 @@ func SimulateMsgExec(ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keepe

txCfg := simappparams.MakeTestEncodingConfig().TxConfig
granteeAcc := ak.GetAccount(ctx, granteeAddr)
tx, err := helpers.GenTx(
tx, err := helpers.GenSignedMockTx(
r,
txCfg,
[]sdk.Msg{&msgExec},
fees,
Expand Down
14 changes: 12 additions & 2 deletions x/bank/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ func SimulateMsgSend(ak types.AccountKeeper, bk keeper.Keeper) simtypes.Operatio
accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
from, to, coins, skip := randomSendFields(r, ctx, accs, bk, ak)
// if coins slice is empty, we can not create valid types.MsgSend
if len(coins) == 0 {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSend, "empty coins slice"), nil, nil
}

// Check send_enabled status of each coin denom
if err := bk.IsSendEnabledCoins(ctx, coins...); err != nil {
Expand Down Expand Up @@ -93,6 +97,10 @@ func SimulateMsgSendToModuleAccount(ak types.AccountKeeper, bk keeper.Keeper, mo

spendable := bk.SpendableCoins(ctx, from.Address)
coins := simtypes.RandSubsetCoins(r, spendable)
// if coins slice is empty, we can not create valid types.MsgSend
if len(coins) == 0 {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSend, "empty coins slice"), nil, nil
}

// Check send_enabled status of each coin denom
if err := bk.IsSendEnabledCoins(ctx, coins...); err != nil {
Expand Down Expand Up @@ -136,7 +144,8 @@ func sendMsgSend(
}
}
txGen := simappparams.MakeTestEncodingConfig().TxConfig
tx, err := helpers.GenTx(
tx, err := helpers.GenSignedMockTx(
r,
txGen,
[]sdk.Msg{msg},
fees,
Expand Down Expand Up @@ -349,7 +358,8 @@ func sendMsgMultiSend(
}

txGen := simappparams.MakeTestEncodingConfig().TxConfig
tx, err := helpers.GenTx(
tx, err := helpers.GenSignedMockTx(
r,
txGen,
[]sdk.Msg{msg},
fees,
Expand Down
Loading

0 comments on commit 0622dd4

Please sign in to comment.