From bddb07edd2546b790a9f568870b6b39da6266046 Mon Sep 17 00:00:00 2001 From: David Minarsch Date: Wed, 6 Nov 2019 17:21:44 +0000 Subject: [PATCH] Add is connected status to skill context --- aea/aea.py | 1 + aea/context/base.py | 8 ++++++++ aea/skills/base.py | 5 +++++ tests/test_aea.py | 1 + 4 files changed, 15 insertions(+) diff --git a/aea/aea.py b/aea/aea.py index 9f4395635b..af506044e8 100644 --- a/aea/aea.py +++ b/aea/aea.py @@ -72,6 +72,7 @@ def __init__(self, name: str, self.wallet.public_keys, self.wallet.addresses, ledger_apis, + self.mailbox.is_connected, self.outbox, self.decision_maker.message_in_queue, self.decision_maker.ownership_state, diff --git a/aea/context/base.py b/aea/context/base.py index 8310e9e1d2..b744d0b9a2 100644 --- a/aea/context/base.py +++ b/aea/context/base.py @@ -34,6 +34,7 @@ def __init__(self, agent_name: str, public_keys: Dict[str, str], addresses: Dict[str, str], ledger_apis: LedgerApis, + is_connected: bool, outbox: OutBox, decision_maker_message_queue: Queue, ownership_state: OwnershipState, @@ -45,6 +46,7 @@ def __init__(self, agent_name: str, :param agent_name: the agent's name :param public_keys: the public keys of the agent :param ledger_apis: the ledger apis + :param is_connected: the connection status :param outbox: the outbox :param decision_maker_message_queue: the (in) queue of the decision maker :param ownership_state: the ownership state of the agent @@ -55,6 +57,7 @@ def __init__(self, agent_name: str, self._public_keys = public_keys self._addresses = addresses self._ledger_apis = ledger_apis + self._is_connected = is_connected self._outbox = outbox self._decision_maker_message_queue = decision_maker_message_queue self._ownership_state = ownership_state @@ -86,6 +89,11 @@ def public_key(self) -> str: """Get the default public key.""" return self._public_keys['default'] + @property + def is_connected(self) -> bool: + """Get connection status.""" + return self._is_connected + @property def outbox(self) -> OutBox: """Get outbox.""" diff --git a/aea/skills/base.py b/aea/skills/base.py index 207f1a2886..1041f0e84d 100644 --- a/aea/skills/base.py +++ b/aea/skills/base.py @@ -78,6 +78,11 @@ def agent_address(self) -> str: """Get address.""" return self._agent_context.address + @property + def is_connected(self) -> bool: + """Get connection status.""" + return self._agent_context.is_connected + @property def outbox(self) -> OutBox: """Get outbox.""" diff --git a/tests/test_aea.py b/tests/test_aea.py index 45e4cdccb8..5f892a322a 100644 --- a/tests/test_aea.py +++ b/tests/test_aea.py @@ -52,6 +52,7 @@ def test_initialise_AEA(): ledger_apis = LedgerApis({}) my_AEA = AEA("Agent0", mailbox1, wallet, ledger_apis, resources=Resources(str(Path(CUR_PATH, "aea")))) assert my_AEA.context == my_AEA._context, "Cannot access the Agent's Context" + assert not my_AEA.context.is_connected, "AEA should not be connected." my_AEA.setup() assert my_AEA.resources is not None,\ "Resources must not be None after setup"