diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b505678d5..4f008aaec1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/baseapp/abci.go b/baseapp/abci.go index 834930196d..e984fe0edf 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -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": diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 2350ba64ce..2da5b95f6f 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -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() } diff --git a/types/result.go b/types/result.go index 9530be01d2..54cc0e0533 100644 --- a/types/result.go +++ b/types/result.go @@ -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