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

Commit

Permalink
fix for #95, fix for #94
Browse files Browse the repository at this point in the history
  • Loading branch information
localhuman committed Nov 21, 2017
1 parent d267ca2 commit 7172b34
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
8 changes: 8 additions & 0 deletions neo/BigInteger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@

class BigInteger(int):

@property
def Sign(self):
if self > 0:
return 1
elif self == 0:
return 0
return -1

@staticmethod
def FromBytes(data, signed=False):
return BigInteger(int.from_bytes(data, 'little', signed=signed))
Expand Down
5 changes: 3 additions & 2 deletions neo/VM/InteropService.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,10 @@ def __init__(self, value):
super(Struct, self).__init__(value)

def Clone(self):
newArray = []
length = len(self._array)
newArray = [None for i in range(0, length)]

for i in range(0, len(self._array)):
for i in range(0, length):
if self._array[i] is None:
newArray[i] = None
elif self._array[i].IsStruct:
Expand Down
18 changes: 18 additions & 0 deletions neo/test_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,24 @@ def test_big_integer_frombytes(self):
self.assertEqual(b1, b2)
self.assertTrue(b1.Equals(b2))

def test_big_integer_sign(self):

b1 = BigInteger(3)
b2 = BigInteger(0)
b3 = BigInteger(-4)
self.assertEqual(b1.Sign, 1)
self.assertEqual(b2.Sign, 0)
self.assertEqual(b3.Sign, -1)

c1 = BigInteger(-100)
c1_bytes = c1.ToByteArray()

c2 = BigInteger.FromBytes(c1_bytes, signed=True)
self.assertEqual(c2.Sign, -1)

c2_unsigned = BigInteger.FromBytes(c1_bytes, signed=False)
self.assertEqual(c2_unsigned.Sign, 1)


class UIntBaseTestCase(NeoTestCase):
def test_initialization(self):
Expand Down

0 comments on commit 7172b34

Please sign in to comment.