Skip to content
Snippets Groups Projects
Commit 6c7c20ad authored by Moul's avatar Moul
Browse files

Fix blockchain.tools.get_currency() patching

The f() shouldn’t be imported if we want to have it patched
Introduce new mocks
parent 3c06d603
Branches
Tags
1 merge request!277Account storage support: authentication, revocation (#477)
Pipeline #40304 passed
...@@ -27,7 +27,7 @@ from duniterpy.key.verifying_key import VerifyingKey ...@@ -27,7 +27,7 @@ from duniterpy.key.verifying_key import VerifyingKey
from silkaj import auth, network, tui from silkaj import auth, network, tui
from silkaj.account_storage import AccountStorage 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.constants import FAILURE_EXIT_STATUS, SUCCESS_EXIT_STATUS
from silkaj.public_key import gen_pubkey_checksum from silkaj.public_key import gen_pubkey_checksum
from silkaj.wot import idty_tools from silkaj.wot import idty_tools
...@@ -36,7 +36,7 @@ from silkaj.wot import tools as w_tools ...@@ -36,7 +36,7 @@ from silkaj.wot import tools as w_tools
@click.command("create", help="Create and save a revocation document") @click.command("create", help="Create and save a revocation document")
def create() -> None: def create() -> None:
currency = get_currency() currency = bc_tools.get_currency()
key = auth.auth_method() key = auth.auth_method()
gen_pubkey_checksum(key.pubkey) gen_pubkey_checksum(key.pubkey)
...@@ -62,7 +62,7 @@ def create() -> None: ...@@ -62,7 +62,7 @@ def create() -> None:
) )
@click.pass_context @click.pass_context
def revoke_now(ctx: click.Context) -> None: def revoke_now(ctx: click.Context) -> None:
currency = get_currency() currency = bc_tools.get_currency()
warn_before_dry_run_or_display(ctx) warn_before_dry_run_or_display(ctx)
......
...@@ -59,3 +59,11 @@ def patched_get_head_block(): ...@@ -59,3 +59,11 @@ def patched_get_head_block():
def patched_get_head_block_gtest(): def patched_get_head_block_gtest():
return mocked_block_gtest return mocked_block_gtest
def patched_get_currency():
return currency
def patched_get_currency_gtest():
return "g1-test"
...@@ -20,12 +20,14 @@ import pytest ...@@ -20,12 +20,14 @@ import pytest
from click.testing import CliRunner from click.testing import CliRunner
from silkaj import auth, cli from silkaj import auth, cli
from silkaj.blockchain import tools
from tests.patched.auth import ( from tests.patched.auth import (
patched_auth_by_auth_file, patched_auth_by_auth_file,
patched_auth_by_scrypt, patched_auth_by_scrypt,
patched_auth_by_seed, patched_auth_by_seed,
patched_auth_by_wif, patched_auth_by_wif,
) )
from tests.patched.blockchain_tools import patched_get_currency
@pytest.mark.parametrize( @pytest.mark.parametrize(
...@@ -62,6 +64,7 @@ def test_authentication_cmd_cli(account, monkeypatch): ...@@ -62,6 +64,7 @@ def test_authentication_cmd_cli(account, monkeypatch):
patched_auth_options = Mock() patched_auth_options = Mock()
monkeypatch.setattr(auth, "auth_options", patched_auth_options) monkeypatch.setattr(auth, "auth_options", patched_auth_options)
monkeypatch.setattr(Path, "mkdir", Mock) monkeypatch.setattr(Path, "mkdir", Mock)
monkeypatch.setattr(tools, "get_currency", patched_get_currency)
command = build_authentication_cmd(account) command = build_authentication_cmd(account)
result = CliRunner().invoke(cli.cli, args=command) result = CliRunner().invoke(cli.cli, args=command)
......
...@@ -33,7 +33,10 @@ from silkaj.public_key import gen_pubkey_checksum ...@@ -33,7 +33,10 @@ from silkaj.public_key import gen_pubkey_checksum
from silkaj.wot import idty_tools, revocation from silkaj.wot import idty_tools, revocation
from silkaj.wot import tools as w_tools from silkaj.wot import tools as w_tools
from tests.patched.auth import patched_auth_method 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 from tests.patched.idty_tools import idty1, idty2, idty_block, lookup_one, lookup_two
REVOCATION_PATH = Path("revocation.txt") REVOCATION_PATH = Path("revocation.txt")
...@@ -662,7 +665,7 @@ def test_revocation_cli_revoke( ...@@ -662,7 +665,7 @@ def test_revocation_cli_revoke(
monkeypatch, monkeypatch,
): ):
monkeypatch.setattr(auth, "auth_method", patched_auth_method_Claude) 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(w_tools, "choose_identity", patched_choose_identity)
monkeypatch.setattr(bma.blockchain, "block", patch_get_id_block) monkeypatch.setattr(bma.blockchain, "block", patch_get_id_block)
patched_send_bma_revoke = Mock() patched_send_bma_revoke = Mock()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment