[PAN-2394] Synchronizer returns false if it is in sync (#1130)

* Synchronizer returns false if it is in sync

* expand RunnerTest to test eth_syncing behaviour

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Sally MacFarlane 6 years ago committed by GitHub
parent 36b52f2cf9
commit 5058e6a636
  1. 3
      ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java
  2. 38
      pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java

@ -135,6 +135,9 @@ public class DefaultSynchronizer<C> implements Synchronizer {
if (!started.get()) {
return Optional.empty();
}
if (syncState.syncStatus().getCurrentBlock() == syncState.syncStatus().getHighestBlock()) {
return Optional.empty();
}
return Optional.of(syncState.syncStatus());
}

@ -224,20 +224,50 @@ public final class RunnerTest {
MediaType.parse("application/json; charset=utf-8"),
"{\"jsonrpc\":\"2.0\",\"id\":"
+ Json.encode(7)
+ ",\"method\":\"eth_syncing\"}"))
+ ",\"method\":\"eth_blockNumber\"}"))
.url(baseUrl)
.build())
.execute()) {
assertThat(resp.code()).isEqualTo(200);
final Response syncingResp =
client
.newCall(
new Request.Builder()
.post(
RequestBody.create(
MediaType.parse("application/json; charset=utf-8"),
"{\"jsonrpc\":\"2.0\",\"id\":"
+ Json.encode(7)
+ ",\"method\":\"eth_syncing\"}"))
.url(baseUrl)
.build())
.execute();
assertThat(syncingResp.code()).isEqualTo(200);
final int currentBlock =
UInt256.fromHexString(
new JsonObject(resp.body().string())
.getJsonObject("result")
.getString("currentBlock"))
new JsonObject(resp.body().string()).getString("result"))
.toInt();
System.out.println("******current block " + currentBlock);
if (currentBlock < blockCount) {
// if not yet at blockCount, we should get a sync result from eth_syncing
final int syncResultCurrentBlock =
UInt256.fromHexString(
new JsonObject(syncingResp.body().string())
.getJsonObject("result")
.getString("currentBlock"))
.toInt();
assertThat(syncResultCurrentBlock).isLessThan(blockCount);
}
assertThat(currentBlock).isEqualTo(blockCount);
resp.close();
// when we have synced to blockCount, eth_syncing should return false
final boolean syncResult =
new JsonObject(syncingResp.body().string()).getBoolean("result");
assertThat(syncResult).isFalse();
syncingResp.close();
}
});

Loading…
Cancel
Save