use of org.hyperledger.besu.ethereum.eth.sync.worldstate.StubTask in project besu by hyperledger.
the class CompleteTaskStepTest method shouldMarkCompleteWhenTaskHasData.
@Test
public void shouldMarkCompleteWhenTaskHasData() {
// Use an arbitrary but actually valid trie node to get children from.
final StubTask task = validTask();
completeTaskStep.markAsCompleteOrFailed(blockHeader, downloadState, task);
assertThat(task.isCompleted()).isTrue();
assertThat(task.isFailed()).isFalse();
verify(downloadState).checkCompletion(worldStateStorage, blockHeader);
}
use of org.hyperledger.besu.ethereum.eth.sync.worldstate.StubTask in project besu by hyperledger.
the class PersistDataStepTest method shouldSkipPersistingTasksWithNoData.
@Test
public void shouldSkipPersistingTasksWithNoData() {
final Task<NodeDataRequest> withData = createTaskWithData(1, 2, 3);
final StubTask withoutData = createTaskWithoutData(4, 5, 6);
final List<Task<NodeDataRequest>> tasks = asList(withData, withoutData);
final List<Task<NodeDataRequest>> result = persistDataStep.persist(tasks, blockHeader, downloadState);
assertThat(result).isSameAs(tasks);
assertThat(worldStateStorage.contains(withData.getData().getHash())).isTrue();
assertThat(worldStateStorage.contains(withoutData.getData().getHash())).isFalse();
}
use of org.hyperledger.besu.ethereum.eth.sync.worldstate.StubTask in project besu by hyperledger.
the class RequestDataStepTest method shouldReportNoProgressWhenRequestCompletesWithNoData.
@Test
public void shouldReportNoProgressWhenRequestCompletesWithNoData() {
final StubTask task1 = StubTask.forHash(HASH1);
final List<Task<NodeDataRequest>> tasks = singletonList(task1);
when(getNodeDataTaskFactory.apply(singletonList(HASH1), BLOCK_NUMBER)).thenReturn(ethTask);
final CompletableFuture<List<Task<NodeDataRequest>>> result = requestDataStep.requestData(tasks, blockHeader, downloadState);
assertThat(result).isNotDone();
getDataFuture.complete(emptyMap());
assertThat(result).isDone();
assertThat(result).isCompletedWithValue(tasks);
verify(downloadState).requestComplete(false);
}
use of org.hyperledger.besu.ethereum.eth.sync.worldstate.StubTask in project besu by hyperledger.
the class RequestDataStepTest method shouldRequestDistinctHashesForTasks.
@Test
public void shouldRequestDistinctHashesForTasks() {
final StubTask task1 = StubTask.forHash(HASH1);
final StubTask task2 = StubTask.forHash(HASH2);
final StubTask task3 = StubTask.forHash(HASH1);
final List<Task<NodeDataRequest>> tasks = asList(task1, task2, task3);
when(getNodeDataTaskFactory.apply(asList(HASH1, HASH2), BLOCK_NUMBER)).thenReturn(ethTask);
final CompletableFuture<List<Task<NodeDataRequest>>> result = requestDataStep.requestData(tasks, blockHeader, downloadState);
assertThat(result).isNotDone();
getDataFuture.complete(ImmutableMap.of(HASH1, DATA1, HASH2, DATA2));
assertThat(result).isDone();
assertThat(result).isCompletedWithValue(tasks);
assertThat(task1.getData().getData()).isEqualTo(DATA1);
assertThat(task2.getData().getData()).isEqualTo(DATA2);
assertThat(task3.getData().getData()).isEqualTo(DATA1);
verify(downloadState).requestComplete(true);
}
use of org.hyperledger.besu.ethereum.eth.sync.worldstate.StubTask in project besu by hyperledger.
the class PersistDataStepTest method createTaskWithData.
private Task<NodeDataRequest> createTaskWithData(final Bytes data) {
final StubTask task = createTaskWithoutData(data);
MerklePatriciaTrie<Bytes, String> trie = new SimpleMerklePatriciaTrie<>(value -> (value != null) ? Bytes.wrap(value.getBytes(StandardCharsets.UTF_8)) : null);
trie.put(data, "01");
task.getData().setData(trie.getValueWithProof(data).getProofRelatedNodes().get(0));
return task;
}
Aggregations