Skip to content
Snippets Groups Projects
Commit 415d829b authored by matograine's avatar matograine
Browse files

[mod] #301 : create function display_pubkey_and_checksum()

    and related tests
parent c919f8f7
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
...@@ -29,3 +29,4 @@ BMA_MAX_BLOCKS_CHUNK_SIZE = 5000 ...@@ -29,3 +29,4 @@ BMA_MAX_BLOCKS_CHUNK_SIZE = 5000
PUBKEY_PATTERN = "[1-9A-HJ-NP-Za-km-z]{43,44}" PUBKEY_PATTERN = "[1-9A-HJ-NP-Za-km-z]{43,44}"
MINIMAL_TX_AMOUNT = 0.01 MINIMAL_TX_AMOUNT = 0.01
CENT_MULT_TO_UNIT = 100 CENT_MULT_TO_UNIT = 100
SHORT_PUBKEY_SIZE = 8
...@@ -18,6 +18,8 @@ along with Silkaj. If not, see <https://www.gnu.org/licenses/>. ...@@ -18,6 +18,8 @@ along with Silkaj. If not, see <https://www.gnu.org/licenses/>.
from datetime import datetime from datetime import datetime
from silkaj import wot from silkaj import wot
from silkaj import crypto_tools as ct
from silkaj.constants import SHORT_PUBKEY_SIZE
def display_amount(tx, message, amount, ud_value, currency_symbol): def display_amount(tx, message, amount, ud_value, currency_symbol):
...@@ -47,6 +49,16 @@ async def display_pubkey(tx, message, pubkey): ...@@ -47,6 +49,16 @@ async def display_pubkey(tx, message, pubkey):
tx.append([message + " (id)", id["uid"]]) tx.append([message + " (id)", id["uid"]])
def display_pubkey_and_checksum(pubkey, short=False, length=SHORT_PUBKEY_SIZE):
"""
Returns "<pubkey>:<checksum>" in full form.
returns `length` first chars of pubkey and checksum in short form.
`length` defaults to SHORT_PUBKEY_SIZE.
"""
short_pubkey = pubkey[:length] + "" if short else pubkey
return short_pubkey + ":" + ct.gen_checksum(pubkey)
def convert_time(timestamp, kind): def convert_time(timestamp, kind):
ts = int(timestamp) ts = int(timestamp)
date = "%Y-%m-%d" date = "%Y-%m-%d"
......
...@@ -16,8 +16,8 @@ along with Silkaj. If not, see <https://www.gnu.org/licenses/>. ...@@ -16,8 +16,8 @@ along with Silkaj. If not, see <https://www.gnu.org/licenses/>.
""" """
import pytest import pytest
from silkaj.tui import display_pubkey, display_amount from silkaj.tui import display_pubkey, display_amount, display_pubkey_and_checksum
from silkaj.constants import G1_SYMBOL from silkaj.constants import G1_SYMBOL, SHORT_PUBKEY_SIZE
import patched import patched
...@@ -63,3 +63,20 @@ async def test_display_pubkey(message, pubkey, id, monkeypatch): ...@@ -63,3 +63,20 @@ async def test_display_pubkey(message, pubkey, id, monkeypatch):
tx = list() tx = list()
await display_pubkey(tx, message, pubkey) await display_pubkey(tx, message, pubkey)
assert tx == expected assert tx == expected
# display_pubkey_and_checksum
@pytest.mark.parametrize(
"pubkey, checksum",
[
("J4c8CARmP9vAFNGtHRuzx14zvxojyRWHW2darguVqjtX", "KAv"),
],
)
def test_display_pubkey_and_checksum(pubkey, checksum):
assert pubkey + ":" + checksum == display_pubkey_and_checksum(pubkey)
assert pubkey[:SHORT_PUBKEY_SIZE] + "…:" + checksum == display_pubkey_and_checksum(
pubkey, short=True
)
assert pubkey[:14] + "…:" + checksum == display_pubkey_and_checksum(
pubkey, short=True, length=14
)
...@@ -26,7 +26,11 @@ from silkaj.tx import ( ...@@ -26,7 +26,11 @@ from silkaj.tx import (
) )
from silkaj.tui import display_pubkey, display_amount from silkaj.tui import display_pubkey, display_amount
from silkaj.money import UDValue from silkaj.money import UDValue
from silkaj.constants import G1_SYMBOL, CENT_MULT_TO_UNIT, MINIMAL_TX_AMOUNT from silkaj.constants import (
G1_SYMBOL,
CENT_MULT_TO_UNIT,
MINIMAL_TX_AMOUNT,
)
from duniterpy.documents.transaction import ( from duniterpy.documents.transaction import (
InputSource, InputSource,
Transaction, Transaction,
......
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