|
|
|
@ -13,6 +13,7 @@ |
|
|
|
|
package tech.pegasys.pantheon.ethereum.eth.sync.tasks; |
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatThrownBy; |
|
|
|
|
import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryBlockchain; |
|
|
|
|
|
|
|
|
|
import tech.pegasys.pantheon.ethereum.ProtocolContext; |
|
|
|
@ -26,6 +27,7 @@ import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManagerTestUtil; |
|
|
|
|
import tech.pegasys.pantheon.ethereum.eth.manager.RespondingEthPeer; |
|
|
|
|
import tech.pegasys.pantheon.ethereum.eth.manager.RespondingEthPeer.Responder; |
|
|
|
|
import tech.pegasys.pantheon.ethereum.eth.manager.ethtaskutils.AbstractMessageTaskTest; |
|
|
|
|
import tech.pegasys.pantheon.ethereum.eth.manager.exceptions.NoAvailablePeersException; |
|
|
|
|
import tech.pegasys.pantheon.ethereum.eth.manager.task.AbstractPeerTask.PeerTaskResult; |
|
|
|
|
import tech.pegasys.pantheon.ethereum.eth.manager.task.EthTask; |
|
|
|
|
import tech.pegasys.pantheon.ethereum.eth.messages.BlockHeadersMessage; |
|
|
|
@ -161,6 +163,23 @@ public class ImportBlocksTaskTest |
|
|
|
|
assertThat(future.isCompletedExceptionally()).isFalse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void shouldNotRequestDataFromPeerBelowExpectedHeight() { |
|
|
|
|
// Setup a unresponsive peer
|
|
|
|
|
final Responder responder = RespondingEthPeer.emptyResponder(); |
|
|
|
|
final RespondingEthPeer respondingEthPeer = |
|
|
|
|
EthProtocolManagerTestUtil.createPeer(ethProtocolManager, 1); |
|
|
|
|
|
|
|
|
|
// Execute task and wait for response
|
|
|
|
|
final List<Block> requestedData = generateDataToBeRequested(); |
|
|
|
|
final EthTask<PeerTaskResult<List<Block>>> task = createTask(requestedData); |
|
|
|
|
final CompletableFuture<PeerTaskResult<List<Block>>> future = task.run(); |
|
|
|
|
respondingEthPeer.respondWhile(responder, () -> !future.isDone()); |
|
|
|
|
assertThat(future.isDone()).isTrue(); |
|
|
|
|
assertThat(future.isCompletedExceptionally()).isTrue(); |
|
|
|
|
assertThatThrownBy(future::get).hasCauseInstanceOf(NoAvailablePeersException.class); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private MutableBlockchain createShortChain(final long truncateAtBlockNumber) { |
|
|
|
|
final BlockHeader genesisHeader = |
|
|
|
|
blockchain.getBlockHeader(BlockHeader.GENESIS_BLOCK_NUMBER).get(); |
|
|
|
|