def test_envelope_initialisation(): """Testing the envelope initialisation.""" agent_address = "Agent0" receiver_address = "Agent1" msg = Message(content="hello") msg.counterparty = receiver_address assert Envelope( to=receiver_address, sender=agent_address, protocol_id=UNKNOWN_PROTOCOL_PUBLIC_ID, message=msg, ), "Cannot generate a new envelope" envelope = Envelope( to=receiver_address, sender=agent_address, protocol_id=UNKNOWN_PROTOCOL_PUBLIC_ID, message=msg, ) envelope.to = "ChangedAgent" envelope.sender = "ChangedSender" envelope.protocol_id = "my_changed_protocol" envelope.message = b"HelloWorld" assert envelope.to == "ChangedAgent", "Cannot set to value on Envelope" assert envelope.sender == "ChangedSender", "Cannot set sender value on Envelope" assert ( envelope.protocol_id == "my_changed_protocol" ), "Cannot set protocol_id on Envelope " assert envelope.message == b"HelloWorld", "Cannot set message on Envelope" assert envelope.context.uri_raw is not None
def test_envelope_initialisation(): """Testing the envelope initialisation.""" msg = Message(content='hello') message_bytes = ProtobufSerializer().encode(msg) assert Envelope(to="Agent1", sender="Agent0", protocol_id="my_own_protocol", message=message_bytes), "Cannot generate a new envelope" envelope = Envelope(to="Agent1", sender="Agent0", protocol_id="my_own_protocol", message=message_bytes) envelope.to = "ChangedAgent" envelope.sender = "ChangedSender" envelope.protocol_id = "my_changed_protocol" envelope.message = b"HelloWorld" assert envelope.to == "ChangedAgent", "Cannot set to value on Envelope" assert envelope.sender == "ChangedSender",\ "Cannot set sender value on Envelope" assert envelope.protocol_id == "my_changed_protocol",\ "Cannot set protocol_id on Envelope " assert envelope.message == b"HelloWorld", "Cannot set message on Envelope"
def test_envelope_initialisation(): """Testing the envelope initialisation.""" agent_address = "Agent0" receiver_address = "Agent1" msg = DefaultMessage(performative=DefaultMessage.Performative.BYTES, content="hello") msg.to = receiver_address envelope = Envelope( to=receiver_address, sender=agent_address, message=msg, ) assert envelope, "Cannot generate a new envelope" envelope.to = "ChangedAgent" envelope.sender = "ChangedSender" envelope.message = b"HelloWorld" assert envelope.to == "ChangedAgent", "Cannot set to value on Envelope" assert envelope.sender == "ChangedSender", "Cannot set sender value on Envelope" assert envelope.message == b"HelloWorld", "Cannot set message on Envelope" assert envelope.context.uri_raw is not None assert not envelope.is_sender_public_id assert not envelope.is_to_public_id
def test_envelope_initialisation(): """Testing the envelope initialisation.""" msg = Message(content="hello") message_bytes = ProtobufSerializer().encode(msg) assert Envelope( to="Agent1", sender="Agent0", protocol_id=UNKNOWN_PROTOCOL_PUBLIC_ID, message=message_bytes, ), "Cannot generate a new envelope" envelope = Envelope( to="Agent1", sender="Agent0", protocol_id=UNKNOWN_PROTOCOL_PUBLIC_ID, message=message_bytes, ) envelope.to = "ChangedAgent" envelope.sender = "ChangedSender" envelope.protocol_id = "my_changed_protocol" envelope.message = b"HelloWorld" assert envelope.to == "ChangedAgent", "Cannot set to value on Envelope" assert envelope.sender == "ChangedSender", "Cannot set sender value on Envelope" assert (envelope.protocol_id == "my_changed_protocol" ), "Cannot set protocol_id on Envelope " assert envelope.message == b"HelloWorld", "Cannot set message on Envelope" assert envelope.context.uri_raw is not None
def handle_envelope(self, envelope: Envelope) -> None: """ Handle envelope. :param envelope: the envelope received :return: None """ print("React called for tick {}".format(self.tick)) if envelope is not None and envelope.protocol_id == DefaultMessage.protocol_id: sender = envelope.sender receiver = envelope.to envelope.to = sender envelope.sender = receiver envelope.message = DefaultMessage.serializer.decode(envelope.message_bytes) envelope.message.sender = receiver envelope.message.to = sender print( "Received envelope from {} with protocol_id={}".format( sender, envelope.protocol_id ) ) self.outbox.put(envelope)