Beispiel #1
0
        public void CacheDeltasBetween_Should_Stop_When_One_Of_Deltas_Is_Missing()
        {
            var chainSize = 5;
            var chain     = BuildChainedDeltas(chainSize);

            SetCacheExpectations(chain);

            var hashes           = chain.Keys.ToArray();
            var brokenChainIndex = 2;

            _deltaCache.TryGetOrAddConfirmedDelta(hashes[brokenChainIndex], out Arg.Any <Delta>())
            .Returns(false);
            _output.WriteLine($"chain is broken for {hashes[brokenChainIndex]}, it cannot be found on Dfs.");

            var cachedHashes = _synchroniser.CacheDeltasBetween(hashes.First(),
                                                                hashes.Last(), _cancellationToken).ToList();

            OutputCachedHashes(cachedHashes);

            cachedHashes.Count.Should().Be(chainSize - brokenChainIndex);
            hashes.TakeLast(chainSize - brokenChainIndex + 1).ToList().ForEach(h =>
            {
                _deltaCache.Received(1).TryGetOrAddConfirmedDelta(h,
                                                                  out Arg.Any <Delta>(), _cancellationToken);
            });
        }
        public void BuildDeltaEmptyPoolContent()
        {
            var transactionRetriever = Substitute.For <IDeltaTransactionRetriever>();

            transactionRetriever.GetMempoolTransactionsByPriority()
            .Returns(new List <TransactionBroadcast>());

            var deltaBuilder = new DeltaBuilder(transactionRetriever, _randomFactory, _hashProvider, _peerSettings, _cache, _dateTimeProvider, _logger);

            var candidate = deltaBuilder.BuildCandidateDelta(_previousDeltaHash);

            ValidateDeltaCandidate(candidate, _zeroCoinbaseEntry.ToByteArray());

            _cache.Received(1).AddLocalDelta(Arg.Is(candidate), Arg.Any <Delta>());
        }
Beispiel #3
0
        public async Task Sync_Can_Download_Deltas()
        {
            _syncTestHeight = 10;

            var sync = new Synchroniser(new SyncState(), _peerSyncManager, _deltaCache, _deltaHeightWatcher, _deltaHashProvider, _deltaDfsReader, _deltaIndexService,
                                        _mapperProvider, _userOutput, Substitute.For <ILogger>(), _syncTestHeight);

            sync.SyncCompleted.Subscribe(x => { _manualResetEventSlim.Set(); });

            await sync.StartAsync(CancellationToken.None);

            _manualResetEventSlim.Wait();

            _deltaCache.Received(_syncTestHeight).TryGetOrAddConfirmedDelta(Arg.Any <Cid>(), out Arg.Any <Delta>());
        }
        public async Task GetDeltaRequestObserver_Should_Send_Response_When_Delta_Found_In_Cache()
        {
            var cid        = _hashProvider.ComputeUtf8MultiHash("abcd").CreateCid();
            var delta      = CreateAndExpectDeltaFromCache(cid);
            var observable = CreateStreamWithDeltaRequest(cid);

            _observer.StartObserving(observable);

            _testScheduler.Start();

            _deltaCache.Received(1).TryGetOrAddConfirmedDelta(Arg.Is <Cid>(
                                                                  s => s.Equals(cid)), out Arg.Any <Delta>());

            await _fakeContext.Channel.ReceivedWithAnyArgs(1)
            .WriteAndFlushAsync(Arg.Is <IMessageDto <ProtocolMessage> >(pm =>
                                                                        pm.Content.FromProtocolMessage <GetDeltaResponse>().Delta.PreviousDeltaDfsHash ==
                                                                        delta.PreviousDeltaDfsHash));
        }