Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

Commit

Permalink
fix bigint again (#967)
Browse files Browse the repository at this point in the history
  • Loading branch information
ixje committed Jun 12, 2019
1 parent 00b3860 commit 366cb0c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions neo/Core/BigInteger.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ def ToByteArray(self, signed=True):
msb = len(data) - 1
for i, b in enumerate(data[::-1]):
if b != highbyte:
msb = i
msb -= i
break

needExtraByte = (data[msb] & 0x80) == (highbyte & 0x80)
needExtraByte = (data[msb] & 0x80) != (highbyte & 0x80)
if needExtraByte:
return data
else:
Expand Down
8 changes: 6 additions & 2 deletions neo/Core/tests/test_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ def test_big_integer_to_ba(self):

b2 = BigInteger(-100)
b2ba = b2.ToByteArray()
integer2 = BigInteger.from_bytes(b2ba, 'little')
self.assertEqual(integer2, 65436)
integer2 = BigInteger.from_bytes(b2ba, 'little', signed=True)
self.assertEqual(integer2, -100)

b3 = BigInteger(128)
b3ba = b3.ToByteArray()
Expand All @@ -288,6 +288,10 @@ def test_big_integer_to_ba(self):
b6ba = b6.ToByteArray()
self.assertEqual(20, len(b6ba))

b7 = BigInteger(-399990000)
b7ba = b7.ToByteArray()
self.assertEqual(b'\x10\xa3\x28\xe8', b7ba)

def test_big_integer_frombytes(self):
b1 = BigInteger(8972340892734890723)
ba = b1.ToByteArray()
Expand Down

0 comments on commit 366cb0c

Please sign in to comment.