public PeerValidationIntegrationTest(ITestOutputHelper output) : base(output)
        {
            var logger = Substitute.For <ILogger>();

            var keyRegistry = TestKeyRegistry.MockKeyRegistry();

            ContainerProvider.ContainerBuilder.RegisterInstance(keyRegistry).As <IKeyRegistry>();

            ContainerProvider.ContainerBuilder.RegisterModule(new KeystoreModule());
            ContainerProvider.ContainerBuilder.RegisterModule(new KeySignerModule());
            ContainerProvider.ContainerBuilder.RegisterModule(new HashingModule());
            ContainerProvider.ContainerBuilder.RegisterModule(new BulletProofsModule());

            _peerSettings = new PeerSettings(ContainerProvider.ConfigurationRoot);

            var peerSettings =
                PeerIdHelper.GetPeerId("sender", _peerSettings.BindAddress, _peerSettings.Port)
                .ToSubstitutedPeerSettings();

            ContainerProvider.ContainerBuilder.Register(c =>
            {
                var peerClient = c.Resolve <IPeerClient>();
                peerClient.StartAsync().ConfigureAwait(false).GetAwaiter().GetResult();
                return(new PeerChallengeRequest(logger, peerClient, peerSettings, 10));
            }).As <IPeerChallengeRequest>().SingleInstance();
        }
        public void Init()
        {
            Setup(TestContext.CurrentContext);

            var logger = Substitute.For <ILogger>();

            var keyRegistry = TestKeyRegistry.MockKeyRegistry();

            ContainerProvider.ContainerBuilder.RegisterInstance(keyRegistry).As <IKeyRegistry>();

            ContainerProvider.ContainerBuilder.RegisterModule(new KeystoreModule());
            ContainerProvider.ContainerBuilder.RegisterModule(new KeySignerModule());
            ContainerProvider.ContainerBuilder.RegisterModule(new HashingModule());
            ContainerProvider.ContainerBuilder.RegisterModule(new BulletProofsModule());

            _peerSettings = new PeerSettings(ContainerProvider.ConfigurationRoot);

            var peerSettings =
                PeerIdHelper.GetPeerId("sender", _peerSettings.BindAddress, _peerSettings.Port)
                .ToSubstitutedPeerSettings();

            ContainerProvider.ContainerBuilder.Register(c =>
            {
                var peerClient = c.Resolve <IPeerClient>();
                peerClient.StartAsync().ConfigureAwait(false).GetAwaiter().GetResult();
                return(new PeerChallengeRequest(logger, peerClient, peerSettings, 10));
            }).As <IPeerChallengeRequest>().SingleInstance();

            _peerChallengeRequest = ContainerProvider.Container.Resolve <IPeerChallengeRequest>();

            var eventLoopGroupFactoryConfiguration = new EventLoopGroupFactoryConfiguration
            {
                TcpClientHandlerWorkerThreads = 2,
                TcpServerHandlerWorkerThreads = 3,
                UdpServerHandlerWorkerThreads = 4,
                UdpClientHandlerWorkerThreads = 5
            };

            var keySigner = ContainerProvider.Container.Resolve <IKeySigner>(); // @@

            _peerService = new PeerService(
                new UdpServerEventLoopGroupFactory(eventLoopGroupFactoryConfiguration),
                new PeerServerChannelFactory(ContainerProvider.Container.Resolve <IPeerMessageCorrelationManager>(),
                                             ContainerProvider.Container.Resolve <IBroadcastManager>(),
                                             keySigner,
                                             ContainerProvider.Container.Resolve <IPeerIdValidator>(),
                                             ContainerProvider.Container.Resolve <IPeerSettings>()),
                new DiscoveryHelper.DevDiscover(),
                ContainerProvider.Container.Resolve <IEnumerable <IP2PMessageObserver> >(),
                _peerSettings,
                ContainerProvider.Container.Resolve <ILogger>(),
                ContainerProvider.Container.Resolve <IHealthChecker>());

            _peerService.StartAsync().Wait();
        }
        public void Network_config_should_allow_building_PeerSettings(string networkConfig)
        {
            var configRoot = new ConfigurationBuilder().AddJsonFile(networkConfig).Build();

            var configModule = new ConfigurationModule(configRoot);

            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterModule(configModule);
            containerBuilder.RegisterInstance(configRoot).As <IConfigurationRoot>();

            var peerSettings = new PeerSettings(configRoot);

            peerSettings.Should().NotBeNull();
            peerSettings.NetworkType.Should().NotBeNull();
            peerSettings.Port.Should().BeInRange(1025, 65535);
            peerSettings.BindAddress.Should().BeOfType <IPAddress>();
            peerSettings.PublicKey.Should().NotBeNullOrWhiteSpace();
            peerSettings.SeedServers.Should().NotBeEmpty();
        }