|
|
|
@ -87,7 +87,7 @@ public final class EthProtocolManagerTest { |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void disconnectOnUnsolicitedMessage() { |
|
|
|
|
try (EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
try (final EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
final MessageData messageData = |
|
|
|
|
BlockHeadersMessage.create(Collections.singletonList(blockchain.getBlockHeader(1).get())); |
|
|
|
|
final MockPeerConnection peer = setupPeer(ethManager, (cap, msg, conn) -> {}); |
|
|
|
@ -98,7 +98,7 @@ public final class EthProtocolManagerTest { |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void disconnectOnFailureToSendStatusMessage() { |
|
|
|
|
try (EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
try (final EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
final MessageData messageData = |
|
|
|
|
BlockHeadersMessage.create(Collections.singletonList(blockchain.getBlockHeader(1).get())); |
|
|
|
|
final MockPeerConnection peer = |
|
|
|
@ -110,7 +110,7 @@ public final class EthProtocolManagerTest { |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void disconnectOnWrongChainId() { |
|
|
|
|
try (EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
try (final EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
final MessageData messageData = |
|
|
|
|
BlockHeadersMessage.create(Collections.singletonList(blockchain.getBlockHeader(1).get())); |
|
|
|
|
final MockPeerConnection peer = |
|
|
|
@ -133,7 +133,7 @@ public final class EthProtocolManagerTest { |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void disconnectOnWrongGenesisHash() { |
|
|
|
|
try (EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
try (final EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
final MessageData messageData = |
|
|
|
|
BlockHeadersMessage.create(Collections.singletonList(blockchain.getBlockHeader(1).get())); |
|
|
|
|
final MockPeerConnection peer = |
|
|
|
@ -156,7 +156,7 @@ public final class EthProtocolManagerTest { |
|
|
|
|
|
|
|
|
|
@Test(expected = ConditionTimeoutException.class) |
|
|
|
|
public void doNotDisconnectOnValidMessage() { |
|
|
|
|
try (EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
try (final EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
final MessageData messageData = |
|
|
|
|
GetBlockBodiesMessage.create(Collections.singletonList(gen.hash())); |
|
|
|
|
final MockPeerConnection peer = setupPeer(ethManager, (cap, msg, conn) -> {}); |
|
|
|
@ -171,7 +171,7 @@ public final class EthProtocolManagerTest { |
|
|
|
|
@Test |
|
|
|
|
public void respondToGetHeaders() throws ExecutionException, InterruptedException { |
|
|
|
|
final CompletableFuture<Void> done = new CompletableFuture<>(); |
|
|
|
|
try (EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
try (final EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
final long startBlock = 5L; |
|
|
|
|
final int blockCount = 5; |
|
|
|
|
final MessageData messageData = |
|
|
|
@ -203,7 +203,8 @@ public final class EthProtocolManagerTest { |
|
|
|
|
public void respondToGetHeadersWithinLimits() throws ExecutionException, InterruptedException { |
|
|
|
|
final CompletableFuture<Void> done = new CompletableFuture<>(); |
|
|
|
|
final int limit = 5; |
|
|
|
|
try (EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1, limit)) { |
|
|
|
|
try (final EthProtocolManager ethManager = |
|
|
|
|
new EthProtocolManager(blockchain, 1, true, 1, limit)) { |
|
|
|
|
final long startBlock = 5L; |
|
|
|
|
final int blockCount = 10; |
|
|
|
|
final MessageData messageData = |
|
|
|
@ -234,7 +235,7 @@ public final class EthProtocolManagerTest { |
|
|
|
|
@Test |
|
|
|
|
public void respondToGetHeadersReversed() throws ExecutionException, InterruptedException { |
|
|
|
|
final CompletableFuture<Void> done = new CompletableFuture<>(); |
|
|
|
|
try (EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
try (final EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
final long endBlock = 10L; |
|
|
|
|
final int blockCount = 5; |
|
|
|
|
final MessageData messageData = GetBlockHeadersMessage.create(endBlock, blockCount, true, 0); |
|
|
|
@ -264,7 +265,7 @@ public final class EthProtocolManagerTest { |
|
|
|
|
@Test |
|
|
|
|
public void respondToGetHeadersWithSkip() throws ExecutionException, InterruptedException { |
|
|
|
|
final CompletableFuture<Void> done = new CompletableFuture<>(); |
|
|
|
|
try (EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
try (final EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
final long startBlock = 5L; |
|
|
|
|
final int blockCount = 5; |
|
|
|
|
final int skip = 1; |
|
|
|
@ -297,7 +298,7 @@ public final class EthProtocolManagerTest { |
|
|
|
|
public void respondToGetHeadersReversedWithSkip() |
|
|
|
|
throws ExecutionException, InterruptedException { |
|
|
|
|
final CompletableFuture<Void> done = new CompletableFuture<>(); |
|
|
|
|
try (EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
try (final EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
final long endBlock = 10L; |
|
|
|
|
final int blockCount = 5; |
|
|
|
|
final int skip = 1; |
|
|
|
@ -351,7 +352,7 @@ public final class EthProtocolManagerTest { |
|
|
|
|
@Test |
|
|
|
|
public void respondToGetHeadersPartial() throws ExecutionException, InterruptedException { |
|
|
|
|
final CompletableFuture<Void> done = new CompletableFuture<>(); |
|
|
|
|
try (EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
try (final EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
final long startBlock = blockchain.getChainHeadBlockNumber() - 1L; |
|
|
|
|
final int blockCount = 5; |
|
|
|
|
final MessageData messageData = |
|
|
|
@ -382,7 +383,7 @@ public final class EthProtocolManagerTest { |
|
|
|
|
@Test |
|
|
|
|
public void respondToGetHeadersEmpty() throws ExecutionException, InterruptedException { |
|
|
|
|
final CompletableFuture<Void> done = new CompletableFuture<>(); |
|
|
|
|
try (EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
try (final EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
final long startBlock = blockchain.getChainHeadBlockNumber() + 1; |
|
|
|
|
final int blockCount = 5; |
|
|
|
|
final MessageData messageData = |
|
|
|
@ -410,7 +411,7 @@ public final class EthProtocolManagerTest { |
|
|
|
|
@Test |
|
|
|
|
public void respondToGetBodies() throws ExecutionException, InterruptedException { |
|
|
|
|
final CompletableFuture<Void> done = new CompletableFuture<>(); |
|
|
|
|
try (EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
try (final EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
// Setup blocks query
|
|
|
|
|
final long startBlock = blockchain.getChainHeadBlockNumber() - 5; |
|
|
|
|
final int blockCount = 2; |
|
|
|
@ -454,7 +455,8 @@ public final class EthProtocolManagerTest { |
|
|
|
|
public void respondToGetBodiesWithinLimits() throws ExecutionException, InterruptedException { |
|
|
|
|
final CompletableFuture<Void> done = new CompletableFuture<>(); |
|
|
|
|
final int limit = 5; |
|
|
|
|
try (EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1, limit)) { |
|
|
|
|
try (final EthProtocolManager ethManager = |
|
|
|
|
new EthProtocolManager(blockchain, 1, true, 1, limit)) { |
|
|
|
|
// Setup blocks query
|
|
|
|
|
final int blockCount = 10; |
|
|
|
|
final long startBlock = blockchain.getChainHeadBlockNumber() - blockCount; |
|
|
|
@ -497,7 +499,7 @@ public final class EthProtocolManagerTest { |
|
|
|
|
@Test |
|
|
|
|
public void respondToGetBodiesPartial() throws ExecutionException, InterruptedException { |
|
|
|
|
final CompletableFuture<Void> done = new CompletableFuture<>(); |
|
|
|
|
try (EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
try (final EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
// Setup blocks query
|
|
|
|
|
final long expectedBlockNumber = blockchain.getChainHeadBlockNumber() - 1; |
|
|
|
|
final BlockHeader header = blockchain.getBlockHeader(expectedBlockNumber).get(); |
|
|
|
@ -534,7 +536,7 @@ public final class EthProtocolManagerTest { |
|
|
|
|
@Test |
|
|
|
|
public void respondToGetReceipts() throws ExecutionException, InterruptedException { |
|
|
|
|
final CompletableFuture<Void> done = new CompletableFuture<>(); |
|
|
|
|
try (EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
try (final EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
// Setup blocks query
|
|
|
|
|
final long startBlock = blockchain.getChainHeadBlockNumber() - 5; |
|
|
|
|
final int blockCount = 2; |
|
|
|
@ -577,7 +579,8 @@ public final class EthProtocolManagerTest { |
|
|
|
|
public void respondToGetReceiptsWithinLimits() throws ExecutionException, InterruptedException { |
|
|
|
|
final CompletableFuture<Void> done = new CompletableFuture<>(); |
|
|
|
|
final int limit = 5; |
|
|
|
|
try (EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1, limit)) { |
|
|
|
|
try (final EthProtocolManager ethManager = |
|
|
|
|
new EthProtocolManager(blockchain, 1, true, 1, limit)) { |
|
|
|
|
// Setup blocks query
|
|
|
|
|
final int blockCount = 10; |
|
|
|
|
final long startBlock = blockchain.getChainHeadBlockNumber() - blockCount; |
|
|
|
@ -619,7 +622,7 @@ public final class EthProtocolManagerTest { |
|
|
|
|
@Test |
|
|
|
|
public void respondToGetReceiptsPartial() throws ExecutionException, InterruptedException { |
|
|
|
|
final CompletableFuture<Void> done = new CompletableFuture<>(); |
|
|
|
|
try (EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
try (final EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
// Setup blocks query
|
|
|
|
|
final long blockNumber = blockchain.getChainHeadBlockNumber() - 5; |
|
|
|
|
final int blockCount = 2; |
|
|
|
@ -721,7 +724,7 @@ public final class EthProtocolManagerTest { |
|
|
|
|
blockchain.appendBlock(block, receipts); |
|
|
|
|
|
|
|
|
|
final CompletableFuture<Void> done = new CompletableFuture<>(); |
|
|
|
|
try (EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
try (final EthProtocolManager ethManager = new EthProtocolManager(blockchain, 1, true, 1)) { |
|
|
|
|
final long startBlock = 1L; |
|
|
|
|
final int requestedBlockCount = 13; |
|
|
|
|
final int receivedBlockCount = 2; |
|
|
|
|