Search in sources :

Example 1 with RskJsonRpcRequest

use of co.rsk.rpc.modules.RskJsonRpcRequest in project rskj by rsksmart.

the class JacksonBasedRpcSerializerTest method testStringId_then_convertSuccessfully.

@Test
public void testStringId_then_convertSuccessfully() throws IOException {
    String messageStr = "{\"jsonrpc\": \"2.0\",\"method\": \"eth_subscribe\",\"params\": [\"newHeads\"],\"id\": \"string\"}";
    RskJsonRpcRequest requestFromStringId = convertJson(messageStr);
    Assert.assertEquals("string", requestFromStringId.getId());
}
Also used : RskJsonRpcRequest(co.rsk.rpc.modules.RskJsonRpcRequest) Test(org.junit.Test)

Example 2 with RskJsonRpcRequest

use of co.rsk.rpc.modules.RskJsonRpcRequest in project rskj by rsksmart.

the class EthSubscribeRequestTest method deserializePendingTransactions.

@Test
public void deserializePendingTransactions() throws IOException {
    String message = "{\"jsonrpc\":\"2.0\",\"id\":333,\"method\":\"eth_subscribe\",\"params\":[\"newPendingTransactions\"]}";
    RskJsonRpcRequest request = serializer.deserializeRequest(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)));
    validateParams(request, EthSubscribePendingTransactionsParams.class);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RskJsonRpcRequest(co.rsk.rpc.modules.RskJsonRpcRequest) Test(org.junit.Test)

Example 3 with RskJsonRpcRequest

use of co.rsk.rpc.modules.RskJsonRpcRequest in project rskj by rsksmart.

the class EthSubscribeRequestTest method deserializeNewHeads.

@Test
public void deserializeNewHeads() throws IOException {
    String message = "{\"jsonrpc\":\"2.0\",\"id\":333,\"method\":\"eth_subscribe\",\"params\":[\"newHeads\"]}";
    RskJsonRpcRequest request = serializer.deserializeRequest(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)));
    validateParams(request, EthSubscribeNewHeadsParams.class);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RskJsonRpcRequest(co.rsk.rpc.modules.RskJsonRpcRequest) Test(org.junit.Test)

Example 4 with RskJsonRpcRequest

use of co.rsk.rpc.modules.RskJsonRpcRequest in project rskj by rsksmart.

the class EthSubscribeRequestTest method deserializeLogsParametersAsArrays.

@Test
public void deserializeLogsParametersAsArrays() throws IOException {
    RskAddress logAddress = new RskAddress("0x3e1127bf1a673d378a8570f7a79cea4f10e20489");
    Topic logTopic = new Topic("0x2809c7e17bf978fbc7194c0a694b638c4215e9140cacc6c38ca36010b45697df");
    String message = "{\"jsonrpc\":\"2.0\",\"id\":333,\"method\":\"eth_subscribe\",\"params\":[\"logs\", {\"address\":[\"" + logAddress.toJsonString() + "\"],\"topics\":[\"" + logTopic.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(1)));
    assertThat(logsParams.getTopics()[0], is(arrayWithSize(1)));
    assertThat(logsParams.getTopics()[0], hasItemInArray(logTopic));
}
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 5 with RskJsonRpcRequest

use of co.rsk.rpc.modules.RskJsonRpcRequest in project rskj by rsksmart.

the class EthSubscribeRequestTest method deserializeLogsSingleParameters.

@Test
public void deserializeLogsSingleParameters() throws IOException {
    RskAddress logAddress = new RskAddress("0x3e1127bf1a673d378a8570f7a79cea4f10e20489");
    Topic logTopic = new Topic("0x2809c7e17bf978fbc7194c0a694b638c4215e9140cacc6c38ca36010b45697df");
    String message = "{\"jsonrpc\":\"2.0\",\"id\":333,\"method\":\"eth_subscribe\",\"params\":[\"logs\", {\"address\":\"" + logAddress.toJsonString() + "\",\"topics\":\"" + logTopic.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(1)));
    assertThat(logsParams.getTopics()[0], is(arrayWithSize(1)));
    assertThat(logsParams.getTopics()[0], hasItemInArray(logTopic));
}
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)

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