Пример #1
0
    def test_data_received(self, mock):
        node = NeoNode()
        node.endpoint = Endpoint('hello.com', 1234)
        node.host = node.endpoint.host
        node.port = node.endpoint.port
        payload = VersionPayload(10234, 1234, 'version')
        message = Message('version', payload=payload)
        stream = StreamManager.GetStream()
        writer = BinaryWriter(stream)
        message.Serialize(writer)

        out = stream.getvalue()
        node.dataReceived(out)

        mock.assert_called_once()

        self.assertEqual(node.Version.Nonce, payload.Nonce)
Пример #2
0
    def test_data_received(self, mock):

        node = NeoNode()
        node.endpoint = Endpoint('hello.com', 1234)
        node.host = node.endpoint.host
        node.port = node.endpoint.port
        payload = VersionPayload(10234, 1234, 'version')
        message = Message('version', payload=payload)
        stream = StreamManager.GetStream()
        writer = BinaryWriter(stream)
        message.Serialize(writer)

        out = stream.getvalue()
        node.dataReceived(out)

        mock.assert_called_once()

        self.assertEqual(node.Version.Nonce, payload.Nonce)
Пример #3
0
    def test_getpeers(self):
        # Given this is an isolated environment and there is no peers
        # lets simulate that at least some addresses are known
        node = NodeLeader.Instance()
        node.ADDRS = ["127.0.0.1:20333", "127.0.0.2:20334"]
        test_node = NeoNode()
        test_node.host = "127.0.0.1"
        test_node.port = 20333
        node.Peers.append(test_node)

        req = self._gen_rpc_req("getpeers", params=[])
        mock_req = mock_request(json.dumps(req).encode("utf-8"))
        res = json.loads(self.app.home(mock_req))

        self.assertEqual(len(node.Peers), len(res['result']['connected']))
        self.assertEqual(len(res['result']['unconnected']),
                         len(node.ADDRS) - len(node.Peers))
        # To avoid messing up the next tests
        node.Peers = []
        node.ADDRS = []
Пример #4
0
    def test_getpeers(self):
        # Given this is an isolated environment and there is no peers
        # lets simulate that at least some addresses are known
        node = NodeLeader.Instance()
        node.ADDRS = ["127.0.0.1:20333", "127.0.0.2:20334"]
        test_node = NeoNode()
        test_node.host = "127.0.0.1"
        test_node.port = 20333
        node.Peers.append(test_node)

        req = self._gen_rpc_req("getpeers", params=[])
        mock_req = mock_request(json.dumps(req).encode("utf-8"))
        res = json.loads(self.app.home(mock_req))

        self.assertEqual(len(node.Peers), len(res['result']['connected']))
        self.assertEqual(len(res['result']['unconnected']),
                         len(node.ADDRS) - len(node.Peers))
        # To avoid messing up the next tests
        node.Peers = []
        node.ADDRS = []
Пример #5
0
    def test_handle_message(self, mock):

        node = NeoNode()
        node.endpoint = Endpoint('hello.com', 1234)
        node.host = node.endpoint.host
        node.port = node.endpoint.port

        payload = VersionPayload(10234, 1234, 'version')

        message = Message('version', payload=payload)

        stream = StreamManager.GetStream()
        writer = BinaryWriter(stream)

        message.Serialize(writer)

        out = stream.getvalue()

        print("OUT %s " % out)

        out1 = out[0:10]
        out2 = out[10:20]
        out3 = out[20:]

        node.dataReceived(out1)
        node.dataReceived(out2)

        self.assertEqual(node.buffer_in, out1 + out2)
        #        import pdb
        #        pdb.set_trace()

        self.assertEqual(node.bytes_in, 20)

        mock.assert_not_called()

        node.dataReceived(out3)

        self.assertEqual(node.bytes_in, len(out))
        #        mock.assert_called_with(message)

        mock.assert_called_once()
Пример #6
0
    def test_handle_message(self, mock):

        node = NeoNode()
        node.endpoint = Endpoint('hello.com', 1234)
        node.host = node.endpoint.host
        node.port = node.endpoint.port

        payload = VersionPayload(10234, 1234, 'version')

        message = Message('version', payload=payload)

        stream = StreamManager.GetStream()
        writer = BinaryWriter(stream)

        message.Serialize(writer)

        out = stream.getvalue()

        print("OUT %s " % out)

        out1 = out[0:10]
        out2 = out[10:20]
        out3 = out[20:]

        node.dataReceived(out1)
        node.dataReceived(out2)

        self.assertEqual(node.buffer_in, out1 + out2)
#        import pdb
#        pdb.set_trace()

        self.assertEqual(node.bytes_in, 20)

        mock.assert_not_called()

        node.dataReceived(out3)

        self.assertEqual(node.bytes_in, len(out))
#        mock.assert_called_with(message)

        mock.assert_called_once()