Example #1
0
    def test_propose(self):
        """Test that a Propose can be sent correctly."""
        propose_empty = FipaMessage(
            message_id=1,
            dialogue_reference=(str(0), ""),
            target=0,
            performative=FipaMessage.Performative.PROPOSE,
            proposal=Description({"foo": "bar"}),
        )
        propose_empty.to = FETCHAI_ADDRESS_TWO
        propose_empty.sender = FETCHAI_ADDRESS_ONE
        self.multiplexer1.put(
            Envelope(
                to=propose_empty.to,
                sender=propose_empty.sender,
                protocol_id=propose_empty.protocol_id,
                message=propose_empty,
            ))
        envelope = self.multiplexer2.get(block=True, timeout=2.0)
        expected_propose_empty = FipaMessage.serializer.decode(
            envelope.message)
        expected_propose_empty.to = propose_empty.to
        expected_propose_empty.sender = propose_empty.sender
        assert expected_propose_empty == propose_empty

        propose_descriptions = FipaMessage(
            message_id=1,
            dialogue_reference=(str(0), ""),
            target=0,
            performative=FipaMessage.Performative.PROPOSE,
            proposal=Description({"foo": "bar"},
                                 DataModel("foobar",
                                           [Attribute("foo", str, True)])),
        )

        propose_descriptions.to = FETCHAI_ADDRESS_TWO
        propose_descriptions.sender = FETCHAI_ADDRESS_ONE
        self.multiplexer1.put(
            Envelope(
                to=propose_descriptions.to,
                sender=propose_descriptions.sender,
                protocol_id=propose_descriptions.protocol_id,
                message=propose_descriptions,
            ))
        envelope = self.multiplexer2.get(block=True, timeout=2.0)
        expected_propose_descriptions = FipaMessage.serializer.decode(
            envelope.message)
        expected_propose_descriptions.to = propose_descriptions.to
        expected_propose_descriptions.sender = propose_descriptions.sender
        assert expected_propose_descriptions == propose_descriptions
Example #2
0
    def test_error_unsupported_skill(self):
        """Test the unsupported skill."""
        msg = FipaMessage(
            message_id=1,
            dialogue_reference=(str(0), ""),
            target=0,
            performative=FipaMessage.Performative.ACCEPT,
        )
        msg.counterparty = self.address
        msg.sender = self.address
        envelope = Envelope(
            to=msg.counterparty,
            sender=msg.sender,
            protocol_id=msg.protocol_id,
            message=msg,
        )

        self.my_error_handler.send_unsupported_skill(envelope=envelope)

        wait_for_condition(lambda: len(self.my_aea._inbox._history) >= 1,
                           timeout=5)
        envelope = self.my_aea._inbox._history[-1]

        msg = envelope.message
        assert msg.performative == DefaultMessage.Performative.ERROR
        assert msg.error_code == DefaultMessage.ErrorCode.UNSUPPORTED_SKILL
Example #3
0
    def test_negative_message_has_attributes_invalid_message_id(self):
        """Negative test for message_has_attributes method where the message id does NOT match."""
        dummy_message = FipaMessage(
            dialogue_reference=("0", "0"),
            message_id=1,
            performative=FipaMessage.Performative.CFP,
            target=0,
            query="some_query",
        )
        dummy_message.to = "some_to"
        dummy_message.sender = "some_sender"

        invalid_has_attribute, invalid_has_attribute_msg = self.message_has_attributes(
            actual_message=dummy_message,
            message_type=FipaMessage,
            message_id=2,
            performative=FipaMessage.Performative.CFP,
            target=0,
            query="some_query",
            to="some_to",
            sender="some_sender",
        )
        assert not invalid_has_attribute
        assert (
            invalid_has_attribute_msg ==
            "The 'message_id' fields do not match. Actual 'message_id': 1. Expected 'message_id': 2"
        )
