From 1edf80786e5a301e48c7a79a33e1ba34e23d34e8 Mon Sep 17 00:00:00 2001
From: Moul <moul@moul.re>
Date: Fri, 14 Oct 2022 18:36:51 +0200
Subject: [PATCH] Move verify in blockchain.verify (#330)

---
 silkaj/{blocks.py => blockchain/verify.py}     |  0
 silkaj/cli.py                                  |  2 +-
 tests/blockchain/__init__.py                   | 14 ++++++++++++++
 .../test_verify.py}                            | 18 ++++++------------
 4 files changed, 21 insertions(+), 13 deletions(-)
 rename silkaj/{blocks.py => blockchain/verify.py} (100%)
 create mode 100644 tests/blockchain/__init__.py
 rename tests/{test_verify_blocks.py => blockchain/test_verify.py} (92%)

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 2e45cf09..5ec6fbb7 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 00000000..58426bbc
--- /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 4bc45556..d1ba48d2 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
-- 
GitLab