diff --git a/silkaj/wot.py b/silkaj/wot.py index 25a029d67b82a4f78fac73fe904d5f248f201162..ddbe2a16d04fba17401dabab4b5c6bdc0e2fd17b 100644 --- a/silkaj/wot.py +++ b/silkaj/wot.py @@ -26,7 +26,7 @@ from duniterpy.api.errors import DuniterError from silkaj.network_tools import ClientInstance from silkaj.crypto_tools import is_pubkey_and_check from silkaj.tools import message_exit, coroutine -from silkaj.tui import convert_time +from silkaj.tui import convert_time, display_pubkey_and_checksum from silkaj.blockchain_tools import BlockchainParams from silkaj.constants import ASYNC_SLEEP @@ -60,6 +60,11 @@ async def received_sent_certifications(uid_pubkey): client = ClientInstance().client first_block = await client(blockchain.block, 1) time_first_block = first_block["time"] + + checked_pubkey = is_pubkey_and_check(uid_pubkey) + if checked_pubkey: + uid_pubkey = checked_pubkey + identity, pubkey, signed = await choose_identity(uid_pubkey) certifications = OrderedDict() params = await BlockchainParams().params @@ -84,7 +89,7 @@ async def received_sent_certifications(uid_pubkey): print( "{0} ({1}) from block #{2}\nreceived {3} and sent {4}/{5} certifications:\n{6}\n{7}\n".format( identity["uid"], - pubkey[:5] + "…", + display_pubkey_and_checksum(pubkey, True), identity["meta"]["timestamp"][:15] + "…", len(certifications["received"]), nbr_sent_certs, @@ -167,7 +172,7 @@ async def id_pubkey_correspondence(id_pubkey): idty = await identity_of(id_pubkey) print( "{} public key corresponds to identity: {}".format( - id_pubkey, idty["uid"] + display_pubkey_and_checksum(id_pubkey), idty["uid"] ) ) except: @@ -177,7 +182,7 @@ async def id_pubkey_correspondence(id_pubkey): pubkeys = await wot_lookup(id_pubkey) print("Public keys found matching '{}':\n".format(id_pubkey)) for pubkey in pubkeys: - print("→", pubkey["pubkey"], end=" ") + print("→", display_pubkey_and_checksum(pubkey["pubkey"]), end=" ") try: corresponding_id = await client(wot.identity_of, pubkey["pubkey"]) print("↔ " + corresponding_id["uid"]) @@ -200,7 +205,9 @@ async def choose_identity(pubkey_uid): for pubkey_index, lookup in enumerate(lookups): for uid_index, identity in enumerate(lookup["uids"]): identities_choices["id"].append(str(pubkey_index) + str(uid_index)) - identities_choices["pubkey"].append(lookup["pubkey"]) + identities_choices["pubkey"].append( + display_pubkey_and_checksum(lookup["pubkey"]) + ) identities_choices["uid"].append(identity["uid"]) identities_choices["timestamp"].append( identity["meta"]["timestamp"][:20] + "…" diff --git a/tests/test_end_to_end.py b/tests/test_end_to_end.py index 3c8fa3064ffdc3e5b36bafc4070b5bae8d032f71..b5e340275acec70e3f79d668842cfc1f8d31364f 100644 --- a/tests/test_end_to_end.py +++ b/tests/test_end_to_end.py @@ -31,7 +31,7 @@ def test_wot(): """tests 'silkaj wot' returns a number of members""" output = check_output(silkaj + ["wot", "moul"]).decode() - assert "moul (GfKER…) from block #0-E3B0C44298FC1…" in output + assert "moul (GfKERHnJ…:J1k) from block #0-E3B0C44298FC1…" in output assert "received_expire" in output assert "received" in output assert "sent" in output diff --git a/tests/test_wot.py b/tests/test_wot.py index a4789a38206d13710c911ed857d071478c685182..9f05df3f11555ee81f90621396ebc550b7625a8d 100644 --- a/tests/test_wot.py +++ b/tests/test_wot.py @@ -24,6 +24,8 @@ from silkaj import wot pubkey_titi_tata = "B4RoF48cTxzmsQDB3UjodKdZ2cVymKSKzgiPVRoMeA88" pubkey_toto_tutu = "totoF48cTxzmsQDB3UjodKdZ2cVymKSKzgiPVRoMeA88" +pubkey_titi_tata_checksum = "B4RoF48cTxzmsQDB3UjodKdZ2cVymKSKzgiPVRoMeA88:9iP" + def identity_card(uid, timestamp): return { @@ -135,6 +137,7 @@ def patched_prompt_tutu(message): "selected_uid, pubkey, patched_prompt, patched_lookup", [ ("titi", pubkey_titi_tata, patched_prompt_titi, patched_lookup_one), + ("titi", pubkey_titi_tata_checksum, patched_prompt_titi, patched_lookup_one), ("tata", pubkey_titi_tata, patched_prompt_tata, patched_lookup_two), ("toto", pubkey_toto_tutu, patched_prompt_toto, patched_lookup_three), ("tutu", pubkey_toto_tutu, patched_prompt_tutu, patched_lookup_four), @@ -148,7 +151,8 @@ async def test_choose_identity( monkeypatch.setattr(wot, "wot_lookup", patched_lookup) monkeypatch.setattr(click, "prompt", patched_prompt) identity_card, get_pubkey, signed = await wot.choose_identity(pubkey) - assert pubkey == get_pubkey + expected_pubkey = pubkey.split(":")[0] + assert expected_pubkey == get_pubkey assert selected_uid == identity_card["uid"] # Check whether the table is not displayed in case of one identity