baseapp: add sdk.Result to simulation response

This commit is contained in:
Federico Kunze 2020-03-19 20:03:49 -03:00
parent 230a1e8ba3
commit eeea5ebf89
No known key found for this signature in database
GPG Key ID: 655F93A970080A30
4 changed files with 26 additions and 6 deletions

View File

@ -70,6 +70,8 @@ to now accept a `codec.JSONMarshaler` for modular serialization of genesis state
* (crypto/keys) [\#5735](https://github.com/cosmos/cosmos-sdk/pull/5735) Keyring's Update() function is now no-op.
* (types/rest) [\#5779](https://github.com/cosmos/cosmos-sdk/pull/5779) Drop unused Parse{Int64OrReturnBadRequest,QueryParamBool}() functions.
* (keys) [\#5820](https://github.com/cosmos/cosmos-sdk/pull/5820/) Removed method CloseDB from Keybase interface.
* (baseapp) [\#5837](https://github.com/cosmos/cosmos-sdk/issues/5837) Transaction simulation now returns a `SimulationResponse` which contains the `GasInfo` and
`Result` from the execution.
### Features

View File

@ -326,12 +326,20 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) abci.Res
return sdkerrors.QueryResult(sdkerrors.Wrap(err, "failed to decode tx"))
}
gInfo, _, _ := app.Simulate(txBytes, tx)
gInfo, res, err := app.Simulate(txBytes, tx)
if err != nil {
return sdkerrors.QueryResult(sdkerrors.Wrap(err, "failed to simulate tx"))
}
simRes := sdk.SimulationResponse{
GasInfo: gInfo,
Result: res,
}
return abci.ResponseQuery{
Codespace: sdkerrors.RootCodespace,
Height: req.Height,
Value: codec.Cdc.MustMarshalBinaryBare(gInfo.GasUsed),
Value: codec.Cdc.MustMarshalBinaryBare(simRes),
}
case "version":

View File

@ -935,10 +935,13 @@ func TestSimulateTx(t *testing.T) {
queryResult := app.Query(query)
require.True(t, queryResult.IsOK(), queryResult.Log)
var res uint64
err = codec.Cdc.UnmarshalBinaryBare(queryResult.Value, &res)
var simRes sdk.SimulationResponse
err = codec.Cdc.UnmarshalBinaryBare(queryResult.Value, &simRes)
require.NoError(t, err)
require.Equal(t, gasConsumed, res)
require.Equal(t, gInfo, simRes.GasInfo)
require.Equal(t, result.Log, simRes.Result.Log)
require.Equal(t, result.Events, simRes.Result.Events)
require.True(t, bytes.Equal(result.Data, simRes.Result.Data))
app.EndBlock(abci.RequestEndBlock{})
app.Commit()
}

View File

@ -17,7 +17,7 @@ type GasInfo struct {
// GasWanted is the maximum units of work we allow this tx to perform.
GasWanted uint64
// GasUsed is the amount of gas actually consumed. NOTE: unimplemented
// GasUsed is the amount of gas actually consumed.
GasUsed uint64
}
@ -35,6 +35,13 @@ type Result struct {
Events Events
}
// SimulationResponse defines the response generated when a transaction is successfully
// simulated by the Baseapp.
type SimulationResponse struct {
GasInfo
Result *Result
}
// ABCIMessageLogs represents a slice of ABCIMessageLog.
type ABCIMessageLogs []ABCIMessageLog