Search in sources :

Example 1 with Topic

use of org.ethereum.rpc.Topic 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 2 with Topic

use of org.ethereum.rpc.Topic 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)

Example 3 with Topic

use of org.ethereum.rpc.Topic 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)

Aggregations

RskAddress (co.rsk.core.RskAddress)3 RskJsonRpcRequest (co.rsk.rpc.modules.RskJsonRpcRequest)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Topic (org.ethereum.rpc.Topic)3 Test (org.junit.Test)3