Skip to content

Commit

Permalink
[api] Fix execution reverted message in eth_call (#4454)
Browse files Browse the repository at this point in the history
Co-authored-by: CoderZhi <thecoderzhi@gmail.com>
  • Loading branch information
envestcc and CoderZhi committed Oct 24, 2024
1 parent eec98a2 commit cd4a7fa
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
2 changes: 0 additions & 2 deletions api/coreservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,6 @@ func (core *coreService) ReadContract(ctx context.Context, callerAddr address.Ad
if err != nil {
return "", nil, status.Error(codes.Internal, err.Error())
}
// ReadContract() is read-only, if no error returned, we consider it a success
receipt.Status = uint64(iotextypes.ReceiptStatus_Success)
res := iotexapi.ReadContractResponse{
Data: hex.EncodeToString(retval),
Receipt: receipt.ConvertToReceiptPb(),
Expand Down
2 changes: 1 addition & 1 deletion api/grpcserver_integrity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@ func TestGrpcServer_ReadContractIntegrity(t *testing.T) {
res, err := grpcHandler.ReadContract(context.Background(), request)
require.NoError(err)
require.Equal(test.retValue, res.Data)
require.EqualValues(1, res.Receipt.Status)
require.EqualValues(0, res.Receipt.Status)
require.Equal(test.actionHash, hex.EncodeToString(res.Receipt.ActHash))
require.Equal(test.gasConsumed, res.Receipt.GasConsumed)
}
Expand Down
5 changes: 4 additions & 1 deletion api/web3server.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,10 @@ func (svr *web3Handler) call(in *gjson.Result) (interface{}, error) {
if err != nil {
return nil, err
}
if receipt != nil && len(receipt.GetExecutionRevertMsg()) > 0 {
if receipt != nil && receipt.Status == uint64(iotextypes.ReceiptStatus_ErrExecutionReverted) {
if len(receipt.GetExecutionRevertMsg()) == 0 {
return "0x" + ret, status.Error(codes.InvalidArgument, "execution reverted")
}
return "0x" + ret, status.Error(codes.InvalidArgument, "execution reverted: "+receipt.GetExecutionRevertMsg())
}
return "0x" + ret, nil
Expand Down
2 changes: 1 addition & 1 deletion api/web3server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func TestCall(t *testing.T) {

t.Run("revert call", func(t *testing.T) {
receipt := &iotextypes.Receipt{
Status: 0,
Status: uint64(iotextypes.ReceiptStatus_ErrExecutionReverted),
BlkHeight: 0,
ActHash: nil,
GasConsumed: 0,
Expand Down

0 comments on commit cd4a7fa

Please sign in to comment.