def test_get_contact_with_bad_id(self): """ Ensures a ValueError exception is raised if one attempts to get a contact from the k-bucket with an id that doesn't exist in the k-bucket. """ range_min = 12345 range_max = 98765 bucket = Bucket(range_min, range_max) contact = PeerNode("12345", "192.168.0.2", 8888, 123) bucket.add_contact(contact) with self.assertRaises(ValueError): bucket.get_contact("54321")
def test_get_contact(self): """ Ensures it is possible to get a contact from the k-bucket with a valid id. """ range_min = 12345 range_max = 98765 bucket = Bucket(range_min, range_max) for i in range(K): contact = PeerNode(PUBLIC_KEY, "192.168.0.%d" % i, 9999, 123) contact.network_id = hex(i) bucket.add_contact(contact) for i in range(K): self.assertTrue(bucket.get_contact(hex(i)), "Could not get contact with id %d" % i)