Fixed big-endian decoding

This commit is contained in:
Biryuzovye Kleshni 2018-07-30 02:58:39 +00:00
parent 8e1259d06c
commit 0aaad8b896
2 changed files with 11 additions and 10 deletions

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