Skip to content

Commit

Permalink
Fix LegacySimulateTransactions not returning correct error on reverte…
Browse files Browse the repository at this point in the history
…d txns (#1535)
  • Loading branch information
omerfirmak authored and wojciechos committed Dec 11, 2023
1 parent 3ec3bce commit e36f846
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion rpc/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,11 @@ func (h *Handler) SimulateTransactions(id BlockID, transactions []BroadcastedTra
func (h *Handler) LegacySimulateTransactions(id BlockID, transactions []BroadcastedTransaction,
simulationFlags []SimulationFlag,
) ([]SimulatedTransaction, *jsonrpc.Error) {
return h.simulateTransactions(id, transactions, simulationFlags, true, false)
res, err := h.simulateTransactions(id, transactions, simulationFlags, true, true)
if err != nil && err.Code == ErrTransactionExecutionError.Code {
return nil, makeContractError(errors.New(err.Data.(TransactionExecutionErrorData).ExecutionError))
}
return res, err
}

func (h *Handler) simulateTransactions(id BlockID, transactions []BroadcastedTransaction, //nolint: gocyclo
Expand Down
11 changes: 11 additions & 0 deletions rpc/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3230,6 +3230,17 @@ func TestSimulateTransactions(t *testing.T) {
TransactionIndex: 44,
ExecutionError: "oops",
}), err)

mockVM.EXPECT().Execute(nil, nil, uint64(0), uint64(0), sequencerAddress, mockState, network, []*felt.Felt{}, false, true, true, nil, nil, true).
Return(nil, nil, vm.TransactionExecutionError{
Index: 44,
Cause: errors.New("oops"),
})

_, err = handler.LegacySimulateTransactions(rpc.BlockID{Latest: true}, []rpc.BroadcastedTransaction{}, []rpc.SimulationFlag{rpc.SkipValidateFlag})
require.Equal(t, rpc.ErrContractError.CloneWithData(rpc.ContractErrorData{
RevertError: "oops",
}), err)
})
}

Expand Down

0 comments on commit e36f846

Please sign in to comment.