Search in sources :

Example 6 with RskJsonRpcRequest

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")));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RskJsonRpcRequest(co.rsk.rpc.modules.RskJsonRpcRequest) Test(org.junit.Test)

Example 7 with RskJsonRpcRequest

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)));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RskJsonRpcRequest(co.rsk.rpc.modules.RskJsonRpcRequest) Test(org.junit.Test)

Example 8 with RskJsonRpcRequest

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));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RskJsonRpcRequest(co.rsk.rpc.modules.RskJsonRpcRequest) RskAddress(co.rsk.core.RskAddress) Topic(org.ethereum.rpc.Topic) Test(org.junit.Test)

Example 9 with RskJsonRpcRequest

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RskJsonRpcRequest(co.rsk.rpc.modules.RskJsonRpcRequest) Test(org.junit.Test)

Example 10 with RskJsonRpcRequest

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)));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RskJsonRpcRequest(co.rsk.rpc.modules.RskJsonRpcRequest) Test(org.junit.Test)

Aggregations

RskJsonRpcRequest (co.rsk.rpc.modules.RskJsonRpcRequest)12 Test (org.junit.Test)11 ByteArrayInputStream (java.io.ByteArrayInputStream)9 RskAddress (co.rsk.core.RskAddress)3 Topic (org.ethereum.rpc.Topic)3 JsonRpcError (co.rsk.jsonrpc.JsonRpcError)1 JsonRpcIdentifiableMessage (co.rsk.jsonrpc.JsonRpcIdentifiableMessage)1 JsonRpcResultOrError (co.rsk.jsonrpc.JsonRpcResultOrError)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ByteBuf (io.netty.buffer.ByteBuf)1 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)1 TextWebSocketFrame (io.netty.handler.codec.http.websocketx.TextWebSocketFrame)1 IOException (java.io.IOException)1