Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,13 @@ private io.grpc.Status convert(StatusCode code) {
case CONTRACT_CONTEXTUAL_ERROR:
case UNLOADABLE_FUNCTION:
case INVALID_FUNCTION:
case INVALID_ARGUMENT:
return io.grpc.Status.INVALID_ARGUMENT;
case CERTIFICATE_NOT_FOUND:
case CONTRACT_NOT_FOUND:
case ASSET_NOT_FOUND:
case FUNCTION_NOT_FOUND:
case SECRET_NOT_FOUND:
Comment on lines +133 to +139
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While the new status code mappings are correct, there are no corresponding unit tests being added in CommonServiceTest.java to verify this. It would be good practice to add tests that throw LedgerException with StatusCode.INVALID_ARGUMENT and StatusCode.SECRET_NOT_FOUND and assert that the correct gRPC status is returned to the client. This would prevent future regressions and improve test coverage, as the current tests only check that onError is called, not which specific error is propagated.

For example, a test for INVALID_ARGUMENT could look like this (you will need to add imports for ArgumentCaptor, StatusRuntimeException, and assertEquals):

@Test
public void serve_LedgerExceptionWithInvalidArgument_ShouldCallOnErrorWithInvalidArgument() {
    // Arrange
    service = new CommonService(stats, gateKeeper);
    ThrowableConsumer<String> f =
        r -> {
          throw new LedgerException("test", StatusCode.INVALID_ARGUMENT);
        };
    String request = "test";
    ArgumentCaptor<StatusRuntimeException> captor = ArgumentCaptor.forClass(StatusRuntimeException.class);

    // Act
    service.serve(f, request, observerWithEmpty);

    // Assert
    verify(observerWithEmpty).onError(captor.capture());
    assertEquals(io.grpc.Status.Code.INVALID_ARGUMENT, captor.getValue().getStatus().getCode());
}

A similar test should be added for SECRET_NOT_FOUND.

return io.grpc.Status.NOT_FOUND;
case CERTIFICATE_ALREADY_REGISTERED:
case SECRET_ALREADY_REGISTERED:
Expand Down