public async Task ProcessDownloadJob_Success() { var response = await _networkService.GetBlockByHashAsync(Hash.FromString("PeerBlock"), null); var peerBlock = response.Payload; await _blockDownloadJobManager.EnqueueAsync(peerBlock.GetHash(), peerBlock.Height, _blockSyncOptions.MaxBatchRequestBlockCount, null); await _blockDownloadWorker.ProcessDownloadJobAsync(); var chain = await _blockchainService.GetChainAsync(); chain.BestChainHeight.ShouldBe(31); var jobInfo = await _blockDownloadJobStore.GetFirstWaitingJobAsync(); jobInfo.JobId.ShouldBe(peerBlock.GetHash()); _blockSyncStateProvider.TryGetDownloadJobTargetState(chain.BestChainHash, out var state).ShouldBeTrue(); state.ShouldBeFalse(); _blockSyncStateProvider.SetDownloadJobTargetState(chain.BestChainHash, true); await _blockDownloadWorker.ProcessDownloadJobAsync(); jobInfo = await _blockDownloadJobStore.GetFirstWaitingJobAsync(); jobInfo.ShouldBeNull(); _blockSyncStateProvider.TryGetDownloadJobTargetState(chain.BestChainHash, out state).ShouldBeFalse(); }
public void RemoveDownloadJobTargetState_Test() { var targetHash = HashHelper.ComputeFrom("TargetHash"); _blockSyncStateProvider.SetDownloadJobTargetState(targetHash, true); _blockDownloadService.RemoveDownloadJobTargetState(null); _blockSyncStateProvider.TryGetDownloadJobTargetState(targetHash, out _).ShouldBeTrue(); _blockDownloadService.RemoveDownloadJobTargetState(targetHash); _blockSyncStateProvider.TryGetDownloadJobTargetState(targetHash, out _).ShouldBeFalse(); }
public void DownloadJobTargetState_Test() { var targetHash = HashHelper.ComputeFrom("TargetHash"); var result = _blockSyncStateProvider.TryUpdateDownloadJobTargetState(targetHash, false); result.ShouldBeFalse(); _blockSyncStateProvider.SetDownloadJobTargetState(targetHash, false); result = _blockSyncStateProvider.TryGetDownloadJobTargetState(targetHash, out var value); result.ShouldBeTrue(); value.ShouldBeFalse(); result = _blockSyncStateProvider.TryUpdateDownloadJobTargetState(targetHash, false); result.ShouldBeFalse(); result = _blockSyncStateProvider.TryUpdateDownloadJobTargetState(targetHash, true); result.ShouldBeTrue(); _blockSyncStateProvider.TryRemoveDownloadJobTargetState(targetHash); result = _blockSyncStateProvider.TryGetDownloadJobTargetState(targetHash, out value); result.ShouldBeFalse(); }
public bool IsNotReachedDownloadTarget(Hash targetBlockHash) { return(_blockSyncStateProvider.TryGetDownloadJobTargetState(targetBlockHash, out var state) && state == false); }