Beispiel #1
0
def test_is_valid_address():
    """Test LedgerApis.is_valid_address."""
    assert LedgerApis.is_valid_address(DEFAULT_LEDGER, FETCHAI_ADDRESS_ONE)
    assert LedgerApis.is_valid_address(EthereumCrypto.identifier,
                                       ETHEREUM_ADDRESS_ONE)
    assert LedgerApis.is_valid_address(CosmosCrypto.identifier,
                                       COSMOS_ADDRESS_ONE)
Beispiel #2
0
    def _handle_bytes(self, default_msg: DefaultMessage,
                      default_dialogue: DefaultDialogue) -> None:
        """
        Handle a default message of invalid performative.

        :param default_msg: the message
        :param default_dialogue: the default dialogue
        :return: None
        """
        strategy = cast(Strategy, self.context.strategy)
        if default_msg.sender == strategy.aw1_aea:
            try:
                confirmed_aea, developer_handle = default_msg.content.decode(
                    "utf-8").split("_")
            except Exception:  # pylint: disable=broad-except
                confirmed_aea, developer_handle = "", ""
            if not LedgerApis.is_valid_address("fetchai", confirmed_aea):
                self.context.logger.warning(
                    f"received invalid address={confirmed_aea} in dialogue={default_dialogue}."
                )
                return
            if developer_handle == "":
                self.context.logger.warning(
                    f"received invalid developer_handle={developer_handle}.")
                return
            self.context.logger.info(
                f"adding confirmed_aea={confirmed_aea} with developer_handle={developer_handle} to db."
            )
            strategy.register_counterparty(confirmed_aea, developer_handle)
        else:
            self.context.logger.warning(
                f"cannot handle default message of performative={default_msg.performative} in dialogue={default_dialogue}. Invalid sender={default_msg.sender}"
            )
Beispiel #3
0
    def __init__(self, **kwargs: Any) -> None:
        """
        Initialize the strategy of the agent.

        :return: None
        """
        ethereum_address = kwargs.pop("ethereum_address",
                                      DEFAULT_ETHEREUM_ADDRESS)
        enforce(
            ethereum_address != DEFAULT_ETHEREUM_ADDRESS
            and LedgerApis.is_valid_address("ethereum", ethereum_address),
            f"Not a valid ethereum_address: {ethereum_address}",
        )
        self._ethereum_address = ethereum_address
        signature_of_fetchai_address = kwargs.pop(
            "signature_of_fetchai_address",
            DEFAULT_SIGNATURE_OF_FETCHAI_ADDRESS)
        enforce(
            signature_of_fetchai_address !=
            DEFAULT_SIGNATURE_OF_FETCHAI_ADDRESS
            and isinstance(signature_of_fetchai_address, str),
            f"Not a valid signature_of_fetchai_address: {signature_of_fetchai_address}",
        )
        self._signature_of_fetchai_address = signature_of_fetchai_address
        developer_handle = kwargs.pop("developer_handle",
                                      DEFAULT_DEVELOPER_HANDLE)
        enforce(
            developer_handle != DEFAULT_DEVELOPER_HANDLE
            and isinstance(developer_handle, str),
            f"Not a valid developer_handle: {developer_handle}",
        )
        self._developer_handle = developer_handle
        tweet = kwargs.pop("tweet", DEFAULT_TWEET)
        enforce(isinstance(tweet, str), "Not a valid tweet link")
        self._tweet = tweet
        self._shared_storage_key = kwargs.pop("shared_storage_key",
                                              DEFAULT_SHARED_STORAGE_KEY)
        self._whitelist = kwargs.pop("whitelist", DEFAULT_WHITELIST)
        super().__init__(**kwargs)
        self._is_ready_to_register = False
        self._is_registered = False
        self.is_registration_pending = False
        self.signature_of_ethereum_address: Optional[str] = None
        self._ledger_id = self.context.default_ledger_id