diff --git a/api/coreservice.go b/api/coreservice.go index 21d4a66fde..97f8ec2f82 100644 --- a/api/coreservice.go +++ b/api/coreservice.go @@ -561,8 +561,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(), diff --git a/api/grpcserver_integrity_test.go b/api/grpcserver_integrity_test.go index b3222859e7..b415ac9783 100644 --- a/api/grpcserver_integrity_test.go +++ b/api/grpcserver_integrity_test.go @@ -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) } diff --git a/api/web3server.go b/api/web3server.go index 8a46f6cfb6..f920cc31c9 100644 --- a/api/web3server.go +++ b/api/web3server.go @@ -425,7 +425,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 diff --git a/api/web3server_test.go b/api/web3server_test.go index 902e70fc23..1ad7ea524c 100644 --- a/api/web3server_test.go +++ b/api/web3server_test.go @@ -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,