def test_merge_peer(self): # Testing peer storage with merge of peers peer_storage = PeerStorage() p1 = PeerId() p2 = PeerId() p2.id = p1.id p2.public_key = p1.public_key p1.public_key = '' peer_storage.add_or_merge(p1) self.assertEqual(len(peer_storage), 1) peer_storage.add_or_merge(p2) peer = peer_storage[p1.id] self.assertEqual(peer.id, p1.id) self.assertEqual(peer.private_key, p1.private_key) self.assertEqual(peer.public_key, p1.public_key) self.assertEqual(peer.entrypoints, []) p3 = PeerId() p3.entrypoints.append('1') p3.entrypoints.append('3') p3.public_key = '' p4 = PeerId() p4.public_key = '' p4.private_key = '' p4.id = p3.id p4.entrypoints.append('2') p4.entrypoints.append('3') peer_storage.add_or_merge(p4) self.assertEqual(len(peer_storage), 2) peer_storage.add_or_merge(p3) self.assertEqual(len(peer_storage), 2) peer = peer_storage[p3.id] self.assertEqual(peer.id, p3.id) self.assertEqual(peer.private_key, p3.private_key) self.assertEqual(peer.entrypoints, ['2', '3', '1']) with self.assertRaises(ValueError): peer_storage.add(p1)
def test_invalid_public_key(self): p1 = PeerId() p2 = PeerId() p1.public_key = p2.public_key self.assertRaises(InvalidPeerIdException, p1.validate)