2021-01-16 19:58:40 +01:00
|
|
|
"""
|
|
|
|
Tests for openclpow module
|
|
|
|
"""
|
|
|
|
import hashlib
|
|
|
|
import unittest
|
|
|
|
from struct import pack, unpack
|
|
|
|
|
2021-01-29 16:02:55 +01:00
|
|
|
from .common import skip_python3
|
|
|
|
|
|
|
|
skip_python3() # noqa:E402
|
|
|
|
|
2021-02-01 10:35:04 +01:00
|
|
|
from pybitmessage import openclpow
|
2021-01-16 19:58:40 +01:00
|
|
|
|
2021-01-19 19:42:43 +01:00
|
|
|
|
2021-02-01 10:35:04 +01:00
|
|
|
class TestOpenClPow(unittest.TestCase):
|
2021-01-16 19:58:40 +01:00
|
|
|
"""
|
|
|
|
Main opencl test case
|
|
|
|
"""
|
|
|
|
|
2021-01-19 19:42:43 +01:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
openclpow.initCL()
|
|
|
|
|
2021-02-01 10:35:04 +01:00
|
|
|
@unittest.skipUnless(openclpow.enabledGpus, "No GPUs found / enabled")
|
2021-01-16 19:58:40 +01:00
|
|
|
def test_openclpow(self):
|
|
|
|
"""Check the working of openclpow module"""
|
|
|
|
target_ = 54227212183
|
2021-02-01 10:35:04 +01:00
|
|
|
initialHash = (
|
|
|
|
"3758f55b5a8d902fd3597e4ce6a2d3f23daff735f65d9698c270987f4e67ad590"
|
|
|
|
"b93f3ffeba0ef2fd08a8dc2f87b68ae5a0dc819ab57f22ad2c4c9c8618a43b3"
|
|
|
|
).decode("hex")
|
2021-01-16 19:58:40 +01:00
|
|
|
nonce = openclpow.do_opencl_pow(initialHash.encode("hex"), target_)
|
|
|
|
trialValue, = unpack(
|
2021-02-01 10:35:04 +01:00
|
|
|
'>Q', hashlib.sha512(hashlib.sha512(
|
|
|
|
pack('>Q', nonce) + initialHash).digest()).digest()[0:8])
|
2021-01-16 19:58:40 +01:00
|
|
|
self.assertLess((nonce - trialValue), target_)
|