public async Task Start_ShouldLaunch_NetInitEvent()
        {
            NetworkInitializedEvent eventData = null;

            _eventBus.Subscribe <NetworkInitializedEvent>(ed =>
            {
                eventData = ed;
                return(Task.CompletedTask);
            });

            await _networkServer.StartAsync();

            await _networkServer.StopAsync();

            eventData.ShouldNotBeNull();
        }
        public async Task Calling_DisposedPeer_ThrowsUnrecoverableNEtException()
        {
            await _networkServer.StartAsync();

            Channel channel = new Channel("localhost", 2001, ChannelCredentials.Insecure);

            PeerService.PeerServiceClient peerClient = new PeerService.PeerServiceClient(channel);

            GrpcClient grpcClient = new GrpcClient(channel, peerClient);

            AElfPeerEndpointHelper.TryParse("127.0.0.1:2001", out var endpoint);

            GrpcPeer peer = new GrpcPeer(grpcClient, endpoint, new PeerConnectionInfo
            {
                SessionId = new byte[] { 1, 2, 3 }
            });

            await peer.DisconnectAsync(false);

            var exHealthCheck = await Assert.ThrowsAsync <NetworkException>(async() => await peer.CheckHealthAsync());

            exHealthCheck.ExceptionType.ShouldBe(NetworkExceptionType.Unrecoverable);

            var exGetBlocks = await Assert.ThrowsAsync <NetworkException>(
                async() => await peer.GetBlocksAsync(Hash.FromString("blockHash"), 10));

            exGetBlocks.ExceptionType.ShouldBe(NetworkExceptionType.Unrecoverable);

            var exGetBlock = await Assert.ThrowsAsync <NetworkException>(
                async() => await peer.GetBlockByHashAsync(Hash.FromString("blockHash")));

            exGetBlock.ExceptionType.ShouldBe(NetworkExceptionType.Unrecoverable);

            var exGetNodes = await Assert.ThrowsAsync <NetworkException>(
                async() => await peer.GetNodesAsync());

            exGetNodes.ExceptionType.ShouldBe(NetworkExceptionType.Unrecoverable);

            await _networkServer.StopAsync();
        }
Beispiel #3
0
        public async Task StartServer_Test()
        {
            NetworkInitializedEvent received = null;

            _eventBus.Subscribe <NetworkInitializedEvent>(a =>
            {
                received = a;
                return(Task.CompletedTask);
            });

            await _networkServer.StartAsync();

            received.ShouldNotBeNull();

            await _networkServer.StopAsync();
        }
        public async Task <OsBlockchainNodeContext> StartAsync(OsBlockchainNodeContextStartDto dto)
        {
            var transactions = new List <Transaction>();

            transactions.Add(GetTransactionForDeployment(dto.ZeroSmartContract,
                                                         ZeroSmartContractAddressNameProvider.Name,
                                                         dto.SmartContractRunnerCategory));

            transactions.AddRange(dto.InitializationSmartContracts
                                  .Select(p => GetTransactionForDeployment(p.Code, p.SystemSmartContractName,
                                                                           dto.SmartContractRunnerCategory,
                                                                           p.ContractInitializationMethodCallList)));

            if (dto.InitializationTransactions != null)
            {
                transactions.AddRange(dto.InitializationTransactions);
            }

            // Add transaction for initialization
            transactions.Add(GetTransactionForGenesisOwnerInitialization(dto));

            var blockchainNodeContextStartDto = new BlockchainNodeContextStartDto()
            {
                ChainId = dto.ChainId,
                ZeroSmartContractType = dto.ZeroSmartContract,
                Transactions          = transactions.ToArray()
            };

            var context = new OsBlockchainNodeContext
            {
                BlockchainNodeContext =
                    await _blockchainNodeContextService.StartAsync(blockchainNodeContextStartDto),
                AElfNetworkServer = _networkServer
            };

            await _networkServer.StartAsync();

            foreach (var nodePlugin in _nodePlugins)
            {
                await nodePlugin.StartAsync(dto.ChainId);
            }

            return(context);
        }
        public async Task StartServer_Test()
        {
            NetworkInitializedEvent received = null;

            _eventBus.Subscribe <NetworkInitializedEvent>(a =>
            {
                received = a;
                return(Task.CompletedTask);
            });

            await _networkServer.StartAsync();

            received.ShouldNotBeNull();

            var reconnections = _reconnectionService.GetPeersReadyForReconnection(null);

            reconnections.Count.ShouldBe(1);
            reconnections.First().Endpoint.ShouldBe("127.0.0.1:2018");

            await _networkServer.StopAsync();
        }
Beispiel #6
0
        private async Task RestartNetworkServer()
        {
            await _networkServer.StopAsync();

            await _networkServer.StartAsync();
        }