|
|
@ -20,6 +20,7 @@ import static org.mockito.Mockito.when; |
|
|
|
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest; |
|
|
|
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest; |
|
|
|
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod; |
|
|
|
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod; |
|
|
|
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcError; |
|
|
|
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcError; |
|
|
|
|
|
|
|
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcErrorResponse; |
|
|
|
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse; |
|
|
|
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse; |
|
|
|
import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.methods.WebSocketRpcRequest; |
|
|
|
import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.methods.WebSocketRpcRequest; |
|
|
|
|
|
|
|
|
|
|
@ -95,6 +96,9 @@ public class WebSocketRequestHandlerTest { |
|
|
|
public void jsonDecodeFailureShouldRespondInvalidRequest(final TestContext context) { |
|
|
|
public void jsonDecodeFailureShouldRespondInvalidRequest(final TestContext context) { |
|
|
|
final Async async = context.async(); |
|
|
|
final Async async = context.async(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final JsonRpcErrorResponse expectedResponse = |
|
|
|
|
|
|
|
new JsonRpcErrorResponse(null, JsonRpcError.INVALID_REQUEST); |
|
|
|
|
|
|
|
|
|
|
|
final String websocketId = UUID.randomUUID().toString(); |
|
|
|
final String websocketId = UUID.randomUUID().toString(); |
|
|
|
|
|
|
|
|
|
|
|
vertx |
|
|
|
vertx |
|
|
@ -102,7 +106,7 @@ public class WebSocketRequestHandlerTest { |
|
|
|
.consumer(websocketId) |
|
|
|
.consumer(websocketId) |
|
|
|
.handler( |
|
|
|
.handler( |
|
|
|
msg -> { |
|
|
|
msg -> { |
|
|
|
context.assertEquals(Json.encode(JsonRpcError.INVALID_REQUEST), msg.body()); |
|
|
|
context.assertEquals(Json.encode(expectedResponse), msg.body()); |
|
|
|
verifyZeroInteractions(jsonRpcMethodMock); |
|
|
|
verifyZeroInteractions(jsonRpcMethodMock); |
|
|
|
async.complete(); |
|
|
|
async.complete(); |
|
|
|
}) |
|
|
|
}) |
|
|
@ -115,6 +119,9 @@ public class WebSocketRequestHandlerTest { |
|
|
|
public void objectMapperFailureShouldRespondInvalidRequest(final TestContext context) { |
|
|
|
public void objectMapperFailureShouldRespondInvalidRequest(final TestContext context) { |
|
|
|
final Async async = context.async(); |
|
|
|
final Async async = context.async(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final JsonRpcErrorResponse expectedResponse = |
|
|
|
|
|
|
|
new JsonRpcErrorResponse(null, JsonRpcError.INVALID_REQUEST); |
|
|
|
|
|
|
|
|
|
|
|
final String websocketId = UUID.randomUUID().toString(); |
|
|
|
final String websocketId = UUID.randomUUID().toString(); |
|
|
|
|
|
|
|
|
|
|
|
vertx |
|
|
|
vertx |
|
|
@ -122,7 +129,7 @@ public class WebSocketRequestHandlerTest { |
|
|
|
.consumer(websocketId) |
|
|
|
.consumer(websocketId) |
|
|
|
.handler( |
|
|
|
.handler( |
|
|
|
msg -> { |
|
|
|
msg -> { |
|
|
|
context.assertEquals(Json.encode(JsonRpcError.INVALID_REQUEST), msg.body()); |
|
|
|
context.assertEquals(Json.encode(expectedResponse), msg.body()); |
|
|
|
verifyZeroInteractions(jsonRpcMethodMock); |
|
|
|
verifyZeroInteractions(jsonRpcMethodMock); |
|
|
|
async.complete(); |
|
|
|
async.complete(); |
|
|
|
}) |
|
|
|
}) |
|
|
@ -137,6 +144,8 @@ public class WebSocketRequestHandlerTest { |
|
|
|
|
|
|
|
|
|
|
|
final JsonObject requestJson = |
|
|
|
final JsonObject requestJson = |
|
|
|
new JsonObject().put("id", 1).put("method", "eth_nonexistentMethod"); |
|
|
|
new JsonObject().put("id", 1).put("method", "eth_nonexistentMethod"); |
|
|
|
|
|
|
|
final JsonRpcErrorResponse expectedResponse = |
|
|
|
|
|
|
|
new JsonRpcErrorResponse(1, JsonRpcError.METHOD_NOT_FOUND); |
|
|
|
|
|
|
|
|
|
|
|
final String websocketId = UUID.randomUUID().toString(); |
|
|
|
final String websocketId = UUID.randomUUID().toString(); |
|
|
|
|
|
|
|
|
|
|
@ -145,7 +154,7 @@ public class WebSocketRequestHandlerTest { |
|
|
|
.consumer(websocketId) |
|
|
|
.consumer(websocketId) |
|
|
|
.handler( |
|
|
|
.handler( |
|
|
|
msg -> { |
|
|
|
msg -> { |
|
|
|
context.assertEquals(Json.encode(JsonRpcError.METHOD_NOT_FOUND), msg.body()); |
|
|
|
context.assertEquals(Json.encode(expectedResponse), msg.body()); |
|
|
|
async.complete(); |
|
|
|
async.complete(); |
|
|
|
}) |
|
|
|
}) |
|
|
|
.completionHandler(v -> handler.handle(websocketId, Buffer.buffer(requestJson.toString()))); |
|
|
|
.completionHandler(v -> handler.handle(websocketId, Buffer.buffer(requestJson.toString()))); |
|
|
@ -160,6 +169,8 @@ public class WebSocketRequestHandlerTest { |
|
|
|
final JsonObject requestJson = new JsonObject().put("id", 1).put("method", "eth_x"); |
|
|
|
final JsonObject requestJson = new JsonObject().put("id", 1).put("method", "eth_x"); |
|
|
|
final JsonRpcRequest expectedRequest = requestJson.mapTo(WebSocketRpcRequest.class); |
|
|
|
final JsonRpcRequest expectedRequest = requestJson.mapTo(WebSocketRpcRequest.class); |
|
|
|
when(jsonRpcMethodMock.response(eq(expectedRequest))).thenThrow(new RuntimeException()); |
|
|
|
when(jsonRpcMethodMock.response(eq(expectedRequest))).thenThrow(new RuntimeException()); |
|
|
|
|
|
|
|
final JsonRpcErrorResponse expectedResponse = |
|
|
|
|
|
|
|
new JsonRpcErrorResponse(1, JsonRpcError.INTERNAL_ERROR); |
|
|
|
|
|
|
|
|
|
|
|
final String websocketId = UUID.randomUUID().toString(); |
|
|
|
final String websocketId = UUID.randomUUID().toString(); |
|
|
|
|
|
|
|
|
|
|
@ -168,7 +179,7 @@ public class WebSocketRequestHandlerTest { |
|
|
|
.consumer(websocketId) |
|
|
|
.consumer(websocketId) |
|
|
|
.handler( |
|
|
|
.handler( |
|
|
|
msg -> { |
|
|
|
msg -> { |
|
|
|
context.assertEquals(Json.encode(JsonRpcError.INTERNAL_ERROR), msg.body()); |
|
|
|
context.assertEquals(Json.encode(expectedResponse), msg.body()); |
|
|
|
async.complete(); |
|
|
|
async.complete(); |
|
|
|
}) |
|
|
|
}) |
|
|
|
.completionHandler(v -> handler.handle(websocketId, Buffer.buffer(requestJson.toString()))); |
|
|
|
.completionHandler(v -> handler.handle(websocketId, Buffer.buffer(requestJson.toString()))); |
|
|
|