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();
}
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));
}
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));
}
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());
}
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));
}
Aggregations