diff --git a/silkaj/blocks.py b/silkaj/blockchain/verify.py similarity index 100% rename from silkaj/blocks.py rename to silkaj/blockchain/verify.py diff --git a/silkaj/cli.py b/silkaj/cli.py index 2e45cf097076b9f1c240ad08d79cf1c410ebeaa2..5ec6fbb75c5c66b6da3185382a81587e57c2d6a9 100644 --- a/silkaj/cli.py +++ b/silkaj/cli.py @@ -23,7 +23,7 @@ from silkaj.auth import generate_auth_file from silkaj.blockchain.blocks import list_blocks from silkaj.blockchain.difficulty import difficulties from silkaj.blockchain.information import argos_info, currency_info -from silkaj.blocks import verify_blocks_signatures +from silkaj.blockchain.verify import verify_blocks_signatures from silkaj.cert import send_certification from silkaj.checksum import checksum_command from silkaj.constants import ( diff --git a/tests/blockchain/__init__.py b/tests/blockchain/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..58426bbc2bbfc951dc181bdd19b5b2569c074af0 --- /dev/null +++ b/tests/blockchain/__init__.py @@ -0,0 +1,14 @@ +# Copyright 2016-2022 Maël Azimi <m.a@moul.re> +# +# Silkaj is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Silkaj is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Silkaj. If not, see <https://www.gnu.org/licenses/>. diff --git a/tests/test_verify_blocks.py b/tests/blockchain/test_verify.py similarity index 92% rename from tests/test_verify_blocks.py rename to tests/blockchain/test_verify.py index 4bc455564aa250a44ac198934c9ce2cecf848074..d1ba48d291bf82d013e50df5f8894e592679513d 100644 --- a/tests/test_verify_blocks.py +++ b/tests/blockchain/test_verify.py @@ -19,13 +19,7 @@ from duniterpy.api import bma from duniterpy.documents import Block from silkaj import cli -from silkaj.blocks import ( - check_passed_blocks_range, - display_result, - get_chunk, - get_chunk_size, - verify_block_signature, -) +from silkaj.blockchain import verify from silkaj.constants import ( BMA_MAX_BLOCKS_CHUNK_SIZE, FAILURE_EXIT_STATUS, @@ -49,7 +43,7 @@ def test_check_passed_blocks_range(from_block, to_block, capsys, monkeypatch): client = client_instance() # https://medium.com/python-pandemonium/testing-sys-exit-with-pytest-10c6e5f7726f with pytest.raises(SystemExit) as pytest_wrapped_e: - check_passed_blocks_range(client, from_block, to_block) + verify.check_passed_blocks_range(client, from_block, to_block) assert pytest_wrapped_e.type == SystemExit assert pytest_wrapped_e.value.code == FAILURE_EXIT_STATUS captured = capsys.readouterr() @@ -94,7 +88,7 @@ def test_verify_blocks_signatures(from_block, to_block, monkeypatch): ], ) def test_get_chunk_size(from_block, to_block, chunks_from, chunk_from): - chunk_size = get_chunk_size(from_block, to_block, chunks_from, chunk_from) + chunk_size = verify.get_chunk_size(from_block, to_block, chunks_from, chunk_from) if chunk_from != chunks_from[-1]: assert chunk_size == BMA_MAX_BLOCKS_CHUNK_SIZE else: @@ -104,7 +98,7 @@ def test_get_chunk_size(from_block, to_block, chunks_from, chunk_from): @pytest.mark.parametrize("chunk_size, chunk_from", [(2, 1), (5, 10)]) def test_get_chunks(chunk_size, chunk_from): client = client_instance() - chunk = get_chunk(client, chunk_size, chunk_from) + chunk = verify.get_chunk(client, chunk_size, chunk_from) assert chunk[0]["number"] + chunk_size - 1 == chunk[-1]["number"] @@ -141,7 +135,7 @@ def test_verify_block_signature(signature, block_raw): # Check with valid and non-valid signatures block invalid_signatures_blocks = [] block = Block.from_signed_raw(block_raw + signature + "\n") - verify_block_signature(invalid_signatures_blocks, block) + verify.verify_block_signature(invalid_signatures_blocks, block) if block.number == G1_INVALID_BLOCK_SIG: assert invalid_signatures_blocks == [block.number] else: @@ -159,6 +153,6 @@ def test_display_result(from_block, to_block, invalid_blocks_signatures, capsys) expected += " ".join(str(n) for n in invalid_blocks_signatures) else: expected += "no blocks with a wrong signature." - display_result(from_block, to_block, invalid_blocks_signatures) + verify.display_result(from_block, to_block, invalid_blocks_signatures) captured = capsys.readouterr() assert expected + "\n" == captured.out