New POW calculation module #1284

Open
Kleshni wants to merge 38 commits from Kleshni/POW into v0.6
2 changed files with 11 additions and 10 deletions
Showing only changes of commit 0aaad8b896 - Show all commits

View File

@ -23,14 +23,14 @@ static void encode_big_endian(char *result, unsigned long long number) {
static unsigned long long decode_big_endian(const char *encoded) {
return (
(unsigned long long) encoded[0] << 56 |
(unsigned long long) encoded[1] << 48 |
(unsigned long long) encoded[2] << 40 |
(unsigned long long) encoded[3] << 32 |
(unsigned long long) encoded[4] << 24 |
(unsigned long long) encoded[5] << 16 |
(unsigned long long) encoded[6] << 8 |
(unsigned long long) encoded[7]
((unsigned long long) encoded[0] & 0xff) << 56 |
((unsigned long long) encoded[1] & 0xff) << 48 |
((unsigned long long) encoded[2] & 0xff) << 40 |
((unsigned long long) encoded[3] & 0xff) << 32 |
((unsigned long long) encoded[4] & 0xff) << 24 |
((unsigned long long) encoded[5] & 0xff) << 16 |
((unsigned long long) encoded[6] & 0xff) << 8 |
((unsigned long long) encoded[7] & 0xff)
);
}

View File

@ -65,15 +65,16 @@ class TestUtils(unittest.TestCase):
self.assertTrue(utils.checkProof(nonce, initialHash, 0x000002fe91eba356))
def testCheckWorkSufficient(self):
self.assertFalse(utils.checkWorkSufficient(payload, byteDifficulty, lengthExtension, expiryTime - 293757.5))
self.assertTrue(utils.checkWorkSufficient(payload, byteDifficulty, lengthExtension, expiryTime - 293757))
originalTime = utils.time.time
utils.time.time = lambda: expiryTime - 293757.5
self.assertFalse(utils.checkWorkSufficient(payload, byteDifficulty, lengthExtension))
self.assertFalse(utils.checkWorkSufficient(payload, byteDifficulty, lengthExtension, expiryTime - 293757.5))
utils.time.time = lambda: expiryTime - 293757
self.assertTrue(utils.checkWorkSufficient(payload, byteDifficulty, lengthExtension))
self.assertTrue(utils.checkWorkSufficient(payload, byteDifficulty, lengthExtension, expiryTime - 293757))
utils.time.time = originalTime