Beispiel #1
0
        public void Disconnect_Should_Disconnect_From_Node()
        {
            var commandContext = TestCommandHelpers.GenerateCliCommandContext();

            var nodeRpcClient = TestCommandHelpers.MockNodeRpcClient();

            TestCommandHelpers.MockActiveConnection(commandContext, nodeRpcClient);
            TestCommandHelpers.MockNodeRpcClientFactory(commandContext, nodeRpcClient);
            var rpcNodeConfig        = TestCommandHelpers.MockRpcNodeConfig(commandContext);
            var socketClientRegistry = TestCommandHelpers.AddClientSocketRegistry(commandContext, _testScheduler);

            var clientHashCode =
                socketClientRegistry.GenerateClientHashCode(
                    EndpointBuilder.BuildNewEndPoint(rpcNodeConfig.HostAddress, rpcNodeConfig.Port));

            socketClientRegistry.AddClientToRegistry(clientHashCode, nodeRpcClient);

            var commands = new List <ICommand> {
                new DisconnectCommand(commandContext, Substitute.For <ILogger>())
            };
            var console = new CatalystCli(commandContext.UserOutput, commands);

            var isCommandParsed = console.ParseCommand("disconnect", "-n", "node1");

            isCommandParsed.Should().BeTrue();

            socketClientRegistry.Registry.Count.Should().Be(0);
        }
        public void GetDeltaRequest_Should_Be_Invalid_Multihash()
        {
            //Arrange
            var hash           = "test";
            var commandContext = TestCommandHelpers.GenerateCliRequestCommandContext();
            var command        = new GetDeltaCommand(commandContext, _logger);

            //Act
            TestCommandHelpers.GenerateRequest(commandContext, command, "-n", "node1", "-h", hash);

            //Assert
            commandContext.UserOutput.Received(1).WriteLine($"Unable to parse hash {hash} as a Cid");
        }
Beispiel #3
0
        public void Cannot_Connect_With_Invalid_Config()
        {
            var commandContext = TestCommandHelpers.GenerateCliCommandContext();

            commandContext.GetNodeConfig(Arg.Any <string>()).Returns((IRpcClientConfig)null);

            var commands = new List <ICommand> {
                new ConnectCommand(commandContext, _logger)
            };
            var console = new CatalystCli(commandContext.UserOutput, commands);

            var exception = Assert.Throws <ArgumentNullException>(() => console.ParseCommand("connect", "-n", "node1"));
        }
        public void GetMempoolResponse_Can_Get_Output()
        {
            //Arrange
            var getMempoolResponse = new GetMempoolResponse();
            var commandContext     = TestCommandHelpers.GenerateCliResponseCommandContext(_testScheduler);
            var getMempoolCommand  = new GetMempoolCommand(commandContext, Substitute.For <ILogger>());

            //Act
            TestCommandHelpers.GenerateResponse(commandContext, getMempoolResponse);

            _testScheduler.Start();

            //Assert
            commandContext.UserOutput.Received(1).WriteLine(getMempoolResponse.ToJsonString());
        }
        public void VerifyMessageRequest_Can_Be_Sent()
        {
            //Arrange
            var commandContext = TestCommandHelpers.GenerateCliRequestCommandContext();
            var connectedNode = commandContext.GetConnectedNode(null);
            var command = new MessageVerifyCommand(commandContext, Substitute.For<ILogger>());

            //Act
            TestCommandHelpers.GenerateRequest(commandContext, command, "-n", "node1", "-m", "hello world", "-p",
                "public key", "-s", "signature");

            //Assert
            var requestSent = TestCommandHelpers.GetRequest<VerifyMessageRequest>(connectedNode);
            requestSent.Should().BeOfType(typeof(VerifyMessageRequest));
        }
        public void GetDeltaResponse_Error_On_Null_Delta()
        {
            //Arrange
            var deltaResponse   = new GetDeltaResponse();
            var commandContext  = TestCommandHelpers.GenerateCliResponseCommandContext(_testScheduler);
            var getDeltaCommand = new GetDeltaCommand(commandContext, _logger);

            //Act
            TestCommandHelpers.GenerateResponse(commandContext, deltaResponse);

            _testScheduler.Start();

            //Assert
            commandContext.UserOutput.Received(1).WriteLine(GetDeltaCommand.UnableToRetrieveDeltaMessage);
        }
        public void AddFileToDfsResponse_No_Response_Codes()
        {
            //Arrange
            var addFileToDfsResponse = new AddFileToDfsResponse();
            var commandContext       = TestCommandHelpers.GenerateCliResponseCommandContext(_testScheduler);
            var addFileToDfsCommand  = new AddFileCommand(null, commandContext, _logger);

            //Act
            TestCommandHelpers.GenerateResponse(commandContext, addFileToDfsResponse);

            _testScheduler.Start();

            //Assert
            commandContext.UserOutput.Received(1).WriteLine(AddFileCommand.ErrorNoResponseCodes);
        }
        public void GetVersionRequest_Can_Be_Sent()
        {
            //Arrange
            var commandContext = TestCommandHelpers.GenerateCliRequestCommandContext();
            var connectedNode  = commandContext.GetConnectedNode(null);
            var command        = new GetVersionCommand(commandContext, Substitute.For <ILogger>());

            //Act
            TestCommandHelpers.GenerateRequest(commandContext, command, "-n", "node1");

            //Assert
            var requestSent = TestCommandHelpers.GetRequest <VersionRequest>(connectedNode);

            requestSent.Should().BeOfType(typeof(VersionRequest));
        }
