Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' into reduce_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
lucassaldanha authored Nov 1, 2018
2 parents ba01733 + a07a5d6 commit cae0f5e
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ public BytesValue compute(final BytesValue input) {
try {
final Optional<PublicKey> recovered = PublicKey.recoverFromSignature(h, signature);
if (!recovered.isPresent()) {
return Bytes32.ZERO;
return Bytes32.EMPTY;
}

final Bytes32 hashed = Hash.hash(recovered.get().getEncodedBytes());
final MutableBytes32 result = MutableBytes32.create();
hashed.slice(12).copyTo(result, 12);
return result;
} catch (final IllegalArgumentException e) {
return Bytes32.ZERO;
return Bytes32.EMPTY;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static Object[][] parameters() {
return new Object[][] {
{
"acb1c19ac0832320815b5e886c6b73ad7d6177853d44b026f2a7a9e11bb899fc000000000000000000000000000000000000000000000000000000000000001c89ea49159b334f9aebbf54481b69d000d285baa341899db355a4030f6838394e540e9f9fa17bef441e32d98d5f4554cfefdc6a56101352e4b92efafd0d9646e8",
"0x"
null
},
{
"0x0049872459827432342344987245982743234234498724598274323423429943000000000000000000000000000000000000000000000000000000000000001be8359c341771db7f9ea3a662a1741d27775ce277961470028e054ed3285aab8e31f63eaac35c4e6178abbc2a1073040ac9bbb0b67f2bc89a2e9593ba9abe8c53",
Expand Down Expand Up @@ -454,7 +454,8 @@ public static Object[][] parameters() {
@Test
public void shouldRecoverAddress() {
final BytesValue input = BytesValue.fromHexString(this.input);
final BytesValue expected = Bytes32.fromHexString(expectedResult);
final BytesValue expected =
expectedResult == null ? BytesValue.EMPTY : Bytes32.fromHexString(expectedResult);
assertThat(contract.compute(input)).isEqualTo(expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerOptions;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.ServerWebSocket;
import io.vertx.core.net.SocketAddress;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -62,6 +63,7 @@ public CompletableFuture<?> start() {
.setPort(configuration.getPort())
.setWebsocketSubProtocols("undefined"))
.websocketHandler(websocketHandler())
.requestHandler(httpHandler())
.listen(startHandler(resultFuture));

return resultFuture;
Expand Down Expand Up @@ -103,6 +105,11 @@ private Handler<ServerWebSocket> websocketHandler() {
};
}

private Handler<HttpServerRequest> httpHandler() {
return http ->
http.response().setStatusCode(400).end("Websocket endpoint can't handle HTTP requests");
}

private Handler<AsyncResult<HttpServer>> startHandler(final CompletableFuture<?> resultFuture) {
return res -> {
if (res.succeeded()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpClient;
import io.vertx.core.http.HttpClientOptions;
import io.vertx.core.http.HttpServerOptions;
import io.vertx.core.http.WebSocketBase;
import io.vertx.ext.unit.Async;
Expand All @@ -44,6 +46,7 @@ public class WebSocketServiceTest {
private WebSocketConfiguration websocketConfiguration;
private WebSocketRequestHandler webSocketRequestHandlerSpy;
private WebSocketService websocketService;
private HttpClient httpClient;

@Before
public void before() {
Expand All @@ -61,6 +64,13 @@ public void before() {
websocketService.start().join();

websocketConfiguration.setPort(websocketService.socketAddress().getPort());

HttpClientOptions httpClientOptions =
new HttpClientOptions()
.setDefaultHost(websocketConfiguration.getHost())
.setDefaultPort(websocketConfiguration.getPort());

httpClient = vertx.createHttpClient(httpClientOptions);
}

@After
Expand All @@ -76,21 +86,17 @@ public void websocketServiceExecutesHandlerOnMessage(final TestContext context)
final String request = "{\"id\": 1, \"method\": \"eth_subscribe\", \"params\": [\"syncing\"]}";
final String expectedResponse = "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":\"0x1\"}";

vertx
.createHttpClient()
.websocket(
websocketConfiguration.getPort(),
websocketConfiguration.getHost(),
"/",
webSocket -> {
webSocket.write(Buffer.buffer(request));
httpClient.websocket(
"/",
webSocket -> {
webSocket.write(Buffer.buffer(request));

webSocket.handler(
buffer -> {
context.assertEquals(expectedResponse, buffer.toString());
async.complete();
});
});
webSocket.handler(
buffer -> {
context.assertEquals(expectedResponse, buffer.toString());
async.complete();
});
});

async.awaitSuccess(VERTX_AWAIT_TIMEOUT_MILLIS);
}
Expand All @@ -107,15 +113,7 @@ public void websocketServiceRemoveSubscriptionOnConnectionClose(final TestContex
context.assertNotNull(m.body());
async.complete();
})
.completionHandler(
v ->
vertx
.createHttpClient()
.websocket(
websocketConfiguration.getPort(),
websocketConfiguration.getHost(),
"/",
WebSocketBase::close));
.completionHandler(v -> httpClient.websocket("/", WebSocketBase::close));

async.awaitSuccess(VERTX_AWAIT_TIMEOUT_MILLIS);
}
Expand All @@ -127,16 +125,35 @@ public void websocketServiceCloseConnectionOnUnrecoverableError(final TestContex
final byte[] bigMessage = new byte[HttpServerOptions.DEFAULT_MAX_WEBSOCKET_MESSAGE_SIZE + 1];
Arrays.fill(bigMessage, (byte) 1);

vertx
.createHttpClient()
.websocket(
httpClient.websocket(
"/",
webSocket -> {
webSocket.write(Buffer.buffer(bigMessage));
webSocket.closeHandler(v -> async.complete());
});

async.awaitSuccess(VERTX_AWAIT_TIMEOUT_MILLIS);
}

@Test
public void websocketServiceMustReturnErrorOnHttpRequest(final TestContext context) {
final Async async = context.async();

httpClient
.post(
websocketConfiguration.getPort(),
websocketConfiguration.getHost(),
"/",
webSocket -> {
webSocket.write(Buffer.buffer(bigMessage));
webSocket.closeHandler(v -> async.complete());
});
response ->
response.bodyHandler(
b -> {
context
.assertEquals(400, response.statusCode())
.assertEquals(
"Websocket endpoint can't handle HTTP requests", b.toString());
async.complete();
}))
.end();

async.awaitSuccess(VERTX_AWAIT_TIMEOUT_MILLIS);
}
Expand Down
2 changes: 1 addition & 1 deletion quickstart/listQuickstartServices.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ if [ ${#dots} -gt ${maxRetryCount} ]; then
echo "****************************************************************${NORMAL}"
else
echo "JSON-RPC ${BOLD}HTTP${NORMAL}${CYAN} service endpoint : ${ORANGE}http://${HOST}:${explorerMapping##*:}/jsonrpc${CYAN} *"
echo "JSON-RPC ${BOLD}WebSocket${NORMAL}${CYAN} service endpoint : ${ORANGE}http://${HOST}:${explorerMapping##*:}/jsonws${CYAN} *"
echo "JSON-RPC ${BOLD}WebSocket${NORMAL}${CYAN} service endpoint : ${ORANGE}ws://${HOST}:${explorerMapping##*:}/jsonws${CYAN} *"
echo "${CYAN}Web block explorer address : ${ORANGE}http://${HOST}:${explorerMapping##*:}${CYAN} * "
echo "****************************************************************${NORMAL}"
fi
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ private enum EndpointsIdentifier {
final Pattern pattern;

EndpointsIdentifier(final String lineLabel) {
pattern = Pattern.compile(lineLabel + ".+(http://.+:[0-9]+)", Pattern.DOTALL);
pattern =
Pattern.compile(lineLabel + ".+((http|ws)://.+:[0-9]+/{0,1}[a-z]*)", Pattern.DOTALL);
}
}

Expand Down

0 comments on commit cae0f5e

Please sign in to comment.