Inherit TestProofofworkBase from partial.TestPartialRun
This commit is contained in:
parent
822950e8f3
commit
338c006bb1
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from pybitmessage import pathmagic
|
from pybitmessage import pathmagic
|
||||||
|
@ -39,3 +40,5 @@ class TestPartialRun(unittest.TestCase):
|
||||||
# deactivate pathmagic
|
# deactivate pathmagic
|
||||||
os.chdir(cls.dirs[0])
|
os.chdir(cls.dirs[0])
|
||||||
sys.path.remove(cls.dirs[1])
|
sys.path.remove(cls.dirs[1])
|
||||||
|
time.sleep(5)
|
||||||
|
cls.state.shutdown = 0
|
||||||
|
|
|
@ -14,17 +14,22 @@ from pybitmessage.defaults import (
|
||||||
networkDefaultProofOfWorkNonceTrialsPerByte,
|
networkDefaultProofOfWorkNonceTrialsPerByte,
|
||||||
networkDefaultPayloadLengthExtraBytes)
|
networkDefaultPayloadLengthExtraBytes)
|
||||||
|
|
||||||
|
from .partial import TestPartialRun
|
||||||
from .samples import sample_pow_target, sample_pow_initial_hash
|
from .samples import sample_pow_target, sample_pow_initial_hash
|
||||||
|
|
||||||
default_ttl = 7200
|
default_ttl = 7200
|
||||||
|
|
||||||
|
|
||||||
class TestProofofworkBase(unittest.TestCase):
|
class TestProofofworkBase(TestPartialRun):
|
||||||
"""Basic test case for proofofwork"""
|
"""Basic test case for proofofwork"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
proofofwork.init()
|
proofofwork.init()
|
||||||
|
super(TestProofofworkBase, cls).setUpClass()
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.state.shutdown = 0
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _make_sample_payload(TTL=default_ttl):
|
def _make_sample_payload(TTL=default_ttl):
|
||||||
|
@ -43,14 +48,6 @@ class TestProofofworkBase(unittest.TestCase):
|
||||||
class TestProofofwork(TestProofofworkBase):
|
class TestProofofwork(TestProofofworkBase):
|
||||||
"""The main test case for proofofwork"""
|
"""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):
|
def _make_sample_data(self):
|
||||||
payload = self._make_sample_payload()
|
payload = self._make_sample_payload()
|
||||||
return payload, proofofwork.getTarget(
|
return payload, proofofwork.getTarget(
|
||||||
|
@ -70,10 +67,8 @@ class TestProofofwork(TestProofofworkBase):
|
||||||
pack('>Q', nonce) + payload, 2000, 2000,
|
pack('>Q', nonce) + payload, 2000, 2000,
|
||||||
int(time.time()) + TTL - 3600))
|
int(time.time()) + TTL - 3600))
|
||||||
|
|
||||||
import state
|
|
||||||
|
|
||||||
with self.assertRaises(StopIteration):
|
with self.assertRaises(StopIteration):
|
||||||
state.shutdown = 1
|
self.state.shutdown = 1
|
||||||
proofofwork.calculate(payload, TTL)
|
proofofwork.calculate(payload, TTL)
|
||||||
|
|
||||||
def test_CPoW(self):
|
def test_CPoW(self):
|
||||||
|
|
Reference in New Issue
Block a user