def test_generate_currency_id_to_name_invalid_lengths(self): """Test the generate_currency_id_to_name of Helpers module where the lengths do not match.""" # phase with pytest.raises( AEAEnforceError, match="Length of currency_ids does not match nb_currencies.", ): assert generate_currency_id_to_name(nb_currencies=1, currency_ids=[1, 2])
def test_generate_currency_id_to_name(self): """Test the generate_currency_id_to_name of Helpers module.""" expected_currency_id_to_name = { "1": "FT_1", "3": "FT_3", "5": "FT_5", "7": "FT_7", "9": "FT_9", } currency_id_to_name = generate_currency_id_to_name(5, [1, 3, 5, 7, 9]) assert currency_id_to_name == expected_currency_id_to_name
def __init__( self, version_id: str, tx_fee: int, agent_addr_to_name: Dict[Address, str], nb_goods: int, ): """ Instantiate a game configuration. :param version_id: the version of the game. :param tx_fee: the fee for a transaction. :param agent_addr_to_name: a dictionary mapping agent addresses to agent names (as strings). :param nb_goods: the number of goods. """ self._version_id = version_id self._tx_fee = tx_fee self._agent_addr_to_name = agent_addr_to_name self._currency_id_to_name = generate_currency_id_to_name() self._good_id_to_name = generate_good_id_to_name(nb_goods) self._check_consistency()
def __init__(self, **kwargs): """Instantiate the parameter class.""" ledger_id = kwargs.pop("ledger_id", None) self._contract_address = kwargs.pop( "contract_address", None ) # type: Optional[str] self._good_ids = kwargs.pop("good_ids", []) # type: List[int] self._currency_ids = kwargs.pop("currency_ids", []) # type: List[int] self._min_nb_agents = kwargs.pop( "min_nb_agents", DEFAULT_MIN_NB_AGENTS ) # type: int self._money_endowment = kwargs.pop( "money_endowment", DEFAULT_MONEY_ENDOWMENT ) # type: int self._nb_goods = kwargs.pop("nb_goods", DEFAULT_NB_GOODS) # type: int self._nb_currencies = kwargs.pop( "nb_currencies", DEFAULT_NB_CURRENCIES ) # type: int self._tx_fee = kwargs.pop("tx_fee", DEFAULT_TX_FEE) # type: int self._base_good_endowment = kwargs.pop( "base_good_endowment", DEFAULT_BASE_GOOD_ENDOWMENT ) # type: int self._lower_bound_factor = kwargs.pop( "lower_bound_factor", DEFAULT_LOWER_BOUND_FACTOR ) # type: int self._upper_bound_factor = kwargs.pop( "upper_bound_factor", DEFAULT_UPPER_BOUND_FACTOR ) # type: int registration_start_time = kwargs.pop( "registration_start_time", DEFAULT_REGISTRATION_START_TIME ) # type: str self._registration_start_time = datetime.datetime.strptime( registration_start_time, "%d %m %Y %H:%M" ) # type: datetime.datetime self._registration_timeout = kwargs.pop( "registration_timeout", DEFAULT_REGISTRATION_TIMEOUT ) # type: int self._item_setup_timeout = kwargs.pop( "item_setup_timeout", DEFAULT_ITEM_SETUP_TIMEOUT ) # type: int self._competition_timeout = kwargs.pop( "competition_timeout", DEFAULT_COMPETITION_TIMEOUT ) # type: int self._inactivity_timeout = kwargs.pop( "inactivity_timeout", DEFAULT_INACTIVITY_TIMEOUT ) # type: int self._whitelist = set(kwargs.pop("whitelist", [])) # type: Set[str] self._location = kwargs.pop("location", DEFAULT_LOCATION) self._service_data = kwargs.pop("service_data", DEFAULT_SERVICE_DATA) enforce( len(self._service_data) == 2 and "key" in self._service_data and "value" in self._service_data, "service_data must contain keys `key` and `value`", ) self._version_id = self._service_data["value"] # type: str self._agent_location = { "location": Location( latitude=self._location["latitude"], longitude=self._location["longitude"], ) } self._set_service_data = self._service_data self._remove_service_data = {"key": self._service_data["key"]} self._simple_service_data = { self._service_data["key"]: self._service_data["value"] } super().__init__(**kwargs) self._ledger_id = ( ledger_id if ledger_id is not None else self.context.default_ledger_id ) self._contract_id = str(CONTRACT_ID) self._currency_id_to_name = generate_currency_id_to_name( self.nb_currencies, self.currency_ids ) self._good_id_to_name = generate_good_id_to_name( self.nb_goods, self.good_ids, starting_index=1 ) self._registration_end_time = ( self._registration_start_time + datetime.timedelta(seconds=self._registration_timeout) ) self._start_time = self._registration_end_time + datetime.timedelta( seconds=self._item_setup_timeout ) self._end_time = self._start_time + datetime.timedelta( seconds=self._competition_timeout ) now = datetime.datetime.now() if now > self.registration_start_time: self.context.logger.warning( "TAC registration start time {} is in the past! Deregistering skill.".format( self.registration_start_time ) ) self.context.is_active = False else: self.context.logger.info( "TAC registation start time: {}, and registration end time: {}, and start time: {}, and end time: {}".format( self.registration_start_time, self.registration_end_time, self.start_time, self.end_time, ) ) self._check_consistency()