[#319] Handle natural numbers
Description
Handling natural numbers raises Underflow
exception. Namely there are two cases:
-
Underflow
while performingAND
operation ofint
andnat
.We can do
AND
with a negativeInteger
, so we must apply bitwise-and (.&.
fromData.Bits
) first and then convert the result toNatural
(because the type of "return value" isNatural
). However, there is convertingInteger
toNatural
first, sofromIntegral
raisesUnderflow
. To solve this, we just fixed the order of the operations. -
Underflow
while unpacking packedint
asnat
.In Michelson we are able to pack a number as
int
and then to unpack it asnat
. When a number is negative, there must beNONE
. However, there is an attempt to decode a negative number asNatural
indecodeInt
function, soUnderflow
is raised byfromIntegral
again. To solve this, we changedfromIntegral
totoIntegralSized
and madedecodeInt
returnMaybe
withNothing
in case of negative number.
Related issue(s)
Resolves #319 (closed)
✅ Checklist for your Merge Request
Related changes (conditional)
-
Tests (see short guidelines)
-
If I added new functionality, I added tests covering it. -
If I fixed a bug, I added a regression test to prevent the bug from silently reappearing again.
-
-
Documentation
Stylistic guide (mandatory)
-
My commits comply with the following policy. -
My code complies with the style guide.