From 3b6db99152852238bb4284783d114c0b5849cb7b Mon Sep 17 00:00:00 2001
From: Lee Miller <lee.miller@tutanota.com>
Date: Sat, 14 Jan 2023 01:12:35 +0200
Subject: [PATCH] Skip TestProofofwork based on BITMESSAGE_TEST_POW (set for
 py36 currently),

a minimal test case TestProofofworkBase runs in all envs.
---
 src/tests/test_proofofwork.py | 26 ++++++++++++++++++++------
 tox.ini                       |  5 +++++
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/src/tests/test_proofofwork.py b/src/tests/test_proofofwork.py
index db1d8317..2356ed73 100644
--- a/src/tests/test_proofofwork.py
+++ b/src/tests/test_proofofwork.py
@@ -14,21 +14,35 @@ from pybitmessage import proofofwork, protocol
 from .samples import sample_pow_target, sample_pow_initial_hash
 
 
-class TestProofofwork(unittest.TestCase):
-    """The main test case for proofofwork"""
+class TestProofofworkBase(unittest.TestCase):
+    """Basic test case for proofofwork"""
 
     @classmethod
     def setUpClass(cls):
         proofofwork.init()
 
+    @staticmethod
+    def _make_sample_payload(TTL=7200):
+        return pack('>Q', int(time.time() + TTL)) + os.urandom(166)
+
     def test_calculate(self):
         """Ensure a calculated nonce has sufficient work for the protocol"""
-        TTL = 24 * 60 * 60
-        payload = pack('>Q', int(time.time() + TTL)) + os.urandom(166)
-        nonce = proofofwork.calculate(payload, TTL)[1]
+        payload = self._make_sample_payload()
+        nonce = proofofwork.calculate(payload, 7200)[1]
         self.assertTrue(
             protocol.isProofOfWorkSufficient(pack('>Q', nonce) + payload))
-        # raise difficulty
+
+
+@unittest.skipUnless(
+    os.getenv('BITMESSAGE_TEST_POW'), "BITMESSAGE_TEST_POW is not set")
+class TestProofofwork(TestProofofworkBase):
+    """The main test case for proofofwork"""
+
+    def test_calculate(self):
+        """Extended test for the main proofofwork call"""
+        # raise difficulty and TTL
+        TTL = 24 * 60 * 60
+        payload = self._make_sample_payload(TTL)
         nonce = proofofwork.calculate(payload, TTL, 2000, 2000)[1]
         self.assertTrue(
             protocol.isProofOfWorkSufficient(
diff --git a/tox.ini b/tox.ini
index 3524bb57..2acf7a86 100644
--- a/tox.ini
+++ b/tox.ini
@@ -50,6 +50,11 @@ commands = python pybitmessage/bitmessagemain.py -t
 [testenv:py35]
 skip_install = true
 
+[testenv:py36]
+setenv =
+    BITMESSAGE_TEST_POW = true
+    {[testenv]setenv}
+
 [testenv:reset]
 skip_install = true
 deps = coverage