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

CityOfZion / neo3-boa / cfb7933f-2cb9-40ed-8eeb-fdcaff5adc56

02 Jan 2024 02:52PM UTC coverage: 92.1% (+0.02%) from 92.076%
cfb7933f-2cb9-40ed-8eeb-fdcaff5adc56

push

circleci

web-flow
Merge pull request #1156 from CityOfZion/CU-86a1huhbg

Implement the structure used on all boa unit tests working with BoaTestConstructor

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

10 existing lines in 2 files now uncovered.

20763 of 22544 relevant lines covered (92.1%)

1.84 hits per line

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

96.1
/boa3/internal/model/builtin/builtin.py
1
from enum import Enum
2✔
2
from typing import Dict, List, Optional, Tuple, Union
2✔
3

4
from boa3.internal.model.builtin.builtincallable import IBuiltinCallable
2✔
5
from boa3.internal.model.builtin.classmethod import *
2✔
6
from boa3.internal.model.builtin.compile_time import *
2✔
7
from boa3.internal.model.builtin.contract import *
2✔
8
from boa3.internal.model.builtin.decorator import *
2✔
9
from boa3.internal.model.builtin.internal import *
2✔
10
from boa3.internal.model.builtin.interop.interop import Interop
2✔
11
from boa3.internal.model.builtin.math import *
2✔
12
from boa3.internal.model.builtin.method import *
2✔
13
from boa3.internal.model.callable import Callable
2✔
14
from boa3.internal.model.event import Event as EventSymbol
2✔
15
from boa3.internal.model.identifiedsymbol import IdentifiedSymbol
2✔
16
from boa3.internal.model.imports.package import Package
2✔
17
from boa3.internal.model.type.collection.sequence.ecpointtype import ECPointType
2✔
18
from boa3.internal.model.type.collection.sequence.uint160type import UInt160Type
2✔
19
from boa3.internal.model.type.collection.sequence.uint256type import UInt256Type
2✔
20
from boa3.internal.model.type.itype import IType
2✔
21
from boa3.internal.model.type.math import Math
2✔
22
from boa3.internal.model.type.neo import *
2✔
23

24

25
class BoaPackage(str, Enum):
2✔
26
    CompileTime = 'compile_time'
2✔
27
    Contract = 'contract'
2✔
28
    Interop = 'interop'
2✔
29
    Type = 'type'
2✔
30
    TypeHelper = 'helper'
2✔
31
    VM = 'vm'
2✔
32

33

34
class Builtin:
2✔
35
    @classmethod
2✔
36
    def get_symbol(cls, symbol_id: str) -> Optional[Callable]:
2✔
37
        for method in cls._python_builtins:
2✔
38
            if isinstance(method, IBuiltinCallable) and method.identifier == symbol_id:
2✔
39
                return method
2✔
40

41
    @classmethod
2✔
42
    def get_by_self(cls, symbol_id: str, self_type: IType) -> Optional[Callable]:
2✔
43
        for name, method in vars(cls).items():
×
44
            if (isinstance(method, IBuiltinMethod)
×
45
                    and method.identifier == symbol_id
46
                    and method.validate_self(self_type)):
47
                return method
×
48

49
    # builtin method
50
    Abs = AbsMethod()
2✔
51
    Exit = ExitMethod()
2✔
52
    IsInstance = IsInstanceMethod()
2✔
53
    Len = LenMethod()
2✔
54
    NewEvent = CreateEventMethod()
2✔
55
    Max = MaxIntMethod()
2✔
56
    Min = MinIntMethod()
2✔
57
    Print = PrintMethod()
2✔
58
    ScriptHashMethod_ = ScriptHashMethod()
2✔
59
    StrSplit = StrSplitMethod()
2✔
60
    Sum = SumMethod()
2✔
61
    ToHexStr = ToHexStrMethod()
2✔
62

63
    # python builtin class constructor
64
    Bool = BoolMethod()
2✔
65
    ByteArray = ByteArrayMethod()
2✔
66
    ByteArrayEncoding = ByteArrayEncodingMethod()
2✔
67
    Exception = ExceptionMethod()
2✔
68
    IntByteString = IntByteStringMethod()
2✔
69
    IntInt = IntIntMethod()
2✔
70
    ListBytesString = ListBytesStringMethod()
2✔
71
    ListGeneric = ListGenericMethod()
2✔
72
    ListMapping = ListMappingMethod()
2✔
73
    ListSequence = ListSequenceMethod()
2✔
74
    Range = RangeMethod()
2✔
75
    Reversed = ReversedMethod()
2✔
76
    StrBool = StrBoolMethod()
2✔
77
    StrBytes = StrBytesMethod()
2✔
78
    StrClass = StrClassMethod()
2✔
79
    StrInt = StrIntMethod()
