def test_send_receive_envelope(self): """Run the echo skill sequence.""" self.add_item("skill", "fetchai/echo:0.5.0") process = self.run_agent() is_running = self.is_running(process) assert is_running, "AEA not running within timeout!" # add sending and receiving envelope from input/output files sender = "sender" default_dialogues = DefaultDialogues(sender) message_content = b"hello" message = DefaultMessage( performative=DefaultMessage.Performative.BYTES, dialogue_reference=default_dialogues. new_self_initiated_dialogue_reference(), content=message_content, ) sent_envelope = Envelope( to=self.agent_name, sender=sender, protocol_id=message.protocol_id, message=message, ) self.send_envelope_to_agent(sent_envelope, self.agent_name) time.sleep(2.0) received_envelope = self.read_envelope_from_agent(self.agent_name) received_message = DefaultMessage.serializer.decode( received_envelope.message) assert sent_envelope.message.content == received_message.content
def _run_interaction_channel(): # load agent configuration file loader = ConfigLoader.from_configuration_type(PackageType.AGENT) agent_configuration = loader.load(Path(DEFAULT_AEA_CONFIG_FILE).open()) agent_name = agent_configuration.name # load stub connection configuration = ConnectionConfig( input_file=DEFAULT_OUTPUT_FILE_NAME, output_file=DEFAULT_INPUT_FILE_NAME, connection_id=StubConnection.connection_id, ) identity_stub = Identity(agent_name + "_interact", "interact") stub_connection = StubConnection(configuration=configuration, identity=identity_stub) multiplexer = Multiplexer([stub_connection]) inbox = InBox(multiplexer) outbox = OutBox(multiplexer, default_address=identity_stub.address) dialogues = DefaultDialogues(identity_stub.name) try: multiplexer.connect() while True: # pragma: no cover _process_envelopes(agent_name, identity_stub, inbox, outbox, dialogues) except KeyboardInterrupt: click.echo("Interaction interrupted!") except BaseException as e: # pylint: disable=broad-except # pragma: no cover click.echo(e) finally: multiplexer.disconnect()
def test_echo(self): """Run the echo skill sequence.""" self.add_item("skill", "fetchai/echo:0.5.0") process = self.run_agent() is_running = self.is_running(process) assert is_running, "AEA not running within timeout!" # add sending and receiving envelope from input/output files sender = "sender" default_dialogues = DefaultDialogues(sender) message_content = b"hello" message = DefaultMessage( performative=DefaultMessage.Performative.BYTES, dialogue_reference=default_dialogues. new_self_initiated_dialogue_reference(), content=message_content, ) sent_envelope = Envelope( to=self.agent_name, sender=sender, protocol_id=message.protocol_id, message=message, ) self.send_envelope_to_agent(sent_envelope, self.agent_name) time.sleep(2.0) received_envelope = self.read_envelope_from_agent(self.agent_name) # assert sent_envelope.to == received_envelope.sender assert sent_envelope.sender == received_envelope.to assert sent_envelope.protocol_id == received_envelope.protocol_id msg = DefaultMessage.serializer.decode(received_envelope.message) assert sent_envelope.message.content == msg.content check_strings = ( "Echo Handler: setup method called.", "Echo Behaviour: setup method called.", "Echo Behaviour: act method called.", "content={}".format(message_content), ) missing_strings = self.missing_from_output(process, check_strings) assert ( missing_strings == [] ), "Strings {} didn't appear in agent output.".format(missing_strings) assert (self.is_successfully_terminated() ), "Echo agent wasn't successfully terminated."