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)
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)
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()
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()
def do_handshake(self, node: NeoNode): self.node = node raw_version = b"\xb1\xdd\x00\x00version\x00\x00\x00\x00\x00'\x00\x00\x00a\xbb\x9av\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x0ef\x9e[mO3\xe7q\x08\x0b/NEO:2.7.4/=\x8b\x00\x00\x01" raw_verack = b'\xb1\xdd\x00\x00verack\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00]\xf6\xe0\xe2' node.dataReceived(raw_version + raw_verack) return node