コード例 #1
0
ファイル: score_patcher.py プロジェクト: xgenvn/t-bears
    def register_interface_score(internal_score_address: Address):
        """Register interface SCORE. This method must be called before testing internal call(Calling other SCORE method)

        :param internal_score_address: address of internal call SCORE
        """
        if not internal_score_address.is_contract:
            raise InvalidRequestException(f"{internal_score_address} is not SCORE")
        interface_score_mapper[internal_score_address] = Mock()
コード例 #2
0
    def _other_score_call(self, addr_from: Address, addr_to: 'Address',
                          func_name: Optional[str], arg_params: tuple,
                          kw_params: dict, amount: int) -> Any:
        """Call the functions provided by other icon scores.

        :param addr_from:
        :param addr_to:
        :param func_name:
        :param arg_params:
        :param kw_params:
        :param amount:
        :return:
        """

        self.__context.validate_score_blacklist(addr_to)

        if len(self.__context.msg_stack) == MAX_CALL_STACK_SIZE:
            raise InvalidRequestException('Max call stack size exceeded')

        self.__context.msg_stack.append(self.__context.msg)

        self.__context.msg = Message(sender=addr_from, value=amount)
        self.current_address = addr_to

        prev_func_type = self.__context.func_type
        try:
            icon_score = self.__context.get_icon_score(addr_to)
            is_func_readonly = getattr(icon_score,
                                       '_IconScoreBase__is_func_readonly')
            if func_name is not None and is_func_readonly(func_name):
                self.__context.func_type = IconScoreFuncType.READONLY
            else:
                self.__context.func_type = IconScoreFuncType.WRITABLE

            if func_name is None:
                fallback_func = getattr(icon_score,
                                        '_IconScoreBase__fallback_call')
                fallback_func()
                return None
            else:
                external_func = getattr(icon_score,
                                        '_IconScoreBase__external_call')
                return external_func(func_name=func_name,
                                     arg_params=arg_params,
                                     kw_params=kw_params)
        except BaseException as e:
            raise e
        finally:
            self.__context.func_type = prev_func_type
            self.current_address = addr_from
            self.__context.msg = self.__context.msg_stack.pop()
コード例 #3
0
    def transfer(cls, context: 'IconScoreContext', _from: 'Address',
                 _to: 'Address', amount: int):
        sender_address = _from.to_bytes()
        receiver_address = _to.to_bytes()

        sender_balance = none_to_zero(cls.db.get(context, sender_address))
        receiver_balance = none_to_zero(cls.db.get(context, receiver_address))

        if sender_balance < amount:
            raise InvalidRequestException('out of balance')

        sender_balance -= amount
        receiver_balance += amount

        cls.db._db[sender_address] = sender_balance
        cls.db._db[receiver_address] = receiver_balance
コード例 #4
0
ファイル: score_test_case.py プロジェクト: xgenvn/t-bears
def validate_score_instance(score):
    if isinstance(score, IconScoreBase) is False:
        raise InvalidRequestException(f"{score.__name__} is invalid SCORE")
コード例 #5
0
ファイル: score_test_case.py プロジェクト: xgenvn/t-bears
def validate_score(score):
    if issubclass(score, IconScoreBase) is False:
        raise InvalidRequestException(
            f"{score.__name__} is invalid SCORE class")