コード例 #1
0
        public void Setup()
        {
            _receiptStorage = Substitute.For <IReceiptStorage>();
            _blockTree      = Substitute.For <IBlockTree>();

            _syncConfig = new SyncConfig {
                FastBlocks = true
            };
            _syncConfig.PivotNumber = _pivotNumber.ToString();
            _syncConfig.PivotHash   = Keccak.Zero.ToString();

            _syncPeerPool = Substitute.For <ISyncPeerPool>();
            _syncReport   = Substitute.For <ISyncReport>();

            _measuredProgress      = new MeasuredProgress();
            _measuredProgressQueue = new MeasuredProgress();
            _syncReport.FastBlocksReceipts.Returns(_measuredProgress);
            _syncReport.ReceiptsInQueue.Returns(_measuredProgressQueue);

            _selector = Substitute.For <ISyncModeSelector>();

            _feed = new ReceiptsSyncFeed(
                _selector,
                _specProvider,
                _blockTree,
                _receiptStorage,
                _syncPeerPool,
                _syncConfig,
                _syncReport,
                LimboLogs.Instance);
        }
コード例 #2
0
 public void Should_throw_when_fast_blocks_not_enabled()
 {
     _syncConfig = new SyncConfig {
         FastBlocks = false
     };
     Assert.Throws <InvalidOperationException>(
         () => _feed = new ReceiptsSyncFeed(
             _selector,
             _specProvider,
             _blockTree,
             _receiptStorage,
             _syncPeerPool,
             _syncConfig,
             _syncReport,
             LimboLogs.Instance));
 }
コード例 #3
0
        private void LoadScenario(Scenario scenario, ISyncConfig syncConfig)
        {
            _syncConfig             = syncConfig;
            _syncConfig.PivotNumber = _pivotNumber.ToString();
            _syncConfig.PivotHash   = scenario.Blocks.Last().Hash.ToString();

            _feed = new ReceiptsSyncFeed(
                _selector,
                _specProvider,
                _blockTree,
                _receiptStorage,
                _syncPeerPool,
                _syncConfig,
                _syncReport,
                LimboLogs.Instance);

            _blockTree.Genesis.Returns(scenario.Blocks[0].Header);
            _blockTree.FindCanonicalBlockInfo(Arg.Any <long>()).Returns(
                ci =>
            {
                Block block = scenario.Blocks[ci.Arg <long>()];
                if (block == null)
                {
                    return(null);
                }

                BlockInfo blockInfo   = new BlockInfo(block.Hash, block.TotalDifficulty ?? 0);
                blockInfo.BlockNumber = ci.Arg <long>();
                return(blockInfo);
            });

            _blockTree.FindBlock(Keccak.Zero, BlockTreeLookupOptions.None)
            .ReturnsForAnyArgs(ci =>
                               scenario.BlocksByHash.ContainsKey(ci.Arg <Keccak>())
                        ? scenario.BlocksByHash[ci.Arg <Keccak>()]
                        : null);

            _blockTree.FindHeader(Keccak.Zero, BlockTreeLookupOptions.None)
            .ReturnsForAnyArgs(ci =>
                               scenario.BlocksByHash.ContainsKey(ci.Arg <Keccak>())
                        ? scenario.BlocksByHash[ci.Arg <Keccak>()].Header
                        : null);

            _receiptStorage.LowestInsertedReceiptBlockNumber.Returns((long?)null);
            _blockTree.LowestInsertedBodyNumber.Returns(scenario.LowestInsertedBody.Number);
        }
コード例 #4
0
        public async Task Should_finish_on_start_when_receipts_not_stored()
        {
            _feed = new ReceiptsSyncFeed(
                _selector,
                _specProvider,
                _blockTree,
                NullReceiptStorage.Instance,
                _syncPeerPool,
                _syncConfig,
                _syncReport,
                LimboLogs.Instance);

            var request = await _feed.PrepareRequest();

            request.Should().BeNull();
            _feed.CurrentState.Should().Be(SyncFeedState.Finished);
        }