예제 #1
0
        public void Init()
        {
            _hashProvider       = new HashProvider(HashingAlgorithm.GetAlgorithmMetadata("keccak-256"));
            _cycleEventProvider = new TestCycleEventProvider();
            _deltaBuilder       = Substitute.For <IDeltaBuilder>();
            _deltaVoter         = Substitute.For <IDeltaVoter>();
            _deltaElector       = Substitute.For <IDeltaElector>();
            _deltaCache         = Substitute.For <IDeltaCache>();
            _deltaHub           = Substitute.For <IDeltaHub>();
            var deltaHashProvider = Substitute.For <IDeltaHashProvider>();
            var logger            = Substitute.For <ILogger>();

            _syncState = new SyncState {
                IsSynchronized = true, IsRunning = true
            };
            _ledger    = Substitute.For <ILedger>();
            _consensus = new Consensus(
                _deltaBuilder,
                _deltaVoter,
                _deltaElector,
                _deltaCache,
                _deltaHub,
                _cycleEventProvider,
                deltaHashProvider,
                logger);

            _consensus.StartProducing();
        }
        public ConsensusTests()
        {
            var hashingAlgorithm = HashingAlgorithm.GetAlgorithmMetadata("blake2b-256");

            _hashProvider       = new HashProvider(hashingAlgorithm);
            _cycleEventProvider = new TestCycleEventProvider();
            _deltaBuilder       = Substitute.For <IDeltaBuilder>();
            _deltaVoter         = Substitute.For <IDeltaVoter>();
            _deltaElector       = Substitute.For <IDeltaElector>();
            _deltaCache         = Substitute.For <IDeltaCache>();
            _deltaHub           = Substitute.For <IDeltaHub>();
            var deltaHashProvider = Substitute.For <IDeltaHashProvider>();
            var logger            = Substitute.For <ILogger>();

            _consensus = new Consensus(
                _deltaBuilder,
                _deltaVoter,
                _deltaElector,
                _deltaCache,
                _deltaHub,
                _cycleEventProvider,
                deltaHashProvider,
                _hashProvider,
                logger);

            _consensus.StartProducing();
        }
        public void Init()
        {
            var hashProvider = new HashProvider(HashingAlgorithm.GetAlgorithmMetadata("keccak-256"));

            _deltaVoter         = Substitute.For <IDeltaVoter>();
            _fakeChannelContext = Substitute.For <IChannelHandlerContext>();
            var logger = Substitute.For <ILogger>();

            _newHash    = hashProvider.ComputeUtf8MultiHash("newHash").ToCid();
            _prevHash   = hashProvider.ComputeUtf8MultiHash("prevHash").ToCid();
            _producerId = PeerIdHelper.GetPeerId("candidate delta producer");

            var peerRepository = Substitute.For <IPeerRepository>();

            peerRepository.GetPeersByIpAndPublicKey(Arg.Any <ByteString>(), Arg.Any <ByteString>()).Returns(new List <Lib.P2P.Models.Peer> {
                new Lib.P2P.Models.Peer()
            });

            var deltaIndexService = Substitute.For <IDeltaIndexService>();

            deltaIndexService.LatestDeltaIndex().Returns(new Lib.DAO.Ledger.DeltaIndexDao()
            {
                Cid = _prevHash, Height = 0
            });
            _candidateDeltaObserver = new CandidateDeltaObserver(_deltaVoter, deltaIndexService, new SyncState()
            {
                IsSynchronized = true
            }, peerRepository, hashProvider, logger);
        }
예제 #4
0
 public CandidateDeltaObserver(IDeltaVoter deltaVoter, IDeltaIndexService deltaIndexService, SyncState syncState, IPeerRepository peerRepository, IHashProvider provider, ILogger logger)
     : base(logger)
 {
     _deltaVoter        = deltaVoter;
     _deltaIndexService = deltaIndexService;
     _syncState         = syncState;
     _peerRepository    = peerRepository;
     _hashProvider      = provider;
 }
예제 #5
0
        public CandidateDeltaObserverTests()
        {
            var hashProvider = new HashProvider(HashingAlgorithm.GetAlgorithmMetadata("blake2b-256"));

            _deltaVoter         = Substitute.For <IDeltaVoter>();
            _fakeChannelContext = Substitute.For <IChannelHandlerContext>();
            var logger = Substitute.For <ILogger>();

            _newHash                = hashProvider.ComputeUtf8MultiHash("newHash").CreateCid();
            _prevHash               = hashProvider.ComputeUtf8MultiHash("prevHash").CreateCid();
            _producerId             = PeerIdHelper.GetPeerId("candidate delta producer");
            _candidateDeltaObserver = new CandidateDeltaObserver(_deltaVoter, hashProvider, logger);
        }
예제 #6
0
 public Consensus(IDeltaBuilder deltaBuilder,
     IDeltaVoter deltaVoter,
     IDeltaElector deltaElector,
     IDeltaCache deltaCache,
     IDeltaHub deltaHub,
     ICycleEventsProvider cycleEventsProvider,
     IDeltaHashProvider deltaHashProvider,
     ILogger logger)
 {
     _deltaVoter = deltaVoter;
     _deltaElector = deltaElector;
     _cycleEventsProvider = cycleEventsProvider;
     _deltaHashProvider = deltaHashProvider;
     _deltaBuilder = deltaBuilder;
     _deltaHub = deltaHub;
     _deltaCache = deltaCache;
     _logger = logger;
     logger.Information("Consensus repository initialised.");
 }
 public CandidateDeltaObserver(IDeltaVoter deltaVoter, IHashProvider provider, ILogger logger)
     : base(logger)
 {
     _deltaVoter   = deltaVoter;
     _hashProvider = provider;
 }