2✔
80
    StrSequence = StrSequenceMethod()
2✔
81
    Super = SuperMethod()
2✔
82

83
    # python class method
84
    BytesStringIndex = IndexBytesStringMethod()
2✔
85
    BytesStringIsDigit = IsDigitMethod()
2✔
86
    BytesStringJoin = JoinMethod()
2✔
87
    BytesStringLower = LowerMethod()
2✔
88
    BytesStringStartswith = StartsWithMethod()
2✔
89
    BytesStringStrip = StripMethod()
2✔
90
    BytesStringUpper = UpperMethod()
2✔
91
    BytesStringReplace = ReplaceMethod()
2✔
92
    CountSequenceGeneric = CountSequenceGenericMethod()
2✔
93
    CountSequencePrimitive = CountSequencePrimitiveMethod()
2✔
94
    CountStr = CountStrMethod()
2✔
95
    Copy = CopyListMethod()
2✔
96
    ListSort = SortMethod()
2✔
97
    SequenceAppend = AppendMethod()
2✔
98
    SequenceClear = ClearMethod()
2✔
99
    SequenceExtend = ExtendMethod()
2✔
100
    SequenceIndex = IndexSequenceMethod()
2✔
101
    SequenceInsert = InsertMethod()
2✔
102
    SequencePop = PopSequenceMethod()
2✔
103
    SequenceRemove = RemoveMethod()
2✔
104
    SequenceReverse = ReverseMethod()
2✔
105
    DictKeys = MapKeysMethod()
2✔
106
    DictPop = PopDictMethod()
2✔
107
    DictPopDefault = PopDictDefaultMethod()
2✔
108
    DictValues = MapValuesMethod()
2✔
109

110
    # custom class methods
111
    ConvertToBytes = ToBytesMethod
2✔
112
    ConvertToInt = ToIntMethod
2✔
113
    ConvertToStr = ToStrMethod
2✔
114
    ConvertToBool = ToBoolMethod
2✔
115

116
    # builtin decorator
117
    ClassMethodDecorator = ClassMethodDecorator()
2✔
118
    InstanceMethodDecorator = InstanceMethodDecorator()
2✔
119
    PropertyDecorator = PropertyDecorator()
2✔
120
    StaticMethodDecorator = StaticMethodDecorator()
2✔
121

122
    _python_builtins: List[IdentifiedSymbol] = [Abs,
2✔
123
                                                ByteArray,
124
                                                ByteArrayEncoding,
125
                                                BytesStringIndex,
126
                                                BytesStringIsDigit,
127
                                                BytesStringJoin,
128
                                                BytesStringLower,
129
                                                BytesStringStartswith,
130
                                                BytesStringStrip,
131
                                                BytesStringUpper,
132
                                                BytesStringReplace,
133
                                                ClassMethodDecorator,
134
                                                ConvertToBool,
135
                                                ConvertToBytes,
136
                                                ConvertToInt,
137
                                                ConvertToStr,
138
                                                Copy,
139
                                                CountSequenceGeneric,
140
                                                CountSequencePrimitive,
141
                                                CountStr,
142
                                                DictKeys,
143
                                                DictValues,
144
                                                Exception,
145
                                                Exit,
146
                                                IsInstance,
147
                                                Len,
148
                                                ListSort,
149
                                                Max,
150
                                                Min,
151
                                                Print,
152
                                                PropertyDecorator,
153
                                                Range,
154
                                                Reversed,
155
                                                ScriptHashMethod_,
156
                                                SequenceAppend,
157
                                                SequenceClear,
158
                                                SequenceExtend,
159
                                                SequenceIndex,
160
                                                SequenceInsert,
161
                                                SequencePop,
162
                                                SequenceRemove,
163
                                                SequenceReverse,
164
                                                StaticMethodDecorator,
165
                                                StrSplit,
166
                                                Sum,
167
                                                Super,
168
                                                ]
169

170
    @classmethod
2✔
171
    def interop_symbols(cls, package: str = None) -> Dict[str, IdentifiedSymbol]:
2✔
UNCOV
172
        return {symbol.raw_identifier if hasattr(symbol, 'raw_identifier') else symbol.identifier: symbol
×
173
                for symbol in Interop.interop_symbols(package)}
174

175
    # boa builtin decorator
176
    ContractInterface = ContractDecorator()
2✔
177
    ContractMethodDisplayName = DisplayNameDecorator()
2✔
178
    Metadata = MetadataDecorator()
2✔
179
    Public = PublicDecorator()
2✔
180

181
    # boa builtin type
182
    Event = EventType
2✔
183
    UInt160 = UInt160Type.build()
2✔
184
    UInt256 = UInt256Type.build()
2✔
185
    ECPoint = ECPointType.build()
