Esempio n. 1
0
def main() -> None:
    from hathor.p2p.peer_id import PeerId

    peer_id = PeerId()
    data = peer_id.to_json(include_private_key=True)
    txt = json.dumps(data, indent=4)
    print(txt)
Esempio n. 2
0
 def test_create_from_json(self):
     p1 = PeerId()
     data1 = p1.to_json(include_private_key=True)
     p2 = PeerId.create_from_json(data1)
     data2 = p2.to_json(include_private_key=True)
     self.assertEqual(data1, data2)
     p2.validate()
Esempio n. 3
0
 def test_create_from_json_without_private_key(self):
     p1 = PeerId()
     data1 = p1.to_json()
     # Just to test a part of the code
     del data1['entrypoints']
     p2 = PeerId.create_from_json(data1)
     data2 = p2.to_json()
     self.assertEqual(data2['entrypoints'], [])
     data1['entrypoints'] = []
     self.assertEqual(data1, data2)
     p2.validate()
Esempio n. 4
0
    def test_save_peer_file(self):
        p = PeerId()
        tmpdir = tempfile.mkdtemp()
        path = os.path.join(tmpdir, 'peer.json')

        p.save_to_file(path)

        with open(path, 'r') as f:
            peer_from_file = json.loads(f.read())

        self.assertEqual(p.to_json(include_private_key=True), peer_from_file)

        # Removing tmpdir
        shutil.rmtree(tmpdir)