Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api] Fix execution reverted message in eth_call #4454

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions api/coreservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
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 @@ -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
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
Loading