Repository: 0xSpaceShard/starknet-devnet (language: python)

Issue:
Apply pytest parametrization where possible
Candidates found:
- In `test_block_number.py`, common logic is extracted into `base_workflow` and used by `test_block_number_incremented` and `test_block_number_incremented_in_lite_mode`

Parametrization is already applied in some rpc tests.


Discussion / hints:
I put the `help wanted` label because anyone can add a parametrization candidate to this thread.

Fix patch:
diff --git a/scripts/format.sh b/scripts/format.sh
old mode 100755
new mode 100644


Test patch:
diff --git a/test/conftest.py b/test/conftest.py
new file mode 100644
index 000000000..90a5f28ca
--- /dev/null
+++ b/test/conftest.py
@@ -0,0 +1,22 @@
+"""
+Fixtures for tests
+"""
+
+from __future__ import annotations
+
+from test.util import run_devnet_in_background, terminate_and_wait
+
+import pytest
+
+
+@pytest.fixture(name="run_devnet_in_background")
+def fixture_run_devnet_in_background(request) -> None:
+    """
+    Run devnet instance in background
+    """
+    args = getattr(request, "param", [])
+    proc = run_devnet_in_background(*args)
+    try:
+        yield
+    finally:
+        terminate_and_wait(proc)
diff --git a/test/rpc/conftest.py b/test/rpc/conftest.py
index 79a9bdd5f..5cd249b82 100644
--- a/test/rpc/conftest.py
+++ b/test/rpc/conftest.py
@@ -7,7 +7,7 @@
 import json
 import typing
 
-from test.util import load_file_content, run_devnet_in_background, terminate_and_wait
+from test.util import load_file_content
 
 from starkware.starknet.definitions import constants
 from starkware.starknet.services.api.contract_class import ContractClass
@@ -139,16 +139,3 @@ def fixture_rpc_invoke_tx_common() -> dict:
         "nonce": "0x00",
         "type": "INVOKE",
     }
-
-
-@pytest.fixture(name="run_devnet_in_background")
-def fixture_run_devnet_in_background(request) -> None:
-    """
-    Run devnet instance in background
-    """
-    args = getattr(request, "param", [])
-    proc = run_devnet_in_background(*args)
-    try:
-        yield
-    finally:
-        terminate_and_wait(proc)
diff --git a/test/test_block_number.py b/test/test_block_number.py
index 6b0c100a5..81f4b2abc 100644
--- a/test/test_block_number.py
+++ b/test/test_block_number.py
@@ -2,6 +2,8 @@
 Test block number
 """
 
+import pytest
+
 from .shared import ARTIFACTS_PATH, FAILING_CONTRACT_PATH, GENESIS_BLOCK_NUMBER
 from .util import declare, devnet_in_background, deploy, call, invoke
 
@@ -9,6 +11,14 @@
 BLOCK_NUMBER_ABI_PATH = f"{ARTIFACTS_PATH}/block_number.cairo/block_number_abi.json"
 
 
+@pytest.fixture(name="expected_hash")
+def fixture_expected_hash(request):
+    """
+    Fixture to return values of expected hash
+    """
+    return request.param
+
+
 def my_get_block_number(address: str):
     """Execute my_get_block_number on block_number.cairo contract deployed at `address`"""
     return call(
@@ -16,11 +26,28 @@ def my_get_block_number(address: str):
     )
 
 
-def base_workflow():
-    """Used by test cases to perform the test"""
-    deploy_info = deploy(BLOCK_NUMBER_CONTRACT_PATH)
+@pytest.mark.usefixtures("run_devnet_in_background")
+@pytest.mark.parametrize(
+    "run_devnet_in_background, expected_hash",
+    [
+        ([], "0x4f1ea446f67c1be47619444eae4d8118f6e017d0e6fe16e89b3df03da38606d"),
+        (["--lite-mode"], "0x0"),
+    ],
+    indirect=True,
+)
+def test_block_number_incremented(expected_hash):
+    """
+    Tests how block number is incremented in regular mode and lite mode.
+    In regular mode with salt "0x42" our expected hash is
+    0x4f1ea446f67c1be47619444eae4d8118f6e017d0e6fe16e89b3df03da38606d.
+    In lite mode we expect 0x0 transaction hash.
+    """
+
+    deploy_info = deploy(BLOCK_NUMBER_CONTRACT_PATH, salt="0x42")
     block_number_before = my_get_block_number(deploy_info["address"])
+
     assert int(block_number_before) == GENESIS_BLOCK_NUMBER + 1
+    assert expected_hash == deploy_info["tx_hash"]
 
     invoke(
         function="write_block_number",
@@ -41,18 +68,6 @@ def base_workflow():
     assert int(block_number_after) == GENESIS_BLOCK_NUMBER + 2
 
 
-@devnet_in_background()
-def test_block_number_incremented():
-    """Tests how block number is incremented in regular mode"""
-    base_workflow()
-
-
-@devnet_in_background("--lite-mode")
-def test_block_number_incremented_in_lite_mode():
-    """Tests compatibility with lite mode"""
-    base_workflow()
-
-
 @devnet_in_background()
 def test_block_number_incremented_on_declare():
     """Declare tx should increment get_block_number response"""