Skip to content

Commit

Permalink
7311: Remove code only used in test, update test to use code used in …
Browse files Browse the repository at this point in the history
…production code (hyperledger#7775)

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
  • Loading branch information
Matilda-Clerke authored Oct 15, 2024
1 parent acfbc82 commit 716874e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,15 @@ public class GetHeadersFromPeerByNumberTask extends AbstractGetHeadersFromPeerTa
this.blockNumber = blockNumber;
}

public static AbstractGetHeadersFromPeerTask startingAtNumber(
final ProtocolSchedule protocolSchedule,
final EthContext ethContext,
final long firstBlockNumber,
final int segmentLength,
final MetricsSystem metricsSystem) {
return new GetHeadersFromPeerByNumberTask(
protocolSchedule, ethContext, firstBlockNumber, segmentLength, 0, false, metricsSystem);
}

public static AbstractGetHeadersFromPeerTask endingAtNumber(
final ProtocolSchedule protocolSchedule,
final EthContext ethContext,
final long lastlockNumber,
final long lastBlockNumber,
final int segmentLength,
final int skip,
final MetricsSystem metricsSystem) {
return new GetHeadersFromPeerByNumberTask(
protocolSchedule, ethContext, lastlockNumber, segmentLength, skip, true, metricsSystem);
protocolSchedule, ethContext, lastBlockNumber, segmentLength, skip, true, metricsSystem);
}

public static AbstractGetHeadersFromPeerTask forSingleNumber(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected void assertPartialResultMatchesExpectation(
protected List<BlockHeader> generateDataToBeRequested() {
final int count = 3;
final List<BlockHeader> requestedHeaders = new ArrayList<>(count);
for (long i = 0; i < count; i++) {
for (long i = count - 1; i >= 0; i--) {
requestedHeaders.add(blockchain.getBlockHeader(5 + i).get());
}
return requestedHeaders;
Expand All @@ -66,9 +66,13 @@ protected List<BlockHeader> generateDataToBeRequested() {
@Override
protected EthTask<AbstractPeerTask.PeerTaskResult<List<BlockHeader>>> createTask(
final List<BlockHeader> requestedData) {
final BlockHeader firstHeader = requestedData.get(0);
return GetHeadersFromPeerByNumberTask.startingAtNumber(
protocolSchedule, ethContext, firstHeader.getNumber(), requestedData.size(), metricsSystem);
return GetHeadersFromPeerByNumberTask.endingAtNumber(
protocolSchedule,
ethContext,
requestedData.getFirst().getNumber(),
requestedData.size(),
0,
metricsSystem);
}

@Test
Expand Down

0 comments on commit 716874e

Please sign in to comment.