Beispiel #9
0
        public void GetPeerBlackListingResponse_Can_Get_Output()
        {
            //Arrange
            var setPeerBlackListRequest    = new SetPeerBlacklistResponse();
            var commandContext             = TestCommandHelpers.GenerateCliResponseCommandContext(_testScheduler);
            var getPeerBlackListingCommand = new PeerBlackListingCommand(commandContext, Substitute.For <ILogger>());

            //Act
            TestCommandHelpers.GenerateResponse(commandContext, setPeerBlackListRequest);

            _testScheduler.Start();

            //Assert
            commandContext.UserOutput.Received(1).WriteLine(setPeerBlackListRequest.ToJsonString());
        }
Beispiel #10
0
        public void VerifyMessageResponse_Can_Get_Output()
        {
            //Arrange
            var verifyMessageResponse = new VerifyMessageResponse();
            var commandContext        = TestCommandHelpers.GenerateCliResponseCommandContext(_testScheduler);

            new MessageVerifyCommand(commandContext, Substitute.For <ILogger>());

            //Act
            TestCommandHelpers.GenerateResponse(commandContext, verifyMessageResponse);

            _testScheduler.Start();

            //Assert
            commandContext.UserOutput.Received(1).WriteLine(verifyMessageResponse.ToJsonString());
        }
Beispiel #11
0
        public void RemovePeerRequest_Can_Be_Sent()
        {
            //Arrange
            var commandContext = TestCommandHelpers.GenerateCliRequestCommandContext();
            var connectedNode  = commandContext.GetConnectedNode(null);
            var command        = new PeerRemoveCommand(commandContext, Substitute.For <ILogger>());

            //Act
            TestCommandHelpers.GenerateRequest(commandContext, command, "-n", "node1", "-i", "10.1.1.1", "-p",
                                               "publickey");

            //Assert
            var requestSent = TestCommandHelpers.GetRequest <RemovePeerRequest>(connectedNode);

            requestSent.Should().BeOfType(typeof(RemovePeerRequest));
        }
        public void GetDeltaResponse_Can_Get_Output()
        {
            //Arrange
            var deltaResponse = new GetDeltaResponse {
                Delta = new Delta()
            };
            var commandContext  = TestCommandHelpers.GenerateCliResponseCommandContext(_testScheduler);
            var getDeltaCommand = new GetDeltaCommand(commandContext, _logger);

            //Act
            TestCommandHelpers.GenerateResponse(commandContext, deltaResponse);

            _testScheduler.Start();

            //Assert
            commandContext.UserOutput.Received(1).WriteLine(deltaResponse.Delta.ToJsonString());
        }
        public void GetDeltaRequest_Can_Be_Sent()
        {
            //Arrange
            var hashProvider   = new HashProvider(HashingAlgorithm.GetAlgorithmMetadata("blake2b-256"));
            var deltaMultiHash = CidHelper.CreateCid(hashProvider.ComputeUtf8MultiHash("previous"));
            var commandContext = TestCommandHelpers.GenerateCliRequestCommandContext();
            var connectedNode  = commandContext.GetConnectedNode(null);
            var command        = new GetDeltaCommand(commandContext, _logger);

            //Act
            TestCommandHelpers.GenerateRequest(commandContext, command, "-n", "node1", "-h", deltaMultiHash);

            //Assert
            var requestSent = TestCommandHelpers.GetRequest <GetDeltaRequest>(connectedNode);

            requestSent.Should().BeOfType(typeof(GetDeltaRequest));
        }
