示例#1
0
def test_outbox_empty():
    """Test thet the outbox queue is empty."""
    multiplexer = Multiplexer([DummyConnection()])
    multiplexer.connect()
    outbox = OutBox(multiplexer)
    assert outbox.empty(), "The outbox is not empty"
    multiplexer.disconnect()
示例#2
0
def test_outbox_put():
    """Tests that an envelope is putted into the queue."""
    msg = DefaultMessage(
        dialogue_reference=("", ""),
        message_id=1,
        target=0,
        performative=DefaultMessage.Performative.BYTES,
        content=b"hello",
    )
    message_bytes = DefaultSerializer().encode(msg)
    multiplexer = Multiplexer(
        [DummyConnection(connection_id=DUMMY_CONNECTION_PUBLIC_ID)])
    outbox = OutBox(multiplexer)
    inbox = InBox(multiplexer)
    multiplexer.connect()
    envelope = Envelope(
        to="Agent1",
        sender="Agent0",
        protocol_id=DefaultMessage.protocol_id,
        message=message_bytes,
    )
    outbox.put(envelope)
    time.sleep(0.5)
    assert not inbox.empty(
    ), "Inbox must not be empty after putting an envelope"
    multiplexer.disconnect()
示例#3
0
def test_outbox_empty():
    """Test thet the outbox queue is empty."""
    multiplexer = Multiplexer(
        [DummyConnection(connection_id=DUMMY_CONNECTION_PUBLIC_ID)])
    multiplexer.connect()
    outbox = OutBox(multiplexer)
    assert outbox.empty(), "The outbox is not empty"
    multiplexer.disconnect()
示例#4
0
def test_outbox_put_message():
    """Tests that an envelope is created from the message is in the queue."""
    msg = DefaultMessage(type=DefaultMessage.Type.BYTES, content=b"hello")
    message_bytes = DefaultSerializer().encode(msg)
    multiplexer = Multiplexer([DummyConnection()])
    outbox = OutBox(multiplexer)
    inbox = InBox(multiplexer)
    multiplexer.connect()
    outbox.put_message("Agent1", "Agent0", DefaultMessage.protocol_id,
                       message_bytes)
    time.sleep(0.5)
    assert not inbox.empty(
    ), "Inbox will not be empty after putting a message."
    multiplexer.disconnect()
示例#5
0
def test_outbox_put():
    """Tests that an envelope is putted into the queue."""
    msg = Message(content="hello")
    message_bytes = ProtobufSerializer().encode(msg)
    my_queue = Queue()
    envelope = Envelope(to="Agent1",
                        sender="Agent0",
                        protocol_id="my_own_protocol",
                        message=message_bytes)
    my_queue.put(envelope)
    _outbox = OutBox(my_queue)
    _outbox.put(envelope)
    assert _outbox.empty() is False,\
        "Oubox must not be empty after putting an envelope"
示例#6
0
    def __init__(
        self,
        identity: Identity,
        connections: List[Connection],
        loop: Optional[AbstractEventLoop] = None,
        timeout: float = 1.0,
        is_debug: bool = False,
        loop_mode: Optional[str] = None,
    ) -> None:
        """
        Instantiate the agent.

        :param identity: the identity of the agent.
        :param connections: the list of connections of the agent.
        :param loop: the event loop to run the connections.
        :param timeout: the time in (fractions of) seconds to time out an agent between act and react
        :param is_debug: if True, run the agent in debug mode (does not connect the multiplexer).
        :param loop_mode: loop_mode to choose agent run loop.

        :return: None
        """
        self._identity = identity
        self._connections = connections

        self._multiplexer = Multiplexer(self._connections, loop=loop)
        self._inbox = InBox(self._multiplexer)
        self._outbox = OutBox(self._multiplexer)
        self._liveness = Liveness()
        self._timeout = timeout

        self._tick = 0
        self._main_loop: Optional[BaseAgentLoop] = None

        self.is_debug = is_debug
        self._loop_mode = loop_mode or self.DEFAULT_RUN_LOOP
示例#7
0
    def __init__(
            self,
            identity: Identity,
            connections: List[Connection],
            loop: Optional[AbstractEventLoop] = None,
            timeout: float = 1.0,
            is_debug: bool = False,
            is_programmatic: bool = True,  # TODO to remove
    ) -> None:
        """
        Instantiate the agent.

        :param identity: the identity of the agent.
        :param connections: the list of connections of the agent.
        :param loop: the event loop to run the connections.
        :param timeout: the time in (fractions of) seconds to time out an agent between act and react
        :param is_debug: if True, run the agent in debug mode (does not connect the multiplexer).
        :param is_programmatic: if True, run the agent in programmatic mode (skips loading of resources from directory).

        :return: None
        """
        self._identity = identity
        self._connections = connections

        self._multiplexer = Multiplexer(self._connections, loop=loop)
        self._inbox = InBox(self._multiplexer)
        self._outbox = OutBox(self._multiplexer)
        self._liveness = Liveness()
        self._timeout = timeout

        self._tick = 0

        self.is_debug = is_debug
