use of tech.pegasys.teku.networking.eth2.peers.Eth2Peer in project teku by ConsenSys.
the class BeaconBlocksByRangeIntegrationTest method shouldRespondWithBlocksFromCanonicalChain.
@Test
public void shouldRespondWithBlocksFromCanonicalChain() throws Exception {
final Eth2Peer peer = createPeer();
final SignedBlockAndState block1 = peerStorage.chainUpdater().advanceChain();
final SignedBlockAndState block2 = peerStorage.chainUpdater().advanceChain();
peerStorage.chainUpdater().updateBestBlock(block2);
final List<SignedBeaconBlock> response = requestBlocks(peer);
assertThat(response).containsExactly(block1.getBlock(), block2.getBlock());
}
use of tech.pegasys.teku.networking.eth2.peers.Eth2Peer in project teku by ConsenSys.
the class PeerStatusIntegrationTest method shouldExchangeStatusMessagesOnConnection.
@Test
public void shouldExchangeStatusMessagesOnConnection() throws Exception {
final StorageSystem system2 = createStorageSystem();
final RecentChainData recentChainData2 = system2.recentChainData();
assertThat(recentChainData1.getBestBlockRoot()).isEqualTo(recentChainData2.getBestBlockRoot());
final Eth2P2PNetwork network1 = networkFactory.builder().spec(spec).rpcEncoding(rpcEncoding).recentChainData(recentChainData1).startNetwork();
final Eth2P2PNetwork network2 = networkFactory.builder().spec(spec).rpcEncoding(rpcEncoding).recentChainData(recentChainData2).startNetwork();
waitFor(network1.connect(network1.createPeerAddress(network2.getNodeAddress())));
waitFor(() -> {
assertThat(network1.getPeerCount()).isEqualTo(1);
assertThat(network2.getPeerCount()).isEqualTo(1);
});
final Eth2Peer network2ViewOfPeer1 = network2.getPeer(network1.getNodeId()).orElseThrow();
assertStatusMatchesStorage(recentChainData1, network2ViewOfPeer1.getStatus());
final Eth2Peer network1ViewOfPeer2 = network1.getPeer(network2.getNodeId()).orElseThrow();
assertStatusMatchesStorage(recentChainData2, network1ViewOfPeer2.getStatus());
// When the finalized epoch is genesis we should use a zero finalized root (from the state)
// This differs from what recentChainData.getFinalizedCheckpoint will have at genesis
assertThat(network1ViewOfPeer2.getStatus().getFinalizedRoot()).isEqualTo(Bytes32.ZERO);
}
use of tech.pegasys.teku.networking.eth2.peers.Eth2Peer in project teku by ConsenSys.
the class PeerStatusIntegrationTest method shouldUpdatePeerStatus.
@Test
public void shouldUpdatePeerStatus() throws Exception {
final Eth2P2PNetwork network1 = networkFactory.builder().spec(spec).rpcEncoding(rpcEncoding).recentChainData(recentChainData1).startNetwork();
final StorageSystem storageSystem2 = createStorageSystem();
final RecentChainData recentChainData2 = storageSystem2.recentChainData();
final Eth2P2PNetwork network2 = networkFactory.builder().spec(spec).rpcEncoding(rpcEncoding).recentChainData(recentChainData2).peer(network1).startNetwork();
final Eth2Peer network2ViewOfPeer1 = network2.getPeer(network1.getNodeId()).orElseThrow();
assertStatusMatchesStorage(recentChainData1, network2ViewOfPeer1.getStatus());
// Peer 1 advances
this.storageSystem.chainUpdater().advanceChain(10);
final PeerStatus updatedStatusData = waitFor(network2ViewOfPeer1.sendStatus());
assertStatusMatchesStorage(recentChainData1, updatedStatusData);
assertStatusMatchesStorage(recentChainData1, network2ViewOfPeer1.getStatus());
}
use of tech.pegasys.teku.networking.eth2.peers.Eth2Peer in project teku by ConsenSys.
the class Eth2PeerManagerTest method onConnect_shouldDisconnectIfPeerReturnsErrorResponseToStatusMessage.
@Test
void onConnect_shouldDisconnectIfPeerReturnsErrorResponseToStatusMessage() {
final Peer peer = createPeer(1);
final Eth2Peer eth2Peer = getEth2Peer(peer);
when(peer.connectionInitiatedLocally()).thenReturn(true);
when(eth2Peer.sendStatus()).thenReturn(SafeFuture.failedFuture(new RpcException(RpcResponseStatus.SERVER_ERROR_CODE, "It went boom")));
peerManager.onConnect(peer);
verify(eth2Peer).disconnectImmediately(Optional.of(DisconnectReason.REMOTE_FAULT), true);
}
use of tech.pegasys.teku.networking.eth2.peers.Eth2Peer in project teku by ConsenSys.
the class NetworkDataProviderTest method getPeerCount_shouldReturnTotalPeers.
@Test
void getPeerCount_shouldReturnTotalPeers() {
final NetworkDataProvider network = new NetworkDataProvider(p2pNetwork);
final Eth2Peer peer1 = mock(Eth2Peer.class);
final Eth2Peer peer2 = mock(Eth2Peer.class);
when(p2pNetwork.streamPeers()).thenReturn(Stream.of(peer1, peer2));
assertThat(network.getPeerCount()).isEqualTo(2);
verify(p2pNetwork).streamPeers();
}
Aggregations