Example #4
0
    def test_positive_message_has_attributes_valid_type(self):
        """Test the message_has_attributes method where the message is of the specified type."""
        dummy_message = FipaMessage(
            dialogue_reference=("0", "0"),
            message_id=1,
            performative=FipaMessage.Performative.CFP,
            target=0,
            query="some_query",
        )
        dummy_message.to = "some_to"
        dummy_message.sender = "some_sender"

        valid_has_attribute, valid_has_attribute_msg = self.message_has_attributes(
            actual_message=dummy_message,
            message_type=FipaMessage,
            message_id=1,
            performative=FipaMessage.Performative.CFP,
            target=0,
            query="some_query",
            to="some_to",
            sender="some_sender",
        )
        assert valid_has_attribute
        assert (valid_has_attribute_msg ==
                "The message has the provided expected attributes.")
Example #5
0
    def test_cfp(self):
        """Test that a CFP can be sent correctly."""
        cfp_message = FipaMessage(
            message_id=1,
            dialogue_reference=(str(0), ""),
            target=0,
            performative=FipaMessage.Performative.CFP,
            query=Query([Constraint("something", ConstraintType(">", 1))]),
        )
        cfp_message.to = FETCHAI_ADDRESS_TWO
        cfp_message.sender = FETCHAI_ADDRESS_ONE
        self.multiplexer1.put(
            Envelope(
                to=cfp_message.to,
                sender=cfp_message.sender,
                protocol_id=cfp_message.protocol_id,
                message=cfp_message,
            ))
        envelope = self.multiplexer2.get(block=True, timeout=5.0)
        expected_cfp_message = FipaMessage.serializer.decode(envelope.message)
        expected_cfp_message.to = cfp_message.to
        expected_cfp_message.sender = cfp_message.sender
        assert expected_cfp_message == cfp_message

        cfp_none = FipaMessage(
            message_id=1,
            dialogue_reference=(str(0), ""),
            target=0,
            performative=FipaMessage.Performative.CFP,
            query=Query([Constraint("something", ConstraintType(">", 1))]),
        )
        cfp_none.to = FETCHAI_ADDRESS_TWO
        cfp_none.sender = FETCHAI_ADDRESS_ONE
        self.multiplexer1.put(
            Envelope(
                to=cfp_none.to,
                sender=cfp_none.sender,
                protocol_id=cfp_none.protocol_id,
                message=cfp_none,
            ))
        envelope = self.multiplexer2.get(block=True, timeout=5.0)
        expected_cfp_none = FipaMessage.serializer.decode(envelope.message)
        expected_cfp_none.to = cfp_none.to
        expected_cfp_none.sender = cfp_none.sender
        assert expected_cfp_none == cfp_none
Example #6
0
    def test_negative_message_has_attributes_invalid_type(self):
        """Test the message_has_attributes method where the message is NOT of the specified type."""
        dummy_message = FipaMessage(
            dialogue_reference=("0", "0"),
            message_id=1,
            performative=FipaMessage.Performative.CFP,
            target=0,
            query="some_query",
        )
        dummy_message.to = "some_to"
        dummy_message.sender = "some_sender"

        valid_has_attribute, valid_has_attribute_msg = self.message_has_attributes(
            actual_message=dummy_message,
            message_type=DefaultMessage,
            message_id=1,
            performative=FipaMessage.Performative.CFP,
            target=0,
            query="some_query",
            to="some_to",
            sender="some_sender",
        )
        assert not valid_has_attribute
        assert (
            valid_has_attribute_msg ==
            f"The message types do not match. Actual type: {FipaMessage}. Expected type: {DefaultMessage}"
        )

        invalid_has_attribute, invalid_has_attribute_msg = self.message_has_attributes(
            actual_message=dummy_message,
            message_type=FipaMessage,
            message_id=2,
            performative=FipaMessage.Performative.CFP,
            target=0,
            query="some_query",
            to="some_to",
            sender="some_sender",
        )
        assert not invalid_has_attribute
        assert (
            invalid_has_attribute_msg ==
            "The 'message_id' fields do not match. Actual 'message_id': 1. Expected 'message_id': 2"
        )
Example #7
0
 def test_decline(self):
     """Test that a Decline can be sent correctly."""
     decline = FipaMessage(
         message_id=1,
         dialogue_reference=(str(0), ""),
         target=0,
         performative=FipaMessage.Performative.DECLINE,
     )
     decline.to = FETCHAI_ADDRESS_TWO
     decline.sender = FETCHAI_ADDRESS_ONE
     self.multiplexer1.put(
         Envelope(
             to=decline.to,
             sender=decline.sender,
             message=decline,
         ))
     envelope = self.multiplexer2.get(block=True, timeout=2.0)
     expected_decline = FipaMessage.serializer.decode(envelope.message)
     expected_decline.to = decline.to
     expected_decline.sender = decline.sender
     assert expected_decline == decline
Example #8
0
 def test_accept(self):
     """Test that an Accept can be sent correctly."""
     accept = FipaMessage(
         message_id=1,
         dialogue_reference=(str(0), ""),
         target=0,
         performative=FipaMessage.Performative.ACCEPT,
     )
     accept.to = FETCHAI_ADDRESS_TWO
     accept.sender = FETCHAI_ADDRESS_ONE
     self.multiplexer1.put(
         Envelope(
             to=accept.to,
             sender=accept.sender,
             message=accept,
         ))
     envelope = self.multiplexer2.get(block=True, timeout=2.0)
     expected_accept = FipaMessage.serializer.decode(envelope.message)
     expected_accept.to = accept.to
     expected_accept.sender = accept.sender
     assert expected_accept == accept
Example #9
0
 def test_match_accept(self):
     """Test that a match accept can be sent correctly."""
     # NOTE since the OEF SDK doesn't support the match accept, we have to use a fixed message id!
     match_accept = FipaMessage(
         message_id=4,
         dialogue_reference=(str(0), ""),
         target=3,
         performative=FipaMessage.Performative.MATCH_ACCEPT,
     )
     match_accept.to = FETCHAI_ADDRESS_TWO
     match_accept.sender = FETCHAI_ADDRESS_ONE
     self.multiplexer1.put(
         Envelope(
             to=match_accept.to,
             sender=match_accept.sender,
             message=match_accept,
         ))
     envelope = self.multiplexer2.get(block=True, timeout=2.0)
     expected_match_accept = FipaMessage.serializer.decode(envelope.message)
     expected_match_accept.to = match_accept.to
     expected_match_accept.sender = match_accept.sender
     assert expected_match_accept == match_accept
Example #10
0
 def test_inform(self):
     """Test that an inform can be sent correctly."""
     payload = {"foo": "bar"}
     inform = FipaMessage(
         message_id=1,
         dialogue_reference=(str(0), ""),
         target=0,
         performative=FipaMessage.Performative.INFORM,
         info=payload,
     )
     inform.to = FETCHAI_ADDRESS_TWO
     inform.sender = FETCHAI_ADDRESS_ONE
     self.multiplexer1.put(
         Envelope(
             to=inform.to,
             sender=inform.sender,
             message=inform,
         ))
     envelope = self.multiplexer2.get(block=True, timeout=2.0)
     returned_inform = FipaMessage.serializer.decode(envelope.message)
     returned_inform.to = inform.to
     returned_inform.sender = inform.sender
     assert returned_inform == inform
Example #11
0
 def test_accept_w_inform(self):
     """Test that an accept with address can be sent correctly."""
     accept_w_inform = FipaMessage(
         message_id=1,
         dialogue_reference=(str(0), ""),
         target=0,
         performative=FipaMessage.Performative.ACCEPT_W_INFORM,
         info={"address": "my_address"},
     )
     accept_w_inform.to = FETCHAI_ADDRESS_TWO
     accept_w_inform.sender = FETCHAI_ADDRESS_ONE
     self.multiplexer1.put(
         Envelope(
             to=accept_w_inform.to,
             sender=accept_w_inform.sender,
             message=accept_w_inform,
         ))
     envelope = self.multiplexer2.get(block=True, timeout=2.0)
     returned_accept_w_inform = FipaMessage.serializer.decode(
         envelope.message)
     returned_accept_w_inform.to = accept_w_inform.to
     returned_accept_w_inform.sender = accept_w_inform.sender
     assert returned_accept_w_inform == accept_w_inform