def test_getNodeInfo(self):
        with set_qrl_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            block_last_hash_str = 'c23f47a10a8c53cc5ded096369255a32c4a218682a961d0ee7db22c500000000'

            version = "1.0.0"
            num_connections = 10
            num_known_peers = 200
            uptime = 10000
            block_height = 102345
            block_last_hash = bytes(hstr2bin(block_last_hash_str))
            network_id = "network id"
            node_info = qrl_pb2.NodeInfo(version=version,
                                         num_connections=num_connections,
                                         num_known_peers=num_known_peers,
                                         uptime=uptime,
                                         block_height=block_height,
                                         block_last_hash=block_last_hash,
                                         network_id=network_id)
            walletd._public_stub.GetNodeState = Mock(
                return_value=qrl_pb2.GetNodeStateResp(info=node_info))

            resp = service.GetNodeInfo(qrlwallet_pb2.NodeInfoReq(), context=None)

            self.assertEqual(resp.version, version)
            self.assertEqual(resp.num_connections, str(num_connections))
            self.assertEqual(resp.num_known_peers, str(num_known_peers))
            self.assertEqual(resp.uptime, uptime)
            self.assertEqual(resp.block_height, block_height)
            self.assertEqual(resp.block_last_hash, block_last_hash_str)
            self.assertEqual(resp.network_id, network_id)
Beispiel #2
0
    def test_state(self, mock_stub):
        m_node_state_resp_serialized_to_string = b'\n/\n\x160.61.3+ngbd52b1a.dirty\x10\x03\x18\x02 D(\xa7\x010\x83!B\tExcession'
        m_node_state_resp = qrl_pb2.GetNodeStateResp()
        m_node_state_resp.ParseFromString(m_node_state_resp_serialized_to_string)

        mock_stub_instance = mock.MagicMock(name='this should be qrl_pb2_grpc.PublicAPIStub(channel)')
        mock_stub_instance.GetNodeState.return_value = m_node_state_resp

        mock_stub.name = 'this should be qrl_pb2_grpc.PublicAPIStub'
        mock_stub.return_value = mock_stub_instance

        result = self.runner.invoke(qrl_cli, ["state"])
        self.assertEqual(result.exit_code, 0)
        self.assertIn('Excession', result.output)
Beispiel #3
0
    def test_state_json(self, mock_stub):
        m_node_state_resp_serialized = b'\n/\n\x160.61.3+ngbd52b1a.dirty\x10\x03\x18\x02 D(\xa7\x010\x83!B\tExcession'
        m_node_state_resp = qrl_pb2.GetNodeStateResp()
        m_node_state_resp.ParseFromString(m_node_state_resp_serialized)

        mock_stub_instance = mock.MagicMock(name='this should be qrl_pb2_grpc.PublicAPIStub(channel)')
        mock_stub_instance.GetNodeState.return_value = m_node_state_resp

        mock_stub.name = 'this should be qrl_pb2_grpc.PublicAPIStub'
        mock_stub.return_value = mock_stub_instance

        result = self.runner.invoke(qrl_cli, ["--json", "state"])
        print(result.output)
        print(result.exc_info)
        self.assertEqual(result.exit_code, 0)

        the_output = json.loads(result.output)
        self.assertEqual(the_output["info"]["networkId"], "Excession")
Beispiel #4
0
 def GetNodeState(self, request: qrl_pb2.GetNodeStateReq, context) -> qrl_pb2.GetNodeStateResp:
     return qrl_pb2.GetNodeStateResp(info=self.qrlnode.getNodeInfo())
Beispiel #5
0
 def GetNodeState(self, request: qrl_pb2.GetNodeStateReq,
                  context) -> qrl_pb2.GetNodeStateResp:
     if self.context_observer is not None:
         self.context_observer(context)
     logger.debug("[GetNodeState]")
     return qrl_pb2.GetNodeStateResp(info=self.qrlnode.getNodeInfo())