Skip to content
Snippets Groups Projects
Commit 9b9925c7 authored by matograine's avatar matograine
Browse files

[enh] #301 : make `wot` and `id` commands use <pubkey:checksum> format

    * display
    * parameter
* change tests/test_wot and test_end_to_end to match new behavior

* change in choose_identity() will affect commands `cert` and `membership` display.
parent a0e01ce9
No related branches found
No related tags found
2 merge requests!146Merge dev into master branch to complete v0.8.0 development cycle,!143#301: Generalize pubkey checksum display and check
......@@ -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] + ""
......
......@@ -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
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment