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

CityOfZion / neo3-boa / 858f5658-b835-4f01-86b4-3a69cebd0b86

16 Oct 2023 06:23PM UTC coverage: 91.625% (+0.004%) from 91.621%
858f5658-b835-4f01-86b4-3a69cebd0b86

push

circleci

Mirella de Medeiros
Bump version: 1.0.1 → 1.1.0

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

19988 of 21815 relevant lines covered (91.63%)

0.92 hits per line

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

92.5
/boa3/internal/compiler/codegenerator/methodtokencollection.py
1
from typing import List, Optional
1✔
2

3
from boa3.internal.model.builtin.method.builtinmethod import IBuiltinMethod
1✔
4
from boa3.internal.model.type.type import Type
1✔
5
from boa3.internal.neo3.contracts import CallFlags
1✔
6
from boa3.internal.neo3.contracts.nef import MethodToken
1✔
7
from boa3.internal.neo3.core import types
1✔
8

9

10
class MethodTokenCollection:
1✔
11
    def __init__(self):
1✔
12
        self._method_tokens: List[MethodToken] = []
1✔
13
        self._called_builtins: List[IBuiltinMethod] = []
1✔
14

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

26
            if contract_method not in self._called_builtins:
1✔
27
                self._called_builtins.append(contract_method)
1✔
28

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

33
            method_token_id = len(self._method_tokens)
1✔
34
            if hasattr(contract_method, '_method_token_id'):
1✔
35
                contract_method.reset()
1✔
36
            self._method_tokens.append(method_token)
1✔
37

38
        return method_token_id
1✔
39

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

45
        self._called_builtins.clear()
1✔
46
        return self._method_tokens.clear()
1✔
47

48
    def _try_get_index(self, contract_method: IBuiltinMethod, call_flag: CallFlags = CallFlags.ALL) -> Optional[int]:
1✔
49
        if not hasattr(contract_method, 'contract_script_hash'):
1✔
50
            return None
×
51

52
        parameters_count = (contract_method.internal_call_args
1✔
53
                            if hasattr(contract_method, 'internal_call_args')
54
                            else len(contract_method.args))
55

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

64
    def to_list(self) -> List[MethodToken]:
1✔
65
        return self._method_tokens.copy()
1✔
66

67
    def __getitem__(self, item):
1✔
68
        if isinstance(item, int) and len(self._method_tokens) > item:
1✔
69
            return self._method_tokens[item]
1✔
70
        else:
71
            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