def test_blacklist(self): """ Ensures a misbehaving peer is correctly blacklisted. The remove_contact method is called and the contact's id is added to the _blacklist set. """ parent_node_id = 'abc' r = RoutingTable(parent_node_id) contact = PeerNode('abc', '192.168.0.1', 9999, 0) r.remove_contact = MagicMock() r.blacklist(contact) r.remove_contact.called_once_with(contact, True) self.assertIn(contact.network_id, r._blacklist)
def test_add_contact_with_blacklisted_contact(self): """ If the newly discovered contact is, in fact, already in the local node's blacklist then ensure it doesn't get re-added. """ parent_node_id = 'abc' r = RoutingTable(parent_node_id) contact1 = PeerNode(2, '192.168.0.1', 9999, 0) contact2 = PeerNode(4, '192.168.0.2', 9999, 0) r.blacklist(contact2) r.add_contact(contact1) self.assertEqual(len(r._buckets[0]), 1) r.add_contact(contact2) self.assertEqual(len(r._buckets[0]), 1)