diff --git a/src/workprover/fastsolver/common.c b/src/workprover/fastsolver/common.c index 91477154..cc381e5f 100644 --- a/src/workprover/fastsolver/common.c +++ b/src/workprover/fastsolver/common.c @@ -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) ); } diff --git a/src/workprover/test.py b/src/workprover/test.py index bfc3fd3d..535f50ce 100755 --- a/src/workprover/test.py +++ b/src/workprover/test.py @@ -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