示例#8
0
    def setup_class(cls):
        """Initialise the decision maker."""
        cls._patch_logger()
        cls.multiplexer = Multiplexer(
            [DummyConnection(connection_id=DUMMY_CONNECTION_PUBLIC_ID)])
        cls.outbox = OutBox(cls.multiplexer)
        private_key_pem_path = os.path.join(CUR_PATH, "data",
                                            "fet_private_key.txt")
        eth_private_key_pem_path = os.path.join(CUR_PATH, "data",
                                                "fet_private_key.txt")
        cls.wallet = Wallet({
            FETCHAI: private_key_pem_path,
            ETHEREUM: eth_private_key_pem_path
        })
        cls.ledger_apis = LedgerApis({FETCHAI: DEFAULT_FETCHAI_CONFIG},
                                     FETCHAI)
        cls.agent_name = "test"
        cls.ownership_state = OwnershipState()
        cls.preferences = Preferences()
        cls.decision_maker = DecisionMaker(
            agent_name=cls.agent_name,
            max_reactions=MAX_REACTIONS,
            outbox=cls.outbox,
            wallet=cls.wallet,
            ledger_apis=cls.ledger_apis,
        )
        cls.multiplexer.connect()

        cls.tx_id = "transaction0"
        cls.tx_sender_addr = "agent_1"
        cls.tx_counterparty_addr = "pk"
        cls.info = {"some_info_key": "some_info_value"}
        cls.ledger_id = "fetchai"

        cls.decision_maker.start()
示例#9
0
    def __init__(self,
                 name: str,
                 connections: List[Connection],
                 wallet: Wallet,
                 loop: Optional[AbstractEventLoop] = None,
                 timeout: float = 1.0,
                 debug: bool = False) -> None:
        """
        Instantiate the agent.

        :param name: the name of the agent
        :param connections: the list of connections of the agent.
        :param wallet: the crypto wallet of the agent.
        :param loop: the event loop to run the connections.
        :param timeout: the time in (fractions of) seconds to time out an agent between act and react
        :param debug: if True, run the agent in debug mode.

        :return: None
        """
        self._name = name
        self._connections = connections
        self._wallet = wallet

        self._multiplexer = Multiplexer(self._connections, loop=loop)
        self._inbox = InBox(self._multiplexer)
        self._outbox = OutBox(self._multiplexer)
        self._liveness = Liveness()
        self._timeout = timeout

        self.debug = debug
示例#10
0
def test_outbox_put():
    """Tests that an envelope is putted into the queue."""
    msg = DefaultMessage(type=DefaultMessage.Type.BYTES, content=b"hello")
    message_bytes = DefaultSerializer().encode(msg)
    multiplexer = Multiplexer([DummyConnection()])
    outbox = OutBox(multiplexer)
    inbox = InBox(multiplexer)
    multiplexer.connect()
    envelope = Envelope(to="Agent1",
                        sender="Agent0",
                        protocol_id=DefaultMessage.protocol_id,
                        message=message_bytes)
    outbox.put(envelope)
    time.sleep(0.5)
    assert not inbox.empty(
    ), "Inbox must not be empty after putting an envelope"
    multiplexer.disconnect()
示例#11
0
def test_outbox_put_message():
    """Tests that an envelope is created from the message is in the queue."""
    msg = DefaultMessage(
        dialogue_reference=("", ""),
        message_id=1,
        target=0,
        performative=DefaultMessage.Performative.BYTES,
        content=b"hello",
    )
    message_bytes = DefaultSerializer().encode(msg)
    dummy_connection = _make_dummy_connection()
    multiplexer = Multiplexer([dummy_connection])
    outbox = OutBox(multiplexer)
    inbox = InBox(multiplexer)
    multiplexer.connect()
    outbox.put_message("Agent1", "Agent0", DefaultMessage.protocol_id,
                       message_bytes)
    time.sleep(0.5)
    assert not inbox.empty(
    ), "Inbox will not be empty after putting a message."
    multiplexer.disconnect()
示例#12
0
 def setup_class(cls):
     """Initialise the decision maker."""
     cls._patch_logger()
     cls.multiplexer = Multiplexer([DummyConnection()])
     cls.outbox = OutBox(cls.multiplexer)
     private_key_pem_path = os.path.join(CUR_PATH, "data",
                                         "fet_private_key.txt")
     cls.wallet = Wallet({FETCHAI: private_key_pem_path})
     cls.ledger_apis = LedgerApis({FETCHAI: DEFAULT_FETCHAI_CONFIG})
     cls.agent_name = "test"
     cls.ownership_state = OwnershipState()
     cls.preferences = Preferences()
     cls.decision_maker = DecisionMaker(agent_name=cls.agent_name,
                                        max_reactions=MAX_REACTIONS,
                                        outbox=cls.outbox,
                                        wallet=cls.wallet,
                                        ledger_apis=cls.ledger_apis)
     cls.multiplexer.connect()
示例#13
0
def test_outbox_empty():
    """Test thet the outbox queue is empty."""
    my_queue = Queue()
    _outbox = OutBox(my_queue)
    assert _outbox.empty(), "The outbox is not empty"