Beispiel #14
0
        public void Cannot_Connect_With_Invalid_SocketChannel()
        {
            var commandContext = TestCommandHelpers.GenerateCliCommandContext();

            TestCommandHelpers.MockRpcNodeConfig(commandContext);

            var commands = new List <ICommand> {
                new ConnectCommand(commandContext, _logger)
            };
            var console = new CatalystCli(commandContext.UserOutput, commands);

            var isCommandParsed = console.ParseCommand("connect", "-n", "test");

            isCommandParsed.Should().BeFalse();

            commandContext.UserOutput.Received(1).WriteLine(ConnectCommand.InvalidSocketChannel);
        }
Beispiel #15
0
        public void GetPeerListResponse_Can_Get_Output()
        {
            var getPeerListResponse = new GetPeerListResponse();

            getPeerListResponse.Peers.Add(new PeerId());

            var commandContext = TestCommandHelpers.GenerateCliResponseCommandContext(_testScheduler);

            new PeerListCommand(commandContext, Substitute.For <ILogger>());

            //Act
            TestCommandHelpers.GenerateResponse(commandContext, getPeerListResponse);

            _testScheduler.Start();

            commandContext.UserOutput.Received(1).WriteLine(getPeerListResponse.ToJsonString());
        }
Beispiel #16
0
        public void Connect_Should_Connect_To_Node()
        {
            var commandContext = TestCommandHelpers.GenerateCliFullCommandContext();

            TestCommandHelpers.AddClientSocketRegistry(commandContext, _testScheduler);

            var commands = new List <ICommand> {
                new ConnectCommand(commandContext, _logger)
            };
            var console = new CatalystCli(commandContext.UserOutput, commands);

            var isCommandParsed = console.ParseCommand("connect", "-n", "test");

            isCommandParsed.Should().BeTrue();

            commandContext.SocketClientRegistry.Registry.Count.Should().Be(1);
            commandContext.UserOutput.Received(1)
            .WriteLine($"Connected to Node {commandContext.GetConnectedNode("test").Channel.RemoteAddress}");
        }
        public void AddFileToDfsResponse_Finished_Can_Get_Output()
        {
            //Arrange
            var addFileToDfsResponse = new AddFileToDfsResponse
            {
                ResponseCode = ByteString.CopyFrom((byte)FileTransferResponseCodeTypes.Finished.Id)
            };

            var commandContext      = TestCommandHelpers.GenerateCliResponseCommandContext(_testScheduler);
            var addFileToDfsCommand = new AddFileCommand(null, commandContext, _logger);

            //Act
            TestCommandHelpers.GenerateResponse(commandContext, addFileToDfsResponse);

            _testScheduler.Start();

            //Assert
            commandContext.UserOutput.Received(1).WriteLine("File transfer completed, Response: " +
                                                            FileTransferResponseCodeTypes.Finished.Name +
                                                            " Dfs Hash: " + addFileToDfsResponse.DfsHash);
        }