use of co.rsk.rpc.modules.RskJsonRpcRequest in project rskj by rsksmart.
the class EthUnsubscribeRequestTest method deserializeUnsubscribe.
@Test
public void deserializeUnsubscribe() throws IOException {
String message = "{\"jsonrpc\":\"2.0\",\"id\":100,\"method\":\"eth_unsubscribe\",\"params\":[\"0x0204\"]}";
ByteArrayInputStream bais = new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8));
RskJsonRpcRequest request = serializer.deserializeRequest(bais);
assertThat(request, instanceOf(EthUnsubscribeRequest.class));
EthUnsubscribeRequest unsubscribeRequest = (EthUnsubscribeRequest) request;
assertThat(unsubscribeRequest.getParams().getSubscriptionId(), is(new SubscriptionId("0x0204")));
}
use of co.rsk.rpc.modules.RskJsonRpcRequest in project rskj by rsksmart.
the class EthSubscribeRequestTest method deserializeLogsWithEmptyConfig.
@Test
public void deserializeLogsWithEmptyConfig() throws IOException {
String message = "{\"jsonrpc\":\"2.0\",\"id\":333,\"method\":\"eth_subscribe\",\"params\":[\"logs\", {}]}";
RskJsonRpcRequest request = serializer.deserializeRequest(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)));
EthSubscribeLogsParams logsParams = validateParams(request, EthSubscribeLogsParams.class);
assertThat(logsParams.getAddresses(), is(arrayWithSize(0)));
assertThat(logsParams.getTopics(), is(arrayWithSize(0)));
}
use of co.rsk.rpc.modules.RskJsonRpcRequest in project rskj by rsksmart.
the class EthSubscribeRequestTest method deserializeLogsNestedTopicArrays.
@Test
public void deserializeLogsNestedTopicArrays() throws IOException {
RskAddress logAddress = new RskAddress("0x3e1127bf1a673d378a8570f7a79cea4f10e20489");
Topic logTopic1 = new Topic("0x2809c7e17bf978fbc7194c0a694b638c4215e9140cacc6c38ca36010b45697df");
Topic logTopic2 = new Topic("0x4c0a694b638c4215e9140b6f08ecb38c4215e9140b6f08ecbdc8ab6b8ef9b245");
String message = "{\"jsonrpc\":\"2.0\",\"id\":333,\"method\":\"eth_subscribe\",\"params\":[\"logs\", {\"address\":[\"" + logAddress.toJsonString() + "\"],\"topics\":[[\"" + logTopic1.toJsonString() + "\"], [\"" + logTopic2.toJsonString() + "\"]]}]}";
RskJsonRpcRequest request = serializer.deserializeRequest(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)));
EthSubscribeLogsParams logsParams = validateParams(request, EthSubscribeLogsParams.class);
assertThat(logsParams.getAddresses(), is(arrayWithSize(1)));
assertThat(logsParams.getAddresses(), hasItemInArray(logAddress));
assertThat(logsParams.getTopics(), is(arrayWithSize(2)));
assertThat(logsParams.getTopics()[0], is(arrayWithSize(1)));
assertThat(logsParams.getTopics()[0], hasItemInArray(logTopic1));
assertThat(logsParams.getTopics()[1], is(arrayWithSize(1)));
assertThat(logsParams.getTopics()[1], hasItemInArray(logTopic2));
}
use of co.rsk.rpc.modules.RskJsonRpcRequest in project rskj by rsksmart.
the class EthSubscribeRequestTest method deserializeSync.
@Test
public void deserializeSync() throws IOException {
String message = "{\"jsonrpc\":\"2.0\",\"id\":333,\"method\":\"eth_subscribe\",\"params\":[\"syncing\"]}";
RskJsonRpcRequest request = serializer.deserializeRequest(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)));
validateParams(request, EthSubscribeSyncParams.class);
}
use of co.rsk.rpc.modules.RskJsonRpcRequest in project rskj by rsksmart.
the class EthSubscribeRequestTest method deserializeLogsWithoutConfig.
@Test
public void deserializeLogsWithoutConfig() throws IOException {
String message = "{\"jsonrpc\":\"2.0\",\"id\":333,\"method\":\"eth_subscribe\",\"params\":[\"logs\"]}";
RskJsonRpcRequest request = serializer.deserializeRequest(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)));
EthSubscribeLogsParams logsParams = validateParams(request, EthSubscribeLogsParams.class);
assertThat(logsParams.getAddresses(), is(arrayWithSize(0)));
assertThat(logsParams.getTopics(), is(arrayWithSize(0)));
}
Aggregations