From fc97fb3ac456b6173f89e50c8aa957305f6d00ac Mon Sep 17 00:00:00 2001 From: Moul <moul@moul.re> Date: Sun, 26 Sep 2021 13:27:52 +0200 Subject: [PATCH] [mod] #376: Replace tools.message_exit() with sys.exit() except `tx` and `verify` commands which make the tests to fail checksum control --- silkaj/auth.py | 16 ++++++++-------- silkaj/cert.py | 9 ++++----- silkaj/checksum.py | 6 +++--- silkaj/money.py | 10 ++++++---- silkaj/wot_tools.py | 5 ++--- tests/patched/tx.py | 10 +++++----- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/silkaj/auth.py b/silkaj/auth.py index a659df69..b46dfa32 100644 --- a/silkaj/auth.py +++ b/silkaj/auth.py @@ -14,6 +14,7 @@ # along with Silkaj. If not, see <https://www.gnu.org/licenses/>. import re +import sys from getpass import getpass from pathlib import Path @@ -22,7 +23,6 @@ from duniterpy.key import SigningKey from duniterpy.key.scrypt_params import ScryptParams from silkaj.constants import PUBKEY_PATTERN -from silkaj.tools import message_exit from silkaj.tui import display_pubkey_and_checksum SEED_HEX_PATTERN = "^[0-9a-fA-F]{64}$" @@ -86,7 +86,7 @@ def auth_by_auth_file(ctx): file = ctx.obj["AUTH_FILE_PATH"] authfile = Path(file) if not authfile.is_file(): - message_exit('Error: the file "' + file + '" does not exist') + sys.exit('Error: the file "' + file + '" does not exist') filetxt = authfile.open("r").read() # two regural expressions for the PubSec format @@ -100,7 +100,7 @@ def auth_by_auth_file(ctx): elif re.search(regex_pubkey, filetxt) and re.search(regex_signkey, filetxt): return SigningKey.from_pubsec_file(file) else: - message_exit("Error: the format of the file is invalid") + sys.exit("Error: the format of the file is invalid") def auth_by_seed(): @@ -108,7 +108,7 @@ def auth_by_seed(): try: return SigningKey.from_seedhex(seedhex) except Exception as error: - message_exit(error) + sys.exit(error) @pass_context @@ -122,17 +122,17 @@ def auth_by_scrypt(ctx): if n.isnumeric() and r.isnumeric() and p.isnumeric(): n, r, p = int(n), int(r), int(p) if n <= 0 or n > 65536 or r <= 0 or r > 512 or p <= 0 or p > 32: - message_exit("Error: the values of Scrypt parameters are not good") + sys.exit("Error: the values of Scrypt parameters are not good") scrypt_params = ScryptParams(n, r, p) else: - message_exit("one of n, r or p is not a number") + sys.exit("one of n, r or p is not a number") else: scrypt_params = None try: return SigningKey.from_credentials(salt, password, scrypt_params) except ValueError as error: - message_exit(error) + sys.exit(error) def auth_by_wif(): @@ -143,4 +143,4 @@ def auth_by_wif(): try: return SigningKey.from_wif_or_ewif_hex(wif_hex, password) except Exception as error: - message_exit(error) + sys.exit(error) diff --git a/silkaj/cert.py b/silkaj/cert.py index 8ed380f2..de07e2ec 100644 --- a/silkaj/cert.py +++ b/silkaj/cert.py @@ -29,7 +29,6 @@ from silkaj.constants import ALL, DATE, SUCCESS_EXIT_STATUS from silkaj.crypto_tools import is_pubkey_and_check from silkaj.license import license_approval from silkaj.network_tools import ClientInstance, send_document -from silkaj.tools import message_exit @click.command("cert", help="Send certification") @@ -84,10 +83,10 @@ def pre_checks(client, issuer_pubkey, pubkey_to_certify): # Check whether current user is member issuer = wt.is_member(issuer_pubkey) if not issuer: - message_exit("Current identity is not member.") + sys.exit("Current identity is not member.") if issuer_pubkey == pubkey_to_certify: - message_exit("You can’t certify yourself!") + sys.exit("You can’t certify yourself!") # Check if the certification can be renewed req = client(bma.wot.requirements, pubkey_to_certify) @@ -100,12 +99,12 @@ def pre_checks(client, issuer_pubkey, pubkey_to_certify): renewable = cert["expiresIn"] - params["sigValidity"] + params["sigReplay"] if renewable > 0: renewable_date = now().add(seconds=renewable).format(DATE) - message_exit("Certification renewable from " + renewable_date) + sys.exit("Certification renewable from " + renewable_date) # Check if the certification is already in the pending certifications for pending_cert in req["pendingCerts"]: if pending_cert["from"] == issuer_pubkey: - message_exit("Certification is currently been processed") + sys.exit("Certification is currently been processed") return issuer diff --git a/silkaj/checksum.py b/silkaj/checksum.py index 71c85d25..85da7eee 100644 --- a/silkaj/checksum.py +++ b/silkaj/checksum.py @@ -14,6 +14,7 @@ # along with Silkaj. If not, see <https://www.gnu.org/licenses/>. import re +import sys import click @@ -23,7 +24,6 @@ from silkaj.crypto_tools import ( PUBKEY_DELIMITED_PATTERN, gen_checksum, ) -from silkaj.tools import message_exit from silkaj.tui import display_pubkey_and_checksum MESSAGE = "You should specify a pubkey or an authentication method" @@ -41,7 +41,7 @@ def checksum_command(pubkey_checksum): click.echo(display_pubkey_and_checksum(key.pubkey)) else: if not pubkey_checksum: - message_exit(MESSAGE) + sys.exit(MESSAGE) elif re.search(re.compile(PUBKEY_DELIMITED_PATTERN), pubkey_checksum[0]): click.echo(display_pubkey_and_checksum(pubkey_checksum[0])) elif re.search(re.compile(PUBKEY_CHECKSUM_PATTERN), pubkey_checksum[0]): @@ -51,4 +51,4 @@ def checksum_command(pubkey_checksum): else: click.echo("The checksum is invalid") else: - message_exit("Error: Wrong public key format") + sys.exit("Error: Wrong public key format") diff --git a/silkaj/money.py b/silkaj/money.py index b53fd7ab..b23f9ad3 100644 --- a/silkaj/money.py +++ b/silkaj/money.py @@ -13,6 +13,8 @@ # You should have received a copy of the GNU Affero General Public License # along with Silkaj. If not, see <https://www.gnu.org/licenses/>. +import sys + from click import argument, command, echo, pass_context from duniterpy.api.bma import blockchain, tx from duniterpy.documents.transaction import InputSource @@ -27,7 +29,7 @@ from silkaj.crypto_tools import ( validate_checksum, ) from silkaj.network_tools import ClientInstance -from silkaj.tools import CurrencySymbol, message_exit +from silkaj.tools import CurrencySymbol from silkaj.tui import display_amount, display_pubkey_and_checksum @@ -39,7 +41,7 @@ def cmd_amount(ctx, pubkeys): # check input pubkeys if not pubkeys: - message_exit("You should specify one or many pubkeys") + sys.exit("You should specify one or many pubkeys") pubkeys_list = list() wrong_pubkeys = False for inputPubkey in pubkeys: @@ -48,12 +50,12 @@ def cmd_amount(ctx, pubkeys): wrong_pubkeys = True print(f"ERROR: pubkey {inputPubkey} has a wrong format") elif pubkey in pubkeys_list: - message_exit( + sys.exit( f"ERROR: pubkey {display_pubkey_and_checksum(pubkey)} was specified many times" ) pubkeys_list.append(pubkey) if wrong_pubkeys: - message_exit("Please check the pubkeys format.") + sys.exit("Please check the pubkeys format.") total = [0, 0] for pubkey in pubkeys_list: diff --git a/silkaj/wot_tools.py b/silkaj/wot_tools.py index 2c2d72d2..a34c5509 100644 --- a/silkaj/wot_tools.py +++ b/silkaj/wot_tools.py @@ -19,7 +19,6 @@ from duniterpy.api.bma import wot from duniterpy.api.errors import DuniterError from silkaj.network_tools import ClientInstance -from silkaj.tools import message_exit def identity_of(pubkey_uid): @@ -57,9 +56,9 @@ def wot_lookup(identifier): results = client(wot.lookup, identifier) return results["results"] except DuniterError as e: - message_exit(e.message) + sys.exit(e.message) except urllib.error.HTTPError as e: - message_exit(e) + sys.exit(e) def identities_from_pubkeys(pubkeys, uids): diff --git a/tests/patched/tx.py b/tests/patched/tx.py index 18160c16..2750abc0 100644 --- a/tests/patched/tx.py +++ b/tests/patched/tx.py @@ -13,9 +13,9 @@ # You should have received a copy of the GNU Affero General Public License # along with Silkaj. If not, see <https://www.gnu.org/licenses/>. -from duniterpy.key import SigningKey +import sys -from silkaj.tools import message_exit +from duniterpy.key import SigningKey def patched_gen_confirmation_table( @@ -38,7 +38,7 @@ def patched_gen_confirmation_table( and len(tx_amounts) == len(outputAddresses) and sum(tx_amounts) <= pubkey_amount ): - message_exit( + sys.exit( "Test error : patched_transaction_confirmation() : Parameters are not coherent" ) @@ -63,7 +63,7 @@ def patched_handle_intermediaries_transactions( and len(tx_amounts) == len(outputAddresses) and key.pubkey() == issuers ): - message_exit( + sys.exit( "Test error : patched_handle_intermediaries_transactions() : Parameters are not coherent" ) @@ -91,7 +91,7 @@ def patched_generate_and_send_transaction( and sum(tx_amounts) <= listinput_and_amount[2] and key.pubkey() == issuers ): - message_exit( + sys.exit( "Test error : patched_generate_and_send_transaction() : Parameters are not coherent" ) pass -- GitLab