Skip TestProofofwork based on BITMESSAGE_TEST_POW (set for py36 currently),
a minimal test case TestProofofworkBase runs in all envs.
This commit is contained in:
parent
c6ae9f6843
commit
3b6db99152
|
@ -14,21 +14,35 @@ from pybitmessage import proofofwork, protocol
|
||||||
from .samples import sample_pow_target, sample_pow_initial_hash
|
from .samples import sample_pow_target, sample_pow_initial_hash
|
||||||
|
|
||||||
|
|
||||||
class TestProofofwork(unittest.TestCase):
|
class TestProofofworkBase(unittest.TestCase):
|
||||||
"""The main test case for proofofwork"""
|
"""Basic test case for proofofwork"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
proofofwork.init()
|
proofofwork.init()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _make_sample_payload(TTL=7200):
|
||||||
|
return pack('>Q', int(time.time() + TTL)) + os.urandom(166)
|
||||||
|
|
||||||
def test_calculate(self):
|
def test_calculate(self):
|
||||||
"""Ensure a calculated nonce has sufficient work for the protocol"""
|
"""Ensure a calculated nonce has sufficient work for the protocol"""
|
||||||
TTL = 24 * 60 * 60
|
payload = self._make_sample_payload()
|
||||||
payload = pack('>Q', int(time.time() + TTL)) + os.urandom(166)
|
nonce = proofofwork.calculate(payload, 7200)[1]
|
||||||
nonce = proofofwork.calculate(payload, TTL)[1]
|
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
protocol.isProofOfWorkSufficient(pack('>Q', nonce) + payload))
|
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]
|
nonce = proofofwork.calculate(payload, TTL, 2000, 2000)[1]
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
protocol.isProofOfWorkSufficient(
|
protocol.isProofOfWorkSufficient(
|
||||||
|
|
5
tox.ini
5
tox.ini
|
@ -50,6 +50,11 @@ commands = python pybitmessage/bitmessagemain.py -t
|
||||||
[testenv:py35]
|
[testenv:py35]
|
||||||
skip_install = true
|
skip_install = true
|
||||||
|
|
||||||
|
[testenv:py36]
|
||||||
|
setenv =
|
||||||
|
BITMESSAGE_TEST_POW = true
|
||||||
|
{[testenv]setenv}
|
||||||
|
|
||||||
[testenv:reset]
|
[testenv:reset]
|
||||||
skip_install = true
|
skip_install = true
|
||||||
deps = coverage
|
deps = coverage
|
||||||
|
|
Reference in New Issue
Block a user