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