Skip to content

Commit

Permalink
imp!: allow failure expectations when using chain.SendMsgs (cosmos#4018)
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan authored Jul 5, 2023
1 parent dbfb293 commit 1fda14d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
3 changes: 1 addition & 2 deletions testing/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,13 @@ func (chain *TestChain) SendMsgs(msgs ...sdk.Msg) (*sdk.Result, error) {
chain.Coordinator.UpdateTimeForChain(chain)

_, r, err := simapp.SignAndDeliver(
chain.TB,
chain.TxConfig,
chain.App.GetBaseApp(),
msgs,
chain.ChainID,
[]uint64{chain.SenderAccount.GetAccountNumber()},
[]uint64{chain.SenderAccount.GetSequence()},
true, chain.SenderPrivKey,
chain.SenderPrivKey,
)
if err != nil {
return nil, err
Expand Down
20 changes: 5 additions & 15 deletions testing/simapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,9 @@ func SetupWithGenesisAccounts(genAccs []authtypes.GenesisAccount, balances ...ba
//
// CONTRACT: BeginBlock must be called before this function.
func SignAndDeliver(
tb testing.TB, txCfg client.TxConfig, app *bam.BaseApp, msgs []sdk.Msg,
chainID string, accNums, accSeqs []uint64, expPass bool, priv ...cryptotypes.PrivKey,
txCfg client.TxConfig, app *bam.BaseApp, msgs []sdk.Msg,
chainID string, accNums, accSeqs []uint64, priv ...cryptotypes.PrivKey,
) (sdk.GasInfo, *sdk.Result, error) {
tb.Helper()
tx, err := simtestutil.GenSignedMockTx(
rand.New(rand.NewSource(time.Now().UnixNano())),
txCfg,
Expand All @@ -166,18 +165,9 @@ func SignAndDeliver(
accSeqs,
priv...,
)
require.NoError(tb, err)

// Simulate a sending a transaction
gInfo, res, err := app.SimDeliver(txCfg.TxEncoder(), tx)

if expPass {
require.NoError(tb, err)
require.NotNil(tb, res)
} else {
require.Error(tb, err)
require.Nil(tb, res)
if err != nil {
return sdk.GasInfo{}, nil, err
}

return gInfo, res, err
return app.SimDeliver(txCfg.TxEncoder(), tx)
}

0 comments on commit 1fda14d

Please sign in to comment.