From e36f8468b7d3e6cd6ed590a3e77d2e90f75a26dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Irmak?= Date: Fri, 8 Dec 2023 18:38:49 +0300 Subject: [PATCH] Fix LegacySimulateTransactions not returning correct error on reverted txns (#1535) --- rpc/handlers.go | 6 +++++- rpc/handlers_test.go | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/rpc/handlers.go b/rpc/handlers.go index 6885f69b5a..ab2f65d795 100644 --- a/rpc/handlers.go +++ b/rpc/handlers.go @@ -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 diff --git a/rpc/handlers_test.go b/rpc/handlers_test.go index f6d017e236..d788495ea1 100644 --- a/rpc/handlers_test.go +++ b/rpc/handlers_test.go @@ -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) }) }