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

CityOfZion / neo3-boa / cdd4f175-bfea-4f3d-8a74-6ee34db45e69

10 Apr 2024 03:28PM UTC coverage: 92.021% (-0.002%) from 92.023%
cdd4f175-bfea-4f3d-8a74-6ee34db45e69

push

circleci

Mirella de Medeiros
CU-86drpncat - Wrong tuple type hint is compiled on Neo3-boa

107 of 118 new or added lines in 8 files covered. (90.68%)

65 existing lines in 6 files now uncovered.

20908 of 22721 relevant lines covered (92.02%)

1.84 hits per line

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

94.94
/boa3/internal/compiler/codegenerator/engine/stackmemento.py
1
from __future__ import annotations
2✔
2

3
__all__ = [
2✔
4
    'StackMemento',
5
    'NeoStack'
6
]
7

8
from boa3.internal.compiler.codegenerator.engine.istack import IStack
2✔
9
from boa3.internal.compiler.codegenerator.vmcodemapping import VMCodeMapping
2✔
10
from boa3.internal.model.type.itype import IType
2✔
11
from boa3.internal.neo.vm.VMCode import VMCode
2✔
12

13

14
class StackMemento:
2✔
15
    """
16
    This class is responsible for managing the simulation of the blockchain stack during the code generation
17
    """
18

19
    def __init__(self):
2✔
20
        self._stacks: list[tuple[VMCode, NeoStack]] = []
2✔
21
        self._current_stack: NeoStack = NeoStack()
2✔
22

23
    @property
2✔
24
    def stack_map(self) -> dict[int, NeoStack]:
2✔
25
        vm_code_mapping = VMCodeMapping.instance()
2✔
26
        return {vm_code_mapping.get_start_address(vmcode): stack for vmcode, stack in self._stacks}
2✔
27

28
    def get_state(self, code_address: int) -> NeoStack:
2✔
29
        stacks = self.stack_map
2✔
30
        index = None
2✔
31
        for address, stack in sorted(stacks.items()):
2✔
32
            if address >= code_address:
2✔
33
                break
2✔
34
            index = address
2✔
35

36
        if index is None or index not in stacks:
2✔
37
            return NeoStack()
×
38
        else:
39
            return stacks[index]
2✔
40

41
    @property
2✔
42
    def current_stack(self) -> NeoStack:
2✔
43
        return self._current_stack
2✔
44

45
    def restore_state(self, code_address):
2✔
46
        stacks = self.stack_map
2✔
47
        latest_stack = None
2✔
48
        for address, stack in reversed(sorted(stacks.items())):
2✔
49
            if address < code_address:
2✔
50
                latest_stack = stack
2✔
51
                break
2✔
52

53
            vm_code = VMCodeMapping.instance().get_code(address)
2✔
54
            if (vm_code, stack) in self._stacks:
2✔
55
                self._stacks.remove((vm_code, stack))
2✔
56

57
        if latest_stack is not None:
2✔
58
            self._current_stack = latest_stack
2✔
59

60
    def append(self, code: VMCode, value: IType):
2✔
61
        states = self.stack_map
2✔
62
        index = VMCodeMapping.instance().get_start_address(code)
2✔
63
        if index in states:
2✔
64
            states[index].append(value)
2✔
65

66
        else:
67
            if self._current_stack is not None:
2✔
68
                stack = self._current_stack.copy()
2✔
69
            else:
70
                stack = NeoStack()
×
71
            stack.append(value)
2✔
72

73
            self._stacks.append((code, stack))
2✔
74
            self._current_stack = stack
2✔
75

76
    def pop(self, code: VMCode, index: int = -1):
2✔
77
        states = self.stack_map
2✔
78
        stack_index = VMCodeMapping.instance().get_start_address(code)
2✔
79
        if stack_index in states:
2✔
80
            stack = states[stack_index]
2✔
81
        else:
82
            if self._current_stack is not None:
2✔
83
                stack = self._current_stack.copy()
2✔
84
            else:
85
                stack = NeoStack()
×
86

87
            self._stacks.append((code, stack))
2✔
88
            self._current_stack = stack
2✔
89

90
        if len(stack) > 0:
2✔
91
            return stack.pop(index)
2✔
92

93
    def reverse(self, code: VMCode, start: int = 0, end: int = None, *, rotate: bool = False):
2✔
94
        states = self.stack_map
2✔
95
        stack_index = VMCodeMapping.instance().get_start_address(code)
2✔
96
        if stack_index in states:
2✔
97
            stack = states[stack_index]
2✔
98
        else:
99
            if self._current_stack is not None:
2✔
100
                stack = self._current_stack.copy()
2✔
101
            else:
UNCOV
102
                stack = NeoStack()
×
103

104
            self._stacks.append((code, stack))
2✔
105
            self._current_stack = stack
2✔
106

107
        return stack.reverse(start, end, rotate=rotate)
2✔
108

109

110
class NeoStack(IStack):
2✔
111
    def __init__(self):
2✔
112
        from boa3.internal.model.type.itype import IType
2✔
113
        super().__init__(stack_type=IType)
2✔
114

115
    def _default_constructor_args(self) -> tuple:
2✔
116
        return tuple()
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