Search in sources :

Example 1 with NodeStatistics

use of org.ethereum.net.NodeStatistics in project rskj by rsksmart.

the class HandshakeHandlerTest method setup.

@Before
public void setup() {
    RskSystemProperties config = new TestSystemProperties();
    hhKey = config.getMyKey();
    handler = new HandshakeHandler(config, mock(PeerScoringManager.class), mock(P2pHandler.class), mock(MessageCodec.class), // this needs to be the real object so we can test changing the HELLO message
    new ConfigCapabilitiesImpl(config));
    channel = mock(Channel.class);
    when(channel.getNodeStatistics()).thenReturn(new NodeStatistics());
    // We don't pass the handler to the constructor to avoid calling HandshakeHandler.channelActive
    ch = new EmbeddedChannel();
    ch.pipeline().addLast(handler);
    ctx = ch.pipeline().firstContext();
}
Also used : NodeStatistics(org.ethereum.net.NodeStatistics) ConfigCapabilitiesImpl(org.ethereum.net.client.ConfigCapabilitiesImpl) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Channel(org.ethereum.net.server.Channel) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) RskSystemProperties(co.rsk.config.RskSystemProperties) TestSystemProperties(co.rsk.config.TestSystemProperties) Before(org.junit.Before)

Example 2 with NodeStatistics

use of org.ethereum.net.NodeStatistics in project rskj by rsksmart.

the class RskWireProtocolTest method channelRead0_get_block_message.

@Test
public void channelRead0_get_block_message() throws Exception {
    NodeStatistics.StatHandler statHandler = mock(NodeStatistics.StatHandler.class);
    NodeStatistics nodeStatistics = mock(NodeStatistics.class);
    when(channel.getNodeStatistics()).thenReturn(nodeStatistics);
    when(nodeStatistics.getEthInbound()).thenReturn(statHandler);
    Message message = new GetBlockMessage(new byte[32]);
    EthMessage rskMessage = new RskMessage(message);
    target.channelRead0(ctx, rskMessage);
    verify(messageHandler).postMessage(eq(channel), eq(message));
}
Also used : GetBlockMessage(co.rsk.net.messages.GetBlockMessage) Message(co.rsk.net.messages.Message) BlockMessage(co.rsk.net.messages.BlockMessage) EthMessage(org.ethereum.net.eth.message.EthMessage) StatusMessage(org.ethereum.net.eth.message.StatusMessage) GetBlockMessage(co.rsk.net.messages.GetBlockMessage) NodeStatistics(org.ethereum.net.NodeStatistics) EthMessage(org.ethereum.net.eth.message.EthMessage) Test(org.junit.Test)

Example 3 with NodeStatistics

use of org.ethereum.net.NodeStatistics in project rskj by rsksmart.

the class RskWireProtocolTest method channelRead0_old_status_unexpected_genesis.

@Test
public void channelRead0_old_status_unexpected_genesis() throws Exception {
    NodeStatistics.StatHandler statHandler = mock(NodeStatistics.StatHandler.class);
    NodeStatistics nodeStatistics = mock(NodeStatistics.class);
    when(channel.getNodeStatistics()).thenReturn(nodeStatistics);
    when(nodeStatistics.getEthInbound()).thenReturn(statHandler);
    EthMessage message = new StatusMessage(EthVersion.V62.getCode(), 0x0, ByteUtil.bigIntegerToBytes(BigInteger.valueOf(10)), new byte[32], new byte[32]);
    target.channelRead0(ctx, message);
    verify(messageQueue).disconnect(eq(ReasonCode.UNEXPECTED_GENESIS));
}
Also used : NodeStatistics(org.ethereum.net.NodeStatistics) EthMessage(org.ethereum.net.eth.message.EthMessage) StatusMessage(org.ethereum.net.eth.message.StatusMessage) Test(org.junit.Test)

Example 4 with NodeStatistics

use of org.ethereum.net.NodeStatistics in project rskj by rsksmart.

the class RskWireProtocolTest method activate_sendStatus.

@Test
public void activate_sendStatus() {
    BlockDifficulty blockDifficulty = new BlockDifficulty(BigInteger.valueOf(20));
    Status status = mock(Status.class);
    when(status.getTotalDifficulty()).thenReturn(blockDifficulty);
    when(statusResolver.currentStatus()).thenReturn(status);
    when(genesis.getHash()).thenReturn(new Keccak256(new byte[32]));
    NodeStatistics nodeStatistics = mock(NodeStatistics.class);
    when(nodeStatistics.getEthOutbound()).thenReturn(mock(NodeStatistics.StatHandler.class));
    when(channel.getNodeStatistics()).thenReturn(nodeStatistics);
    target.activate();
    verify(messageQueue, times(2)).sendMessage(any());
}
Also used : Status(co.rsk.net.Status) BlockDifficulty(co.rsk.core.BlockDifficulty) NodeStatistics(org.ethereum.net.NodeStatistics) Keccak256(co.rsk.crypto.Keccak256) Test(org.junit.Test)

Example 5 with NodeStatistics

use of org.ethereum.net.NodeStatistics in project rskj by rsksmart.

the class RskWireProtocolTest method channelRead0_old_status_invalid_network.

@Test
public void channelRead0_old_status_invalid_network() throws Exception {
    NodeStatistics.StatHandler statHandler = mock(NodeStatistics.StatHandler.class);
    NodeStatistics nodeStatistics = mock(NodeStatistics.class);
    when(channel.getNodeStatistics()).thenReturn(nodeStatistics);
    when(nodeStatistics.getEthInbound()).thenReturn(statHandler);
    EthMessage message = new StatusMessage(EthVersion.V62.getCode(), 0x1, ByteUtil.bigIntegerToBytes(BigInteger.valueOf(10)), new byte[32], new byte[32]);
    target.channelRead0(ctx, message);
    verify(messageQueue).disconnect(eq(ReasonCode.NULL_IDENTITY));
}
Also used : NodeStatistics(org.ethereum.net.NodeStatistics) EthMessage(org.ethereum.net.eth.message.EthMessage) StatusMessage(org.ethereum.net.eth.message.StatusMessage) Test(org.junit.Test)

Aggregations

NodeStatistics (org.ethereum.net.NodeStatistics)8 Test (org.junit.Test)7 EthMessage (org.ethereum.net.eth.message.EthMessage)6 StatusMessage (org.ethereum.net.eth.message.StatusMessage)6 BlockMessage (co.rsk.net.messages.BlockMessage)3 GetBlockMessage (co.rsk.net.messages.GetBlockMessage)3 Message (co.rsk.net.messages.Message)3 Keccak256 (co.rsk.crypto.Keccak256)2 Status (co.rsk.net.Status)2 RskSystemProperties (co.rsk.config.RskSystemProperties)1 TestSystemProperties (co.rsk.config.TestSystemProperties)1 BlockDifficulty (co.rsk.core.BlockDifficulty)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 Block (org.ethereum.core.Block)1 ConfigCapabilitiesImpl (org.ethereum.net.client.ConfigCapabilitiesImpl)1 Channel (org.ethereum.net.server.Channel)1 Before (org.junit.Before)1