2✔
186
    NeoAccountState = NeoAccountStateType.build()
2✔
187
    Opcode = OpcodeType.build()
2✔
188
    Address = AddressType.build()
2✔
189
    BlockHash = BlockHashType.build()
2✔
190
    PublicKey = PublicKeyType.build()
2✔
191
    ScriptHashType_ = ScriptHashType.build()
2✔
192
    ScriptHashLittleEndian = ScriptHashLittleEndianType.build()
2✔
193
    TransactionId = TransactionIdType.build()
2✔
194

195
    # boa events
196
    Nep11Transfer = Nep11TransferEvent()
2✔
197
    Nep17Transfer = Nep17TransferEvent()
2✔
198

199
    # boa contract interfaces
200
    Nep17Contract = Nep17ContractClass()
2✔
201

202
    # boa smart contract methods
203
    Abort = AbortMethod()
2✔
204
    Env = EnvProperty.build()
2✔
205

206
    # region boa builtin modules
207

208
    BuiltinMathCeil = DecimalCeilingMethod()
2✔
209
    BuiltinMathFloor = DecimalFloorMethod()
2✔
210

211
    MathModule = Package(identifier='math',
2✔
212
                         methods=[Math.Sqrt,
213
                                  BuiltinMathCeil,
214
                                  BuiltinMathFloor])
215

216
    _symbols = [Env]
2✔
217
    _modules = [MathModule]
2✔
218

219
    # endregion
220

221
    boa_builtins: List[IdentifiedSymbol] = []
2✔
222
    boa_builtins.extend(_modules)
2✔
223
    boa_builtins.extend(_symbols)
2✔
224

225
    metadata_fields: Dict[str, Union[type, Tuple[type]]] = {
2✔
226
        'name': str,
227
        'source': (str, type(None)),
228
        'supported_standards': list,
229
        'trusts': list,
230
        'author': (str, type(None)),
231
        'email': (str, type(None)),
232
        'description': (str, type(None)),
233
        'extras': dict
234
    }
235

236
    @classmethod
2✔
237
    def boa_symbols(cls) -> Dict[str, IdentifiedSymbol]:
2✔
UNCOV
238
        return {symbol.identifier: symbol for symbol in cls.boa_builtins}
×
239

240
    @classmethod
2✔
241
    def package_symbols(cls, package: str = None) -> Dict[str, IdentifiedSymbol]:
2✔
242
        if package in BoaPackage.__members__.values():
2✔
243
            return {symbol.identifier: symbol for symbol in cls._boa_symbols[package]}
2✔
244

UNCOV
245
        return cls.boa_symbols()
×
246

247
    @classmethod
2✔
248
    def builtin_events(cls) -> List[EventSymbol]:
2✔
249
        lst: List[EventSymbol] = [event for event in cls.boa_builtins if isinstance(event, EventSymbol)]
2✔
250

251
        for symbols in cls._boa_symbols.values():
2✔
252
            lst.extend([event for event in symbols if isinstance(event, EventSymbol)])
2✔
253

254
        return lst
2✔
255

256
    _builtin_type_package_symbols = [ECPoint,
2✔
257
                                     UInt160,
258
                                     UInt256,
259
                                     Event,
260
                                     Address,
261
                                     BlockHash,
262
                                     PublicKey,
263
                                     ScriptHashType_,
264
                                     ScriptHashLittleEndian,
265
                                     TransactionId,
266
                                     Package(identifier=BoaPackage.TypeHelper,
267
                                             methods=[ConvertToBool,
268
                                                      ConvertToBytes,
269
                                                      ConvertToInt,
270
                                                      ConvertToStr,
271
                                                      ]
272
                                             )
273
                                     ]
274

275
    _boa_symbols: Dict[BoaPackage, List[IdentifiedSymbol]] = {
2✔
276
        BoaPackage.Contract: [Abort,
277
                              NeoAccountState,
278
                              Nep11Transfer,
279
                              Nep17Transfer,
280
                              Nep17Contract,
281
                              ScriptHashMethod_,
282
                              ToHexStr,
283
                              ],
284
        BoaPackage.Interop: Interop.package_symbols,
285
        BoaPackage.Type: _builtin_type_package_symbols,
286
        BoaPackage.VM: [Opcode
287
                        ],
288
        BoaPackage.CompileTime: [ContractInterface,
289
                                 ContractMethodDisplayName,
290
                                 Metadata,
291
                                 NeoMetadataType,
292
                                 Public,
293
                                 NewEvent
294
                                 ]
295
    }
296

297
    _internal_methods = [InnerDeployMethod.instance()
2✔
298
                         ]
299
    internal_methods = {method.raw_identifier: method for method in _internal_methods}
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

© 2025 Coveralls, Inc