Inherit TestProofofworkBase from partial.TestPartialRun

This commit is contained in:
Lee Miller 2023-12-07 00:27:04 +02:00
parent 822950e8f3
commit 338c006bb1
Signed by untrusted user: lee.miller
GPG Key ID: 4F97A5EA88F4AB63
2 changed files with 10 additions and 12 deletions

View File

@ -2,6 +2,7 @@
import os
import sys
import time
import unittest
from pybitmessage import pathmagic
@ -39,3 +40,5 @@ class TestPartialRun(unittest.TestCase):
# deactivate pathmagic
os.chdir(cls.dirs[0])
sys.path.remove(cls.dirs[1])
time.sleep(5)
cls.state.shutdown = 0

View File

@ -14,17 +14,22 @@ from pybitmessage.defaults import (
networkDefaultProofOfWorkNonceTrialsPerByte,
networkDefaultPayloadLengthExtraBytes)
from .partial import TestPartialRun
from .samples import sample_pow_target, sample_pow_initial_hash
default_ttl = 7200
class TestProofofworkBase(unittest.TestCase):
class TestProofofworkBase(TestPartialRun):
"""Basic test case for proofofwork"""
@classmethod
def setUpClass(cls):
proofofwork.init()
super(TestProofofworkBase, cls).setUpClass()
def setUp(self):
self.state.shutdown = 0
@staticmethod
def _make_sample_payload(TTL=default_ttl):
@ -43,14 +48,6 @@ class TestProofofworkBase(unittest.TestCase):
class TestProofofwork(TestProofofworkBase):
"""The main test case for proofofwork"""
@classmethod
def tearDownClass(cls):
import state
state.shutdown = 0
def setUp(self):
self.tearDownClass()
def _make_sample_data(self):
payload = self._make_sample_payload()
return payload, proofofwork.getTarget(
@ -70,10 +67,8 @@ class TestProofofwork(TestProofofworkBase):
pack('>Q', nonce) + payload, 2000, 2000,
int(time.time()) + TTL - 3600))
import state
with self.assertRaises(StopIteration):
state.shutdown = 1
self.state.shutdown = 1
proofofwork.calculate(payload, TTL)
def test_CPoW(self):