• 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

92.31
/boa3/internal/compiler/codegenerator/methodtokencollection.py
1
from boa3.internal.model.builtin.method.builtinmethod import IBuiltinMethod
2✔
2
from boa3.internal.model.type.type import Type
2✔
3
from boa3.internal.neo3.contracts import CallFlags
2✔
4
from boa3.internal.neo3.contracts.nef import MethodToken
2✔
5
from boa3.internal.neo3.core import types
2✔
6

7

8
class MethodTokenCollection:
2✔
9
    def __init__(self):
2✔
10
        self._method_tokens: list[MethodToken] = []
2✔
11
        self._called_builtins: list[IBuiltinMethod] = []
2✔
12

13
    def append(self, contract_method: IBuiltinMethod, call_flag: CallFlags = CallFlags.ALL) -> int | None:
2✔
14
        method_token_id = self._try_get_index(contract_method, call_flag)
2✔
15
        if method_token_id is None and hasattr(contract_method, 'contract_script_hash'):
2✔
16
            method_token = MethodToken(hash=types.UInt160(contract_method.contract_script_hash),
2✔
17
                                       method=contract_method.external_name,
18
                                       parameters_count=(contract_method.internal_call_args
19
                                                         if hasattr(contract_method, 'internal_call_args')
20
                                                         else len(contract_method.args)),
21
                                       has_return_value=contract_method.return_type is not Type.none,
22
                                       call_flags=call_flag)
23

24
            if contract_method not in self._called_builtins:
2✔
25
                self._called_builtins.append(contract_method)
2✔
26

27
            if hasattr(contract_method, 'method_name') and len(contract_method.method_name) == 0:
2✔
28
                # it's a contract method with a different interface, so it shouldn't have its method token included
29
                return None
×
30

31
            method_token_id = len(self._method_tokens)
2✔
32
            if hasattr(contract_method, '_method_token_id'):
2✔
33
                contract_method.reset()
2✔
34
            self._method_tokens.append(method_token)
2✔
35

36
        return method_token_id
2✔
37

38
    def clear(self):
2✔
39
        # reset the opcodes to ensure the correct output when calling consecutive compilations
40
        for method in self._called_builtins:
2✔
41
            method.reset()
2✔
42

43
        self._called_builtins.clear()
2✔
44
        return self._method_tokens.clear()
2✔
45

46
    def _try_get_index(self, contract_method: IBuiltinMethod, call_flag: CallFlags = CallFlags.ALL) -> int | None:
2✔
47
        if not hasattr(contract_method, 'contract_script_hash'):
2✔
48
            return None
×
49

50
        parameters_count = (contract_method.internal_call_args
2✔
51
                            if hasattr(contract_method, 'internal_call_args')
52
                            else len(contract_method.args))
53

54
        method_token_index = next((index for index, token in enumerate(self._method_tokens)
2✔
55
                                   if (token.hash.to_array() == contract_method.contract_script_hash
56
                                       and token.method == contract_method.external_name
57
                                       and token.parameters_count == parameters_count
58
                                       and token.has_return_value == (contract_method.return_type is not Type.none)
59
                                       and token.call_flags == call_flag)), None)
60
        return method_token_index
2✔
61

62
    def to_list(self) -> list[MethodToken]:
2✔
63
        return self._method_tokens.copy()
2✔
64

65
    def __getitem__(self, item):
2✔
66
        if isinstance(item, int) and len(self._method_tokens) > item:
2✔
67
            return self._method_tokens[item]
2✔
68
        else:
69
            return None
×
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