• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CityOfZion / neo3-boa / e084b44c-1a5f-4649-92cd-d3ed06099181

05 Mar 2024 05:58PM UTC coverage: 92.023% (-0.08%) from 92.107%
e084b44c-1a5f-4649-92cd-d3ed06099181

push

circleci

Mirella de Medeiros
CU-86drpnc9z - Drop support to Python 3.10

20547 of 22328 relevant lines covered (92.02%)

1.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.12
/boa3/internal/model/operation/binary/arithmetic/modulo.py
1
from boa3.internal.model.operation.binary.binaryoperation import BinaryOperation
2✔
2
from boa3.internal.model.operation.operator import Operator
2✔
3
from boa3.internal.model.type.type import IType, Type
2✔
4
from boa3.internal.neo.vm.opcode.Opcode import Opcode
2✔
5

6

7
class Modulo(BinaryOperation):
2✔
8
    """
9
    A class used to represent a numeric modulo operation
10

11
    :ivar operator: the operator of the operation. Inherited from :class:`IOperation`
12
    :ivar left: the left operand type. Inherited from :class:`BinaryOperation`
13
    :ivar right: the left operand type. Inherited from :class:`BinaryOperation`
14
    :ivar result: the result type of the operation.  Inherited from :class:`IOperation`
15
    """
16
    _valid_types: list[IType] = [Type.int]
2✔
17

18
    def __init__(self, left: IType = Type.int, right: IType = None):
2✔
19
        self.operator: Operator = Operator.Mod
2✔
20
        super().__init__(left, right)
2✔
21

22
    def validate_type(self, *types: IType) -> bool:
2✔
23
        if len(types) != self.number_of_operands:
2✔
24
            return False
×
25
        left: IType = types[0]
2✔
26
        right: IType = types[1]
2✔
27

28
        return left == right and any(_type.is_type_of(left) for _type in self._valid_types)
2✔
29

30
    def _get_result(self, left: IType, right: IType) -> IType:
2✔
31
        if self.validate_type(left, right):
2✔
32
            return left
2✔
33
        else:
34
            return Type.none
×
35

36
    def generate_opcodes(self, code_generator):
2✔
37
        from boa3.internal.model.operation.binaryop import BinaryOp
2✔
38

39
        # neo's mod has a different result from python's mod in some cases
40
        code_generator.swap_reverse_stack_items(2)
2✔
41
        code_generator.duplicate_stack_item(2)
2✔
42

43
        # result = first % second
44
        super().generate_opcodes(code_generator)
2✔
45

46
        # if the result is not zero and the sign is different from the second operator the result is different
47
        code_generator.duplicate_stack_top_item()
2✔
48
        code_generator.insert_opcode(Opcode.SIGN)   # sign of result
2✔
49
        code_generator.duplicate_stack_item(3)
2✔
50
        code_generator.insert_opcode(Opcode.SIGN)   # sign of second
2✔
51
        code_generator.duplicate_stack_item(2)
2✔
52
        code_generator.convert_operation(BinaryOp.NumNotEq, is_internal=True)
2✔
53

54
        code_generator.swap_reverse_stack_items(2)
2✔
55
        code_generator.convert_literal(0)
2✔
56
        code_generator.convert_operation(BinaryOp.NumNotEq, is_internal=True)
2✔
57

58
        # if sign(result) != sign(second) and result != 0:
59
        code_generator.convert_operation(BinaryOp.And, is_internal=True)
2✔
60
        if_negative = code_generator.convert_begin_if()
2✔
61
        #   result += second
62
        code_generator.convert_operation(BinaryOp.Add, is_internal=True)
2✔
63
        # else
64
        else_negative = code_generator.convert_begin_else(if_negative, is_internal=True)
2✔
65
        #   # just clear stack
66
        code_generator.remove_stack_item(2)
2✔
67
        code_generator.convert_end_if(else_negative, is_internal=True)
2✔
68

69
    def generate_internal_opcodes(self, code_generator):
2✔
70
        code_generator.insert_opcode(Opcode.MOD)
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc