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

CityOfZion / neo3-boa / 0aff654d-b027-49a1-9d97-558d9a2a52ff

05 Mar 2024 04:57PM UTC coverage: 91.985% (-0.1%) from 92.106%
0aff654d-b027-49a1-9d97-558d9a2a52ff

push

circleci

web-flow
Merge pull request #1215 from CityOfZion/CU-86drpndkk

CU-86drpndkk - Refactor test_interop/test_blockchain.py to use BoaTestConstructor

1 of 1 new or added line in 1 file covered. (100.0%)

658 existing lines in 143 files now uncovered.

20635 of 22433 relevant lines covered (91.99%)

1.84 hits per line

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

95.59
/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✔
UNCOV
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, value: IType, code: VMCode):
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:
UNCOV
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:
UNCOV
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

94
class NeoStack(IStack):
2✔
95
    def __init__(self):
2✔
96
        from boa3.internal.model.type.itype import IType
2✔
97
        super().__init__(stack_type=IType)
2✔
98

99
    def _default_constructor_args(self) -> tuple:
2✔
100
        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