Beispiel #1
0
 def initialization(self) -> Initialization:
     """Get game initialization."""
     if self._initialization is None:
         raise AEAEnforceError("Call create before calling initialization.")
     return self._initialization
Beispiel #2
0
 def contract_address(self) -> str:
     """Get the contract address for the game."""
     if self._contract_address is None:
         raise AEAEnforceError("Contract_address not set yet!")
     return self._contract_address
Beispiel #3
0
 def conf(self) -> Configuration:
     """Get game configuration."""
     if self._conf is None:
         raise AEAEnforceError("Call create before calling configuration.")
     return self._conf
Beispiel #4
0
    def build_incoming_message_for_skill_dialogue(
        self,
        dialogue: Dialogue,
        performative: Message.Performative,
        message_type: Optional[Type[Message]] = None,
        dialogue_reference: Optional[Tuple[str, str]] = None,
        message_id: Optional[int] = None,
        target: Optional[int] = None,
        to: Optional[Address] = None,
        sender: Optional[Address] = None,
        **kwargs: Any,
    ) -> Message:
        """
        Quickly create an incoming message with the provided attributes for a dialogue.

        For any attribute not provided, a value based on the dialogue is used.
        These values are shown in parantheses in the list of parameters below.

        NOTE: This method must be used with care. The dialogue provided is part of the skill
        which is being tested. Because for any unspecified attribute, a "correct" value is used,
        the test will be, by design, insured to pass on these values.

        :param dialogue: the dialogue to which the incoming message is intended
        :param performative: the performative of the message
        :param message_type: (the message_class of the provided dialogue) the type of the message
        :param dialogue_reference: (the dialogue_reference of the provided dialogue) the dialogue reference of the message
        :param message_id: (the id of the last message in the provided dialogue + 1) the id of the message
        :param target: (the id of the last message in the provided dialogue) the target of the message
        :param to: (the agent address associated with this skill) the receiver of the message
        :param sender: (the counterperty in the provided dialogue) the sender of the message
        :param kwargs: other attributes

        :return: the created incoming message
        """
        if dialogue is None:
            raise AEAEnforceError("dialogue cannot be None.")

        if dialogue.last_message is None:
            raise AEAEnforceError("dialogue cannot be empty.")

        message_type = (
            message_type if message_type is not None else dialogue.message_class
        )
        dialogue_reference = (
            dialogue_reference
            if dialogue_reference is not None
            else dialogue.dialogue_label.dialogue_reference
        )
        message_id = (
            message_id
            if message_id is not None
            else dialogue.get_incoming_next_message_id()
        )
        target = target if target is not None else dialogue.last_message.message_id
        to = to if to is not None else dialogue.self_address
        sender = (
            sender
            if sender is not None
            else dialogue.dialogue_label.dialogue_opponent_addr
        )

        incoming_message = self.build_incoming_message(
            message_type=message_type,
            performative=performative,
            dialogue_reference=dialogue_reference,
            message_id=message_id,
            target=target,
            to=to,
            sender=sender,
            **kwargs,
        )
        return incoming_message
Beispiel #5
0
    def prepare_skill_dialogue(
        self,
        dialogues: Dialogues,
        messages: Tuple[DialogueMessage, ...],
        counterparty: Address = COUNTERPARTY_ADDRESS,
    ) -> Dialogue:
        """
        Quickly create a dialogue.

        The 'messages' argument is a tuple of DialogueMessages.
        For every DialogueMessage (performative, contents, is_incoming, target):
            - if 'is_incoming' is not provided: for the first message it is assumed False (outgoing),
            for any other message, it is the opposite of the one preceding it.
            - if 'target' is not provided: for the first message it is assumed 0,
            for any other message, it is the index of the message before it in the tuple of messages + 1.

        :param dialogues: a dialogues class
        :param counterparty: the message_id
        :param messages: the dialogue_reference

        :return: the created incoming message
        """
        if len(messages) == 0:
            raise AEAEnforceError("the list of messages must be positive.")

        (
            performative,
            contents,
            message_id,
            is_incoming,
            target,
        ) = self._extract_message_fields(messages[0], index=0, last_is_incoming=True)

        if is_incoming:  # first message from the opponent
            dialogue_reference = dialogues.new_self_initiated_dialogue_reference()
            message = self.build_incoming_message(
                message_type=dialogues.message_class,
                dialogue_reference=dialogue_reference,
                message_id=Dialogue.STARTING_MESSAGE_ID,
                target=target or Dialogue.STARTING_TARGET,
                performative=performative,
                to=self.skill.skill_context.agent_address,
                sender=counterparty,
                **contents,
            )
            dialogue = cast(Dialogue, dialogues.update(message))
            if dialogue is None:
                raise AEAEnforceError(
                    "Cannot update the dialogue with message number {}".format(
                        message_id
                    )
                )
        else:  # first message from self
            _, dialogue = dialogues.create(
                counterparty=counterparty, performative=performative, **contents
            )

        for idx, dialogue_message in enumerate(messages[1:]):
            (
                performative,
                contents,
                message_id,
                is_incoming,
                target,
            ) = self._extract_message_fields(dialogue_message, idx + 1, is_incoming)
            if target is None:
                target = cast(Message, dialogue.last_message).message_id

            if is_incoming:  # messages from the opponent
                dialogue_reference = self._non_initial_incoming_message_dialogue_reference(
                    dialogue
                )
                message_id = dialogue.get_incoming_next_message_id()

                message = self.build_incoming_message(
                    message_type=dialogues.message_class,
                    dialogue_reference=dialogue_reference,
                    message_id=message_id,
                    target=target,
                    performative=performative,
                    to=self.skill.skill_context.agent_address,
                    sender=counterparty,
                    **contents,
                )
                dialogue = cast(Dialogue, dialogues.update(message))
                if dialogue is None:
                    raise AEAEnforceError(
                        "Cannot update the dialogue with message number {}".format(
                            message_id
                        )
                    )
            else:  # messages from self
                dialogue.reply(performative=performative, target=target, **contents)

        return dialogue
Beispiel #6
0
 def associated_ml_trade_dialogue(self) -> MlTradeDialogue:
     """Get associated_ml_trade_dialogue."""
     if self._associated_ml_trade_dialogue is None:
         raise AEAEnforceError("MlTradeDialogue not set!")
     return self._associated_ml_trade_dialogue
Beispiel #7
0
 def associated_ledger_api_dialogue(self) -> LedgerApiDialogue:
     """Get associated_ledger_api_dialogue."""
     if self._associated_ledger_api_dialogue is None:
         raise AEAEnforceError("LedgerApiDialogue not set!")
     return self._associated_ledger_api_dialogue
Beispiel #8
0
 def conf(self) -> Configuration:
     """Get the game configuration."""
     if self._conf is None:
         raise AEAEnforceError("Game configuration not assigned!")
     return self._conf
Beispiel #9
0
 def expected_controller_addr(self) -> Address:
     """Get the expected controller pbk."""
     if self._expected_controller_addr is None:
         raise AEAEnforceError("Expected controller address not assigned!")
     return self._expected_controller_addr
Beispiel #10
0
 def state_update_dialogue(self) -> StateUpdateDialogue:
     """Retrieve the state_update dialogue."""
     if self._state_update_dialogue is None:
         raise AEAEnforceError("StateUpdateDialogue not set!")
     return self._state_update_dialogue
Beispiel #11
0
 def tac_dialogue(self) -> TacDialogue:
     """Retrieve the tac dialogue."""
     if self._tac_dialogue is None:
         raise AEAEnforceError("TacDialogue not set!")
     return self._tac_dialogue
Beispiel #12
0
 def exception_raise():
     """A function that raises an exception."""
     raise AEAEnforceError("expected")