Exemplo n.º 1
0
        public void CheckHealth_returns_expected_results([ValueSource(nameof(CheckHealthTestCases))] CheckHealthTest test)
        {
            IBlockFinder         blockFinder         = Substitute.For <IBlockFinder>();
            ISyncServer          syncServer          = Substitute.For <ISyncServer>();
            IBlockchainProcessor blockchainProcessor = Substitute.For <IBlockchainProcessor>();
            IBlockProducer       blockProducer       = Substitute.For <IBlockProducer>();
            IHealthHintService   healthHintService   = Substitute.For <IHealthHintService>();

            blockchainProcessor.IsProcessingBlocks(Arg.Any <ulong?>()).Returns(test.IsProcessingBlocks);
            blockProducer.IsProducingBlocks(Arg.Any <ulong?>()).Returns(test.IsProducingBlocks);
            syncServer.GetPeerCount().Returns(test.PeerCount);

            BlockHeaderBuilder GetBlockHeader(int blockNumber) => Build.A.BlockHeader.WithNumber(blockNumber);

            blockFinder.Head.Returns(new Block(GetBlockHeader(4).TestObject));
            if (test.IsSyncing)
            {
                blockFinder.FindBestSuggestedHeader().Returns(GetBlockHeader(15).TestObject);
            }
            else
            {
                blockFinder.FindBestSuggestedHeader().Returns(GetBlockHeader(2).TestObject);
            }

            IEthSyncingInfo   ethSyncingInfo    = new EthSyncingInfo(blockFinder);
            NodeHealthService nodeHealthService =
                new(syncServer, blockFinder, blockchainProcessor, blockProducer, new HealthChecksConfig(), healthHintService, ethSyncingInfo, test.IsMining);
            CheckHealthResult result = nodeHealthService.CheckHealth();

            Assert.AreEqual(test.ExpectedHealthy, result.Healthy);
            Assert.AreEqual(test.ExpectedMessage, FormatMessages(result.Messages.Select(x => x.Message)));
            Assert.AreEqual(test.ExpectedLongMessage, FormatMessages(result.Messages.Select(x => x.LongMessage)));
        }
Exemplo n.º 2
0
 public MergeHealthHintService(IHealthHintService?healthHintService, IPoSSwitcher?poSSwitcher)
 {
     _healthHintService = healthHintService ?? throw new ArgumentNullException(nameof(healthHintService));
     _poSSwitcher       = poSSwitcher ?? throw new ArgumentNullException(nameof(poSSwitcher));
 }