From 6c7c20ad59027430d3062b2d6c1cf549ee162f2f Mon Sep 17 00:00:00 2001 From: Moul <moul@moul.re> Date: Mon, 7 Apr 2025 11:54:15 +0200 Subject: [PATCH] Fix blockchain.tools.get_currency() patching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The f() shouldn’t be imported if we want to have it patched Introduce new mocks --- silkaj/wot/revocation.py | 6 +++--- tests/patched/blockchain_tools.py | 8 ++++++++ tests/unit/test_auth.py | 3 +++ tests/unit/wot/test_revocation.py | 7 +++++-- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/silkaj/wot/revocation.py b/silkaj/wot/revocation.py index b824fceb..c3e5ecb9 100644 --- a/silkaj/wot/revocation.py +++ b/silkaj/wot/revocation.py @@ -27,7 +27,7 @@ from duniterpy.key.verifying_key import VerifyingKey from silkaj import auth, network, tui from silkaj.account_storage import AccountStorage -from silkaj.blockchain.tools import get_currency +from silkaj.blockchain import tools as bc_tools from silkaj.constants import FAILURE_EXIT_STATUS, SUCCESS_EXIT_STATUS from silkaj.public_key import gen_pubkey_checksum from silkaj.wot import idty_tools @@ -36,7 +36,7 @@ from silkaj.wot import tools as w_tools @click.command("create", help="Create and save a revocation document") def create() -> None: - currency = get_currency() + currency = bc_tools.get_currency() key = auth.auth_method() gen_pubkey_checksum(key.pubkey) @@ -62,7 +62,7 @@ def create() -> None: ) @click.pass_context def revoke_now(ctx: click.Context) -> None: - currency = get_currency() + currency = bc_tools.get_currency() warn_before_dry_run_or_display(ctx) diff --git a/tests/patched/blockchain_tools.py b/tests/patched/blockchain_tools.py index ed7b4c03..39fc9984 100644 --- a/tests/patched/blockchain_tools.py +++ b/tests/patched/blockchain_tools.py @@ -59,3 +59,11 @@ def patched_get_head_block(): def patched_get_head_block_gtest(): return mocked_block_gtest + + +def patched_get_currency(): + return currency + + +def patched_get_currency_gtest(): + return "g1-test" diff --git a/tests/unit/test_auth.py b/tests/unit/test_auth.py index 969765a9..a98acfd5 100644 --- a/tests/unit/test_auth.py +++ b/tests/unit/test_auth.py @@ -20,12 +20,14 @@ import pytest from click.testing import CliRunner from silkaj import auth, cli +from silkaj.blockchain import tools from tests.patched.auth import ( patched_auth_by_auth_file, patched_auth_by_scrypt, patched_auth_by_seed, patched_auth_by_wif, ) +from tests.patched.blockchain_tools import patched_get_currency @pytest.mark.parametrize( @@ -62,6 +64,7 @@ def test_authentication_cmd_cli(account, monkeypatch): patched_auth_options = Mock() monkeypatch.setattr(auth, "auth_options", patched_auth_options) monkeypatch.setattr(Path, "mkdir", Mock) + monkeypatch.setattr(tools, "get_currency", patched_get_currency) command = build_authentication_cmd(account) result = CliRunner().invoke(cli.cli, args=command) diff --git a/tests/unit/wot/test_revocation.py b/tests/unit/wot/test_revocation.py index 20e0c6f5..c6deb829 100644 --- a/tests/unit/wot/test_revocation.py +++ b/tests/unit/wot/test_revocation.py @@ -33,7 +33,10 @@ from silkaj.public_key import gen_pubkey_checksum from silkaj.wot import idty_tools, revocation from silkaj.wot import tools as w_tools from tests.patched.auth import patched_auth_method -from tests.patched.blockchain_tools import patched_get_head_block_gtest +from tests.patched.blockchain_tools import ( + patched_get_currency_gtest, + patched_get_head_block_gtest, +) from tests.patched.idty_tools import idty1, idty2, idty_block, lookup_one, lookup_two REVOCATION_PATH = Path("revocation.txt") @@ -662,7 +665,7 @@ def test_revocation_cli_revoke( monkeypatch, ): monkeypatch.setattr(auth, "auth_method", patched_auth_method_Claude) - monkeypatch.setattr(bc_tools, "get_head_block", patched_get_head_block_gtest) + monkeypatch.setattr(bc_tools, "get_currency", patched_get_currency_gtest) monkeypatch.setattr(w_tools, "choose_identity", patched_choose_identity) monkeypatch.setattr(bma.blockchain, "block", patch_get_id_block) patched_send_bma_revoke = Mock() -- GitLab