Skip to content

Commit

Permalink
Merge PR cosmos#5421: Refactor Error Handling
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez authored Dec 27, 2019
1 parent 083263b commit 419361d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
16 changes: 7 additions & 9 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func NewSimApp(
}

// init params keeper and subspaces
app.ParamsKeeper = params.NewKeeper(app.cdc, keys[params.StoreKey], tkeys[params.TStoreKey], params.DefaultCodespace)
app.ParamsKeeper = params.NewKeeper(app.cdc, keys[params.StoreKey], tkeys[params.TStoreKey])
app.subspaces[auth.ModuleName] = app.ParamsKeeper.Subspace(auth.DefaultParamspace)
app.subspaces[bank.ModuleName] = app.ParamsKeeper.Subspace(bank.DefaultParamspace)
app.subspaces[staking.ModuleName] = app.ParamsKeeper.Subspace(staking.DefaultParamspace)
Expand All @@ -174,25 +174,24 @@ func NewSimApp(
app.cdc, keys[auth.StoreKey], app.subspaces[auth.ModuleName], auth.ProtoBaseAccount,
)
app.BankKeeper = bank.NewBaseKeeper(
app.AccountKeeper, app.subspaces[bank.ModuleName], bank.DefaultCodespace,
app.BlacklistedAccAddrs(),
app.AccountKeeper, app.subspaces[bank.ModuleName], app.BlacklistedAccAddrs(),
)
app.SupplyKeeper = supply.NewKeeper(
app.cdc, keys[supply.StoreKey], app.AccountKeeper, app.BankKeeper, maccPerms,
)
stakingKeeper := staking.NewKeeper(
app.cdc, keys[staking.StoreKey], app.SupplyKeeper, app.subspaces[staking.ModuleName],
staking.DefaultCodespace)
)
app.MintKeeper = mint.NewKeeper(
app.cdc, keys[mint.StoreKey], app.subspaces[mint.ModuleName], &stakingKeeper,
app.SupplyKeeper, auth.FeeCollectorName,
)
app.DistrKeeper = distr.NewKeeper(
app.cdc, keys[distr.StoreKey], app.subspaces[distr.ModuleName], &stakingKeeper,
app.SupplyKeeper, distr.DefaultCodespace, auth.FeeCollectorName, app.ModuleAccountAddrs(),
app.SupplyKeeper, auth.FeeCollectorName, app.ModuleAccountAddrs(),
)
app.SlashingKeeper = slashing.NewKeeper(
app.cdc, keys[slashing.StoreKey], &stakingKeeper, app.subspaces[slashing.ModuleName], slashing.DefaultCodespace,
app.cdc, keys[slashing.StoreKey], &stakingKeeper, app.subspaces[slashing.ModuleName],
)
app.CrisisKeeper = crisis.NewKeeper(
app.subspaces[crisis.ModuleName], invCheckPeriod, app.SupplyKeeper, auth.FeeCollectorName,
Expand All @@ -201,8 +200,7 @@ func NewSimApp(

// create evidence keeper with router
evidenceKeeper := evidence.NewKeeper(
app.cdc, keys[evidence.StoreKey], app.subspaces[evidence.ModuleName], evidence.DefaultCodespace,
&app.StakingKeeper, app.SlashingKeeper,
app.cdc, keys[evidence.StoreKey], app.subspaces[evidence.ModuleName], &app.StakingKeeper, app.SlashingKeeper,
)
evidenceRouter := evidence.NewRouter()
// TODO: Register evidence routes.
Expand All @@ -217,7 +215,7 @@ func NewSimApp(
AddRoute(upgrade.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper))
app.GovKeeper = gov.NewKeeper(
app.cdc, keys[gov.StoreKey], app.subspaces[gov.ModuleName], app.SupplyKeeper,
&stakingKeeper, gov.DefaultCodespace, govRouter,
&stakingKeeper, govRouter,
)

// register the staking hooks
Expand Down
20 changes: 12 additions & 8 deletions test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func CheckBalance(t *testing.T, app *SimApp, addr sdk.AccAddress, exp sdk.Coins)
func SignCheckDeliver(
t *testing.T, cdc *codec.Codec, app *bam.BaseApp, header abci.Header, msgs []sdk.Msg,
accNums, seq []uint64, expSimPass, expPass bool, priv ...crypto.PrivKey,
) sdk.Result {
) (sdk.GasInfo, *sdk.Result, error) {

tx := helpers.GenTx(
msgs,
Expand All @@ -131,28 +131,32 @@ func SignCheckDeliver(
require.Nil(t, err)

// Must simulate now as CheckTx doesn't run Msgs anymore
res := app.Simulate(txBytes, tx)
_, res, err := app.Simulate(txBytes, tx)

if expSimPass {
require.Equal(t, sdk.CodeOK, res.Code, res.Log)
require.NoError(t, err)
require.NotNil(t, res)
} else {
require.NotEqual(t, sdk.CodeOK, res.Code, res.Log)
require.Error(t, err)
require.Nil(t, res)
}

// Simulate a sending a transaction and committing a block
app.BeginBlock(abci.RequestBeginBlock{Header: header})
res = app.Deliver(tx)
gInfo, res, err := app.Deliver(tx)

if expPass {
require.Equal(t, sdk.CodeOK, res.Code, res.Log)
require.NoError(t, err)
require.NotNil(t, res)
} else {
require.NotEqual(t, sdk.CodeOK, res.Code, res.Log)
require.Error(t, err)
require.Nil(t, res)
}

app.EndBlock(abci.RequestEndBlock{})
app.Commit()

return res
return gInfo, res, err
}

// GenSequenceOfTxs generates a set of signed transactions of messages, such
Expand Down

0 comments on commit 419361d

Please sign in to comment.