def test_ml_skills(self, pytestconfig): """Run the ml skills sequence.""" data_provider_aea_name = "ml_data_provider" model_trainer_aea_name = "ml_model_trainer" self.create_agents(data_provider_aea_name, model_trainer_aea_name) default_routing = { "fetchai/ledger_api:0.1.0": "fetchai/ledger:0.2.0", "fetchai/oef_search:0.3.0": "fetchai/soef:0.5.0", } # prepare data provider agent self.set_agent_context(data_provider_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.5.0") self.add_item("connection", "fetchai/soef:0.5.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.5.0") self.add_item("connection", "fetchai/ledger:0.2.0") self.add_item("skill", "fetchai/ml_data_provider:0.7.0") setting_path = ( "vendor.fetchai.skills.ml_data_provider.models.strategy.args.is_ledger_tx" ) self.set_config(setting_path, False, "bool") setting_path = "agent.default_routing" self.force_set_config(setting_path, default_routing) self.run_install() # add non-funded key self.generate_private_key(COSMOS) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE, connection=True) self.replace_private_key_in_file(NON_FUNDED_COSMOS_PRIVATE_KEY_1, COSMOS_PRIVATE_KEY_FILE) # prepare model trainer agent self.set_agent_context(model_trainer_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.5.0") self.add_item("connection", "fetchai/soef:0.5.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.5.0") self.add_item("connection", "fetchai/ledger:0.2.0") self.add_item("skill", "fetchai/ml_train:0.7.0") setting_path = ( "vendor.fetchai.skills.ml_train.models.strategy.args.is_ledger_tx") self.set_config(setting_path, False, "bool") setting_path = "agent.default_routing" self.force_set_config(setting_path, default_routing) self.run_install() # add funded key self.generate_private_key(COSMOS) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE, connection=True) self.replace_private_key_in_file(FUNDED_COSMOS_PRIVATE_KEY_1, COSMOS_PRIVATE_KEY_FILE) setting_path = "vendor.fetchai.connections.p2p_libp2p.config" self.force_set_config(setting_path, NON_GENESIS_CONFIG) self.set_agent_context(data_provider_aea_name) data_provider_aea_process = self.run_agent() check_strings = ( "Downloading golang dependencies. This may take a while...", "Finished downloading golang dependencies.", "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", "My libp2p addresses:", ) missing_strings = self.missing_from_output(data_provider_aea_process, check_strings, timeout=240, is_terminating=False) assert ( missing_strings == [] ), "Strings {} didn't appear in data_provider_aea output.".format( missing_strings) self.set_agent_context(model_trainer_aea_name) model_trainer_aea_process = self.run_agent() check_strings = ( "Downloading golang dependencies. This may take a while...", "Finished downloading golang dependencies.", "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", "My libp2p addresses:", ) missing_strings = self.missing_from_output(model_trainer_aea_process, check_strings, timeout=240, is_terminating=False) assert ( missing_strings == [] ), "Strings {} didn't appear in model_trainer_aea output.".format( missing_strings) check_strings = ( "registering agent on SOEF.", "registering service on SOEF.", "got a Call for Terms from", "a Terms message:", "got an Accept from", "a Data message:", ) missing_strings = self.missing_from_output(data_provider_aea_process, check_strings, is_terminating=False) assert ( missing_strings == [] ), "Strings {} didn't appear in data_provider_aea output.".format( missing_strings) check_strings = ( "found agents=", "sending CFT to agent=", "received terms message from", "sending dummy transaction digest ...", "received data message from", "Loss:", ) missing_strings = self.missing_from_output(model_trainer_aea_process, check_strings, is_terminating=False) assert ( missing_strings == [] ), "Strings {} didn't appear in model_trainer_aea output.".format( missing_strings) self.terminate_agents(data_provider_aea_process, model_trainer_aea_process) assert (self.is_successfully_terminated() ), "Agents weren't successfully terminated." wait_for_localhost_ports_to_close([9000, 9001])
def test_cli_programmatic_communication(self): """Test the communication of the two agents.""" weather_station = "weather_station" self.fetch_agent("fetchai/weather_station:0.22.0", weather_station) self.set_agent_context(weather_station) self.set_config( "vendor.fetchai.skills.weather_station.models.strategy.args.is_ledger_tx", False, "bool", ) self.run_install() # add non-funded key self.generate_private_key(FETCHAI) self.generate_private_key(FETCHAI, FETCHAI_PRIVATE_KEY_FILE_CONNECTION) self.add_private_key(FETCHAI, FETCHAI_PRIVATE_KEY_FILE) self.add_private_key(FETCHAI, FETCHAI_PRIVATE_KEY_FILE_CONNECTION, connection=True) self.replace_private_key_in_file(NON_FUNDED_FETCHAI_PRIVATE_KEY_1, FETCHAI_PRIVATE_KEY_FILE_CONNECTION) # generate random location location = { "latitude": round(uniform(-90, 90), 2), # nosec "longitude": round(uniform(-180, 180), 2), # nosec } setting_path = ( "vendor.fetchai.skills.weather_station.models.strategy.args.location" ) self.nested_set_config(setting_path, location) self.run_cli_command("build", cwd=self._get_cwd()) self.run_cli_command("issue-certificates", cwd=self._get_cwd()) weather_station_process = self.run_agent() check_strings = ( "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", LIBP2P_SUCCESS_MESSAGE, ) missing_strings = self.missing_from_output(weather_station_process, check_strings, timeout=30, is_terminating=False) assert ( missing_strings == [] ), "Strings {} didn't appear in weather_station output.".format( missing_strings) src_file_path = os.path.join(ROOT_DIR, "tests", PY_FILE) dst_file_path = os.path.join(ROOT_DIR, self.t, DEST) shutil.copyfile(src_file_path, dst_file_path) self._inject_location(location, dst_file_path) weather_client_process = self.start_subprocess(DEST, cwd=self.t) check_strings = ( "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", LIBP2P_SUCCESS_MESSAGE, ) missing_strings = self.missing_from_output( weather_client_process, check_strings, timeout=30, is_terminating=False, ) assert (missing_strings == [] ), "Strings {} didn't appear in weather_client output.".format( missing_strings) check_strings = ( "registering agent on SOEF.", "registering service on SOEF.", "received CFP from sender=", "sending a PROPOSE with proposal=", "received ACCEPT from sender=", "sending MATCH_ACCEPT_W_INFORM to sender=", "received INFORM from sender=", "transaction confirmed, sending data=", ) missing_strings = self.missing_from_output(weather_station_process, check_strings, timeout=120, is_terminating=False) assert ( missing_strings == [] ), "Strings {} didn't appear in weather_station output.".format( missing_strings) check_strings = ( "found agents=", "sending CFP to agent=", "received proposal=", "accepting the proposal from sender=", "informing counterparty=", "received INFORM from sender=", "received the following data=", ) missing_strings = self.missing_from_output(weather_client_process, check_strings, is_terminating=False) assert (missing_strings == [] ), "Strings {} didn't appear in weather_client output.".format( missing_strings) self.terminate_agents(weather_client_process, weather_station_process) assert (self.is_successfully_terminated() ), "Agents weren't successfully terminated." wait_for_localhost_ports_to_close([9000, 9001])
def test_thermometer(self): """Run the thermometer skills sequence.""" thermometer_aea_name = "my_thermometer" thermometer_client_aea_name = "my_thermometer_client" self.create_agents(thermometer_aea_name, thermometer_client_aea_name) default_routing = { "fetchai/ledger_api:0.1.0": "fetchai/ledger:0.2.0", "fetchai/oef_search:0.3.0": "fetchai/soef:0.5.0", } # add packages for agent one and run it self.set_agent_context(thermometer_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.5.0") self.add_item("connection", "fetchai/soef:0.5.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.5.0") self.add_item("connection", "fetchai/ledger:0.2.0") self.add_item("skill", "fetchai/thermometer:0.7.0") setting_path = ( "vendor.fetchai.skills.thermometer.models.strategy.args.is_ledger_tx" ) self.set_config(setting_path, False, "bool") setting_path = "agent.default_routing" self.force_set_config(setting_path, default_routing) self.run_install() # add non-funded key self.generate_private_key(COSMOS) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE, connection=True) self.replace_private_key_in_file(NON_FUNDED_COSMOS_PRIVATE_KEY_1, COSMOS_PRIVATE_KEY_FILE) # add packages for agent two and run it self.set_agent_context(thermometer_client_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.5.0") self.add_item("connection", "fetchai/soef:0.5.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.5.0") self.add_item("connection", "fetchai/ledger:0.2.0") self.add_item("skill", "fetchai/thermometer_client:0.6.0") setting_path = ( "vendor.fetchai.skills.thermometer_client.models.strategy.args.is_ledger_tx" ) self.set_config(setting_path, False, "bool") setting_path = "agent.default_routing" self.force_set_config(setting_path, default_routing) self.run_install() # add funded key self.generate_private_key(COSMOS) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE, connection=True) self.replace_private_key_in_file(FUNDED_COSMOS_PRIVATE_KEY_1, COSMOS_PRIVATE_KEY_FILE) setting_path = "vendor.fetchai.connections.p2p_libp2p.config" self.force_set_config(setting_path, NON_GENESIS_CONFIG) # run AEAs self.set_agent_context(thermometer_aea_name) thermometer_aea_process = self.run_agent() check_strings = ( "Downloading golang dependencies. This may take a while...", "Finished downloading golang dependencies.", "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", "My libp2p addresses:", ) missing_strings = self.missing_from_output(thermometer_aea_process, check_strings, timeout=240, is_terminating=False) assert ( missing_strings == [] ), "Strings {} didn't appear in thermometer_aea output.".format( missing_strings) self.set_agent_context(thermometer_client_aea_name) thermometer_client_aea_process = self.run_agent() check_strings = ( "Downloading golang dependencies. This may take a while...", "Finished downloading golang dependencies.", "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", "My libp2p addresses:", ) missing_strings = self.missing_from_output( thermometer_client_aea_process, check_strings, timeout=240, is_terminating=False, ) assert ( missing_strings == [] ), "Strings {} didn't appear in thermometer_client_aea output.".format( missing_strings) check_strings = ( "registering agent on SOEF.", "registering service on SOEF.", "received CFP from sender=", "sending a PROPOSE with proposal=", "received ACCEPT from sender=", "sending MATCH_ACCEPT_W_INFORM to sender=", "received INFORM from sender=", "transaction confirmed, sending data=", ) missing_strings = self.missing_from_output(thermometer_aea_process, check_strings, is_terminating=False) assert ( missing_strings == [] ), "Strings {} didn't appear in thermometer_aea output.".format( missing_strings) check_strings = ( "found agents=", "sending CFP to agent=", "received proposal=", "accepting the proposal from sender=", "informing counterparty=", "received INFORM from sender=", "received the following data=", ) missing_strings = self.missing_from_output( thermometer_client_aea_process, check_strings, is_terminating=False) assert ( missing_strings == [] ), "Strings {} didn't appear in thermometer_client_aea output.".format( missing_strings) self.terminate_agents(thermometer_aea_process, thermometer_client_aea_process) assert (self.is_successfully_terminated() ), "Agents weren't successfully terminated." wait_for_localhost_ports_to_close([9000, 9001])
def test_weather(self): """Run the weather skills sequence.""" weather_station_aea_name = "my_weather_station" weather_client_aea_name = "my_weather_client" self.create_agents(weather_station_aea_name, weather_client_aea_name) default_routing = { "fetchai/ledger_api:0.10.0": "fetchai/ledger:0.13.0", "fetchai/oef_search:0.13.0": "fetchai/soef:0.17.0", } # generate random location location = { "latitude": round(uniform(-90, 90), 2), # nosec "longitude": round(uniform(-180, 180), 2), # nosec } # add packages for agent one self.set_agent_context(weather_station_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.16.0") self.add_item("connection", "fetchai/soef:0.17.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.16.0") self.add_item("connection", "fetchai/ledger:0.13.0") self.add_item("skill", "fetchai/weather_station:0.19.0") setting_path = "agent.default_routing" self.nested_set_config(setting_path, default_routing) self.run_install() diff = self.difference_to_fetched_agent( "fetchai/weather_station:0.22.0", weather_station_aea_name) assert ( diff == [] ), "Difference between created and fetched project for files={}".format( diff) # add keys self.generate_private_key(FETCHAI) self.generate_private_key(FETCHAI, FETCHAI_PRIVATE_KEY_FILE_CONNECTION) self.add_private_key(FETCHAI, FETCHAI_PRIVATE_KEY_FILE) self.add_private_key(FETCHAI, FETCHAI_PRIVATE_KEY_FILE_CONNECTION, connection=True) self.replace_private_key_in_file(NON_FUNDED_FETCHAI_PRIVATE_KEY_1, FETCHAI_PRIVATE_KEY_FILE_CONNECTION) setting_path = "vendor.fetchai.connections.p2p_libp2p.config.ledger_id" self.set_config(setting_path, FETCHAI) # replace location setting_path = ( "vendor.fetchai.skills.weather_station.models.strategy.args.location" ) self.nested_set_config(setting_path, location) # add packages for agent two self.set_agent_context(weather_client_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.16.0") self.add_item("connection", "fetchai/soef:0.17.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.16.0") self.add_item("connection", "fetchai/ledger:0.13.0") self.add_item("skill", "fetchai/weather_client:0.19.0") setting_path = "agent.default_routing" self.nested_set_config(setting_path, default_routing) self.run_install() diff = self.difference_to_fetched_agent( "fetchai/weather_client:0.23.0", weather_client_aea_name) assert ( diff == [] ), "Difference between created and fetched project for files={}".format( diff) # add keys self.generate_private_key(FETCHAI) self.generate_private_key(FETCHAI, FETCHAI_PRIVATE_KEY_FILE_CONNECTION) self.add_private_key(FETCHAI, FETCHAI_PRIVATE_KEY_FILE) self.add_private_key(FETCHAI, FETCHAI_PRIVATE_KEY_FILE_CONNECTION, connection=True) # fund key self.generate_wealth(FETCHAI) # set p2p configs setting_path = "vendor.fetchai.connections.p2p_libp2p.config" self.nested_set_config(setting_path, NON_GENESIS_CONFIG) # replace location setting_path = ( "vendor.fetchai.skills.weather_client.models.strategy.args.location" ) self.nested_set_config(setting_path, location) self.set_agent_context(weather_station_aea_name) self.run_cli_command("build", cwd=self._get_cwd()) self.run_cli_command("issue-certificates", cwd=self._get_cwd()) weather_station_process = self.run_agent() check_strings = ( "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", LIBP2P_SUCCESS_MESSAGE, ) missing_strings = self.missing_from_output(weather_station_process, check_strings, timeout=30, is_terminating=False) assert ( missing_strings == [] ), "Strings {} didn't appear in weather_station output.".format( missing_strings) self.set_agent_context(weather_client_aea_name) self.run_cli_command("build", cwd=self._get_cwd()) self.run_cli_command("issue-certificates", cwd=self._get_cwd()) weather_client_process = self.run_agent() check_strings = ( "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", LIBP2P_SUCCESS_MESSAGE, ) missing_strings = self.missing_from_output( weather_client_process, check_strings, timeout=30, is_terminating=False, ) assert (missing_strings == [] ), "Strings {} didn't appear in weather_client output.".format( missing_strings) check_strings = ( "registering agent on SOEF.", "registering service on SOEF.", "received CFP from sender=", "sending a PROPOSE with proposal=", "received ACCEPT from sender=", "sending MATCH_ACCEPT_W_INFORM to sender=", "received INFORM from sender=", "checking whether transaction=", "transaction confirmed, sending data=", ) missing_strings = self.missing_from_output(weather_station_process, check_strings, timeout=120, is_terminating=False) assert ( missing_strings == [] ), "Strings {} didn't appear in weather_station output.".format( missing_strings) check_strings = ( "found agents=", "sending CFP to agent=", "received proposal=", "accepting the proposal from sender=", "received MATCH_ACCEPT_W_INFORM from sender=", "requesting transfer transaction from ledger api for message=", "received raw transaction=", "proposing the transaction to the decision maker. Waiting for confirmation ...", "transaction signing was successful.", "sending transaction to ledger.", "transaction was successfully submitted. Transaction digest=", "informing counterparty=", "received INFORM from sender=", "received the following data=", ) missing_strings = self.missing_from_output(weather_client_process, check_strings, is_terminating=False) assert (missing_strings == [] ), "Strings {} didn't appear in weather_client output.".format( missing_strings) self.terminate_agents(weather_station_process, weather_client_process) assert (self.is_successfully_terminated() ), "Agents weren't successfully terminated." wait_for_localhost_ports_to_close([9000, 9001])
def test_carpark(self): """Run the weather skills sequence.""" carpark_aea_name = "my_carpark_aea" carpark_client_aea_name = "my_carpark_client_aea" self.create_agents(carpark_aea_name, carpark_client_aea_name) default_routing = { "fetchai/ledger_api:0.10.0": "fetchai/ledger:0.13.0", "fetchai/oef_search:0.13.0": "fetchai/soef:0.17.0", } # generate random location location = { "latitude": round(uniform(-90, 90), 2), # nosec "longitude": round(uniform(-180, 180), 2), # nosec } # Setup agent one self.set_agent_context(carpark_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.16.0") self.add_item("connection", "fetchai/soef:0.17.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.16.0") self.add_item("connection", "fetchai/ledger:0.13.0") self.add_item("skill", "fetchai/carpark_detection:0.19.0") setting_path = ( "vendor.fetchai.skills.carpark_detection.models.strategy.args.is_ledger_tx" ) self.set_config(setting_path, False, "bool") setting_path = "agent.default_routing" self.nested_set_config(setting_path, default_routing) self.run_install() # add keys self.generate_private_key(FETCHAI) self.generate_private_key(FETCHAI, FETCHAI_PRIVATE_KEY_FILE_CONNECTION) self.add_private_key(FETCHAI, FETCHAI_PRIVATE_KEY_FILE) self.add_private_key( FETCHAI, FETCHAI_PRIVATE_KEY_FILE_CONNECTION, connection=True ) self.replace_private_key_in_file( NON_FUNDED_FETCHAI_PRIVATE_KEY_1, FETCHAI_PRIVATE_KEY_FILE_CONNECTION ) # replace location setting_path = ( "vendor.fetchai.skills.carpark_detection.models.strategy.args.location" ) self.nested_set_config(setting_path, location) self.run_cli_command("build", cwd=self._get_cwd()) self.run_cli_command("issue-certificates", cwd=self._get_cwd()) # Setup agent two self.set_agent_context(carpark_client_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.16.0") self.add_item("connection", "fetchai/soef:0.17.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.16.0") self.add_item("connection", "fetchai/ledger:0.13.0") self.add_item("skill", "fetchai/carpark_client:0.20.0") setting_path = ( "vendor.fetchai.skills.carpark_client.models.strategy.args.is_ledger_tx" ) self.set_config(setting_path, False, "bool") setting_path = "agent.default_routing" self.nested_set_config(setting_path, default_routing) self.run_install() # add keys self.generate_private_key(FETCHAI) self.generate_private_key(FETCHAI, FETCHAI_PRIVATE_KEY_FILE_CONNECTION) self.add_private_key(FETCHAI, FETCHAI_PRIVATE_KEY_FILE) self.add_private_key( FETCHAI, FETCHAI_PRIVATE_KEY_FILE_CONNECTION, connection=True ) # set p2p configs setting_path = "vendor.fetchai.connections.p2p_libp2p.config" self.nested_set_config(setting_path, NON_GENESIS_CONFIG) # replace location setting_path = ( "vendor.fetchai.skills.carpark_client.models.strategy.args.location" ) self.nested_set_config(setting_path, location) self.run_cli_command("build", cwd=self._get_cwd()) self.run_cli_command("issue-certificates", cwd=self._get_cwd()) # Fire the sub-processes and the threads. self.set_agent_context(carpark_aea_name) carpark_aea_process = self.run_agent() check_strings = ( "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", LIBP2P_SUCCESS_MESSAGE, ) missing_strings = self.missing_from_output( carpark_aea_process, check_strings, timeout=30, is_terminating=False ) assert ( missing_strings == [] ), "Strings {} didn't appear in carpark_aea output.".format(missing_strings) self.set_agent_context(carpark_client_aea_name) carpark_client_aea_process = self.run_agent() check_strings = ( "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", LIBP2P_SUCCESS_MESSAGE, ) missing_strings = self.missing_from_output( carpark_client_aea_process, check_strings, timeout=30, is_terminating=False ) assert ( missing_strings == [] ), "Strings {} didn't appear in carpark_client_aea output.".format( missing_strings ) check_strings = ( "registering agent on SOEF.", "registering service on SOEF.", "received CFP from sender=", "sending a PROPOSE with proposal=", "received ACCEPT from sender=", "sending MATCH_ACCEPT_W_INFORM to sender=", "received INFORM from sender=", "transaction confirmed, sending data=", ) missing_strings = self.missing_from_output( carpark_aea_process, check_strings, is_terminating=False ) assert ( missing_strings == [] ), "Strings {} didn't appear in carpark_aea output.".format(missing_strings) check_strings = ( "found agents=", "sending CFP to agent=", "received proposal=", "accepting the proposal from sender=", "informing counterparty=", "received INFORM from sender=", "received the following data=", ) missing_strings = self.missing_from_output( carpark_client_aea_process, check_strings, is_terminating=False ) assert ( missing_strings == [] ), "Strings {} didn't appear in carpark_client_aea output.".format( missing_strings ) self.terminate_agents(carpark_aea_process, carpark_client_aea_process) assert ( self.is_successfully_terminated() ), "Agents weren't successfully terminated." wait_for_localhost_ports_to_close([9000, 9001])
def test_ml_skills(self, pytestconfig): """Run the ml skills sequence.""" data_provider_aea_name = "ml_data_provider" model_trainer_aea_name = "ml_model_trainer" self.create_agents(data_provider_aea_name, model_trainer_aea_name) default_routing = { "fetchai/ledger_api:0.2.0": "fetchai/ledger:0.3.0", "fetchai/oef_search:0.4.0": "fetchai/soef:0.6.0", } # generate random location location = { "latitude": round(uniform(-90, 90), 2), # nosec "longitude": round(uniform(-180, 180), 2), # nosec } # prepare data provider agent self.set_agent_context(data_provider_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.7.0") self.add_item("connection", "fetchai/soef:0.6.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.7.0") self.add_item("connection", "fetchai/ledger:0.3.0") self.add_item("skill", "fetchai/ml_data_provider:0.9.0") setting_path = "agent.default_routing" self.force_set_config(setting_path, default_routing) self.run_install() diff = self.difference_to_fetched_agent( "fetchai/ml_data_provider:0.10.0", data_provider_aea_name ) assert ( diff == [] ), "Difference between created and fetched project for files={}".format(diff) # add keys self.generate_private_key(COSMOS) self.generate_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE_CONNECTION) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE) self.add_private_key( COSMOS, COSMOS_PRIVATE_KEY_FILE_CONNECTION, connection=True ) self.replace_private_key_in_file( NON_FUNDED_COSMOS_PRIVATE_KEY_1, COSMOS_PRIVATE_KEY_FILE_CONNECTION ) # replace location setting_path = ( "vendor.fetchai.skills.ml_data_provider.models.strategy.args.location" ) self.force_set_config(setting_path, location) # prepare model trainer agent self.set_agent_context(model_trainer_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.7.0") self.add_item("connection", "fetchai/soef:0.6.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.7.0") self.add_item("connection", "fetchai/ledger:0.3.0") self.add_item("skill", "fetchai/ml_train:0.9.0") setting_path = "agent.default_routing" self.force_set_config(setting_path, default_routing) self.run_install() diff = self.difference_to_fetched_agent( "fetchai/ml_model_trainer:0.10.0", model_trainer_aea_name ) assert ( diff == [] ), "Difference between created and fetched project for files={}".format(diff) # add keys self.generate_private_key(COSMOS) self.generate_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE_CONNECTION) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE) self.add_private_key( COSMOS, COSMOS_PRIVATE_KEY_FILE_CONNECTION, connection=True ) # fund key self.generate_wealth(COSMOS) # set p2p configs setting_path = "vendor.fetchai.connections.p2p_libp2p.config" self.force_set_config(setting_path, NON_GENESIS_CONFIG) # replace location setting_path = "vendor.fetchai.skills.ml_train.models.strategy.args.location" self.force_set_config(setting_path, location) self.set_agent_context(data_provider_aea_name) data_provider_aea_process = self.run_agent() check_strings = ( "Downloading golang dependencies. This may take a while...", "Finished downloading golang dependencies.", "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", "My libp2p addresses:", ) missing_strings = self.missing_from_output( data_provider_aea_process, check_strings, timeout=240, is_terminating=False ) assert ( missing_strings == [] ), "Strings {} didn't appear in data_provider_aea output.".format( missing_strings ) self.set_agent_context(model_trainer_aea_name) model_trainer_aea_process = self.run_agent() check_strings = ( "Downloading golang dependencies. This may take a while...", "Finished downloading golang dependencies.", "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", "My libp2p addresses:", ) missing_strings = self.missing_from_output( model_trainer_aea_process, check_strings, timeout=240, is_terminating=False ) assert ( missing_strings == [] ), "Strings {} didn't appear in model_trainer_aea output.".format( missing_strings ) check_strings = ( "registering agent on SOEF.", "registering service on SOEF.", "got a Call for Terms from", "a Terms message:", "got an Accept from", "a Data message:", ) missing_strings = self.missing_from_output( data_provider_aea_process, check_strings, timeout=240, is_terminating=False ) assert ( missing_strings == [] ), "Strings {} didn't appear in data_provider_aea output.".format( missing_strings ) check_strings = ( "found agents=", "sending CFT to agent=", "received terms message from", "requesting transfer transaction from ledger api...", "received raw transaction=", "proposing the transaction to the decision maker. Waiting for confirmation ...", "transaction signing was successful.", "sending transaction to ledger.", "transaction was successfully submitted. Transaction digest=", "informing counterparty=", "received data message from", "Loss:", ) missing_strings = self.missing_from_output( model_trainer_aea_process, check_strings, is_terminating=False ) assert ( missing_strings == [] ), "Strings {} didn't appear in model_trainer_aea output.".format( missing_strings ) self.terminate_agents(data_provider_aea_process, model_trainer_aea_process) assert ( self.is_successfully_terminated() ), "Agents weren't successfully terminated." wait_for_localhost_ports_to_close([9000, 9001])
def test_weather(self): """Run the weather skills sequence.""" weather_station_aea_name = "my_weather_station" weather_client_aea_name = "my_weather_client" self.create_agents(weather_station_aea_name, weather_client_aea_name) default_routing = { "fetchai/ledger_api:0.7.0": "fetchai/ledger:0.9.0", "fetchai/oef_search:0.10.0": "fetchai/soef:0.12.0", } # generate random location location = { "latitude": round(uniform(-90, 90), 2), # nosec "longitude": round(uniform(-180, 180), 2), # nosec } # prepare agent one (weather station) self.set_agent_context(weather_station_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.12.0") self.add_item("connection", "fetchai/soef:0.12.0") self.remove_item("connection", "fetchai/stub:0.12.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.12.0") self.add_item("connection", "fetchai/ledger:0.9.0") self.add_item("skill", "fetchai/weather_station:0.15.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.12.0") dotted_path = ( "vendor.fetchai.skills.weather_station.models.strategy.args.is_ledger_tx" ) self.set_config(dotted_path, False, "bool") setting_path = "agent.default_routing" self.nested_set_config(setting_path, default_routing) self.run_install() # add keys self.generate_private_key(FETCHAI) self.generate_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE_CONNECTION) self.add_private_key(FETCHAI, FETCHAI_PRIVATE_KEY_FILE) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE_CONNECTION, connection=True) self.replace_private_key_in_file(NON_FUNDED_COSMOS_PRIVATE_KEY_1, COSMOS_PRIVATE_KEY_FILE_CONNECTION) setting_path = "vendor.fetchai.connections.p2p_libp2p.config.ledger_id" self.set_config(setting_path, COSMOS) # replace location setting_path = ( "vendor.fetchai.skills.weather_station.models.strategy.args.location" ) self.nested_set_config(setting_path, location) # prepare agent two (weather client) self.set_agent_context(weather_client_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.12.0") self.add_item("connection", "fetchai/soef:0.12.0") self.remove_item("connection", "fetchai/stub:0.12.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.12.0") self.add_item("connection", "fetchai/ledger:0.9.0") self.add_item("skill", "fetchai/weather_client:0.14.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.12.0") dotted_path = ( "vendor.fetchai.skills.weather_client.models.strategy.args.is_ledger_tx" ) self.set_config(dotted_path, False, "bool") setting_path = "agent.default_routing" self.nested_set_config(setting_path, default_routing) self.run_install() # add keys self.generate_private_key(FETCHAI) self.generate_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE_CONNECTION) self.add_private_key(FETCHAI, FETCHAI_PRIVATE_KEY_FILE) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE_CONNECTION, connection=True) # set p2p configs setting_path = "vendor.fetchai.connections.p2p_libp2p.config" self.nested_set_config(setting_path, NON_GENESIS_CONFIG) # replace location setting_path = ( "vendor.fetchai.skills.weather_client.models.strategy.args.location" ) self.nested_set_config(setting_path, location) # run agents self.set_agent_context(weather_station_aea_name) weather_station_process = self.run_agent() check_strings = ( "Downloading golang dependencies. This may take a while...", "Finished downloading golang dependencies.", "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", LIBP2P_SUCCESS_MESSAGE, ) missing_strings = self.missing_from_output(weather_station_process, check_strings, timeout=240, is_terminating=False) assert ( missing_strings == [] ), "Strings {} didn't appear in weather_station output.".format( missing_strings) self.set_agent_context(weather_client_aea_name) weather_client_process = self.run_agent() check_strings = ( "Downloading golang dependencies. This may take a while...", "Finished downloading golang dependencies.", "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", LIBP2P_SUCCESS_MESSAGE, ) missing_strings = self.missing_from_output( weather_client_process, check_strings, timeout=240, is_terminating=False, ) assert (missing_strings == [] ), "Strings {} didn't appear in weather_client output.".format( missing_strings) check_strings = ( "registering agent on SOEF.", "registering service on SOEF.", "received CFP from sender=", "sending a PROPOSE with proposal=", "received ACCEPT from sender=", "sending MATCH_ACCEPT_W_INFORM to sender=", "received INFORM from sender=", "transaction confirmed, sending data=", ) missing_strings = self.missing_from_output(weather_station_process, check_strings, is_terminating=False) assert ( missing_strings == [] ), "Strings {} didn't appear in weather_station output.".format( missing_strings) check_strings = ( "found agents=", "sending CFP to agent=", "received proposal=", "accepting the proposal from sender=", "informing counterparty=", "received INFORM from sender=", "received the following data=", ) missing_strings = self.missing_from_output(weather_client_process, check_strings, is_terminating=False) assert (missing_strings == [] ), "Strings {} didn't appear in weather_client output.".format( missing_strings) self.terminate_agents(weather_station_process, weather_client_process) assert (self.is_successfully_terminated() ), "Agents weren't successfully terminated." wait_for_localhost_ports_to_close([9000, 9001])
def test_update_skill_and_run(self): """Test that the resource folder contains scaffold handlers.py module.""" self.initialize_aea(AUTHOR) # generate random location location = { "latitude": round(uniform(-90, 90), 2), # nosec "longitude": round(uniform(-180, 180), 2), # nosec } simple_service_registration_aea = "simple_service_registration" self.fetch_agent( "fetchai/simple_service_registration:0.10.0", simple_service_registration_aea, ) self.set_agent_context(simple_service_registration_aea) # add non-funded key self.generate_private_key(COSMOS) self.generate_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE_CONNECTION) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE_CONNECTION, connection=True) self.replace_private_key_in_file(NON_FUNDED_COSMOS_PRIVATE_KEY_1, COSMOS_PRIVATE_KEY_FILE_CONNECTION) default_routing = { "fetchai/oef_search:0.4.0": "fetchai/soef:0.6.0", } # replace location setting_path = "vendor.fetchai.skills.simple_service_registration.models.strategy.args.location" self.force_set_config(setting_path, location) search_aea = "search_aea" self.create_agents(search_aea) self.set_agent_context(search_aea) skill_name = "my_search" skill_id = AUTHOR + "/" + skill_name + ":" + DEFAULT_VERSION self.scaffold_item("skill", skill_name) self.add_item("connection", "fetchai/p2p_libp2p:0.7.0") self.add_item("connection", "fetchai/soef:0.6.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.7.0") setting_path = "agent.default_routing" self.force_set_config(setting_path, default_routing) # manually change the files: path = Path(self.t, search_aea, "skills", skill_name, "behaviours.py") original = Path(AEA_DIR, "skills", "scaffold", "behaviours.py") assert filecmp.cmp(path, original) with open(path, "w") as file: file.write(self.code_blocks[0]) # block one is behaviour path = Path(self.t, search_aea, "skills", skill_name, "handlers.py") original = Path(AEA_DIR, "skills", "scaffold", "handlers.py") assert filecmp.cmp(path, original) with open(path, "w") as file: file.write(self.code_blocks[1]) # block two is handler path = Path(self.t, search_aea, "skills", skill_name, "my_model.py") original = Path(AEA_DIR, "skills", "scaffold", "my_model.py") assert filecmp.cmp(path, original) with open(path, "w") as file: file.write(self.code_blocks[2]) # block three is dialogues path_new = Path(self.t, search_aea, "skills", skill_name, "dialogues.py") os.rename(path, path_new) path = Path(self.t, search_aea, "skills", skill_name, "skill.yaml") yaml_code_block = extract_code_blocks(self.doc_path, filter="yaml") with open(path, "w") as file: file.write(yaml_code_block[0]) # block one is yaml # update fingerprint self.fingerprint_item("skill", skill_id) # add keys self.generate_private_key(COSMOS) self.generate_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE_CONNECTION) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE_CONNECTION, connection=True) # fund key self.generate_wealth(COSMOS) # set p2p configs setting_path = "vendor.fetchai.connections.p2p_libp2p.config" self.force_set_config(setting_path, NON_GENESIS_CONFIG) # replace location setting_path = "skills.{}.behaviours.my_search_behaviour.args.location".format( skill_name) self.force_set_config(setting_path, location) # run agents self.set_agent_context(simple_service_registration_aea) simple_service_registration_aea_process = self.run_agent() check_strings = ( "Downloading golang dependencies. This may take a while...", "Finished downloading golang dependencies.", "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", "My libp2p addresses:", ) missing_strings = self.missing_from_output( simple_service_registration_aea_process, check_strings, timeout=240, is_terminating=False, ) assert ( missing_strings == [] ), "Strings {} didn't appear in simple_service_registration_aea output.".format( missing_strings) self.set_agent_context(search_aea) search_aea_process = self.run_agent() check_strings = ( "Downloading golang dependencies. This may take a while...", "Finished downloading golang dependencies.", "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", "My libp2p addresses:", ) missing_strings = self.missing_from_output(search_aea_process, check_strings, timeout=240, is_terminating=False) assert (missing_strings == [] ), "Strings {} didn't appear in search_aea output.".format( missing_strings) check_strings = ( "registering agent on SOEF.", "registering service on SOEF.", ) missing_strings = self.missing_from_output( simple_service_registration_aea_process, check_strings, is_terminating=False, ) assert ( missing_strings == [] ), "Strings {} didn't appear in simple_service_registration_aea output.".format( missing_strings) check_strings = ( "sending search request to OEF search node, search_count=", "number of search requests sent=", "found number of agents=1, received search count=", ) missing_strings = self.missing_from_output(search_aea_process, check_strings, is_terminating=False) assert (missing_strings == [] ), "Strings {} didn't appear in search_aea output.".format( missing_strings) self.terminate_agents(simple_service_registration_aea_process, search_aea_process) assert (self.is_successfully_terminated() ), "Agents weren't successfully terminated." wait_for_localhost_ports_to_close([9000, 9001])
def test_thermometer(self): """Run the thermometer skills sequence.""" thermometer_aea_name = "my_thermometer" thermometer_client_aea_name = "my_thermometer_client" self.create_agents(thermometer_aea_name, thermometer_client_aea_name) default_routing = { "fetchai/ledger_api:0.2.0": "fetchai/ledger:0.3.0", "fetchai/oef_search:0.4.0": "fetchai/soef:0.6.0", } # generate random location location = { "latitude": round(uniform(-90, 90), 2), # nosec "longitude": round(uniform(-180, 180), 2), # nosec } # add packages for agent one and run it self.set_agent_context(thermometer_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.7.0") self.add_item("connection", "fetchai/soef:0.6.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.7.0") self.add_item("connection", "fetchai/ledger:0.3.0") self.add_item("skill", "fetchai/thermometer:0.9.0") setting_path = "agent.default_routing" self.force_set_config(setting_path, default_routing) self.run_install() diff = self.difference_to_fetched_agent( "fetchai/thermometer_aea:0.8.0", thermometer_aea_name) assert ( diff == [] ), "Difference between created and fetched project for files={}".format( diff) # add keys self.generate_private_key(COSMOS) self.generate_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE_CONNECTION) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE_CONNECTION, connection=True) self.replace_private_key_in_file(NON_FUNDED_COSMOS_PRIVATE_KEY_1, COSMOS_PRIVATE_KEY_FILE_CONNECTION) # replace location setting_path = "vendor.fetchai.skills.thermometer.models.strategy.args.location" self.force_set_config(setting_path, location) # add packages for agent two and run it self.set_agent_context(thermometer_client_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.7.0") self.add_item("connection", "fetchai/soef:0.6.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.7.0") self.add_item("connection", "fetchai/ledger:0.3.0") self.add_item("skill", "fetchai/thermometer_client:0.8.0") setting_path = "agent.default_routing" self.force_set_config(setting_path, default_routing) self.run_install() diff = self.difference_to_fetched_agent( "fetchai/thermometer_client:0.8.0", thermometer_client_aea_name) assert ( diff == [] ), "Difference between created and fetched project for files={}".format( diff) # add keys self.generate_private_key(COSMOS) self.generate_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE_CONNECTION) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE_CONNECTION, connection=True) # fund key self.generate_wealth(COSMOS) # set p2p configs setting_path = "vendor.fetchai.connections.p2p_libp2p.config" self.force_set_config(setting_path, NON_GENESIS_CONFIG) # replace location setting_path = ( "vendor.fetchai.skills.thermometer_client.models.strategy.args.location" ) self.force_set_config(setting_path, location) # run AEAs self.set_agent_context(thermometer_aea_name) thermometer_aea_process = self.run_agent() check_strings = ( "Downloading golang dependencies. This may take a while...", "Finished downloading golang dependencies.", "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", "My libp2p addresses:", ) missing_strings = self.missing_from_output(thermometer_aea_process, check_strings, timeout=240, is_terminating=False) assert ( missing_strings == [] ), "Strings {} didn't appear in thermometer_aea output.".format( missing_strings) self.set_agent_context(thermometer_client_aea_name) thermometer_client_aea_process = self.run_agent() check_strings = ( "Downloading golang dependencies. This may take a while...", "Finished downloading golang dependencies.", "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", "My libp2p addresses:", ) missing_strings = self.missing_from_output( thermometer_client_aea_process, check_strings, timeout=240, is_terminating=False, ) assert ( missing_strings == [] ), "Strings {} didn't appear in thermometer_client_aea output.".format( missing_strings) check_strings = ( "registering agent on SOEF.", "registering service on SOEF.", "received CFP from sender=", "sending a PROPOSE with proposal=", "received ACCEPT from sender=", "sending MATCH_ACCEPT_W_INFORM to sender=", "received INFORM from sender=", "checking whether transaction=", "transaction confirmed, sending data=", ) missing_strings = self.missing_from_output(thermometer_aea_process, check_strings, timeout=240, is_terminating=False) assert ( missing_strings == [] ), "Strings {} didn't appear in thermometer_aea output.".format( missing_strings) check_strings = ( "found agents=", "sending CFP to agent=", "received proposal=", "accepting the proposal from sender=", "received MATCH_ACCEPT_W_INFORM from sender=", "requesting transfer transaction from ledger api...", "received raw transaction=", "proposing the transaction to the decision maker. Waiting for confirmation ...", "transaction signing was successful.", "sending transaction to ledger.", "transaction was successfully submitted. Transaction digest=", "informing counterparty=", "received INFORM from sender=", "received the following data=", ) missing_strings = self.missing_from_output( thermometer_client_aea_process, check_strings, is_terminating=False) assert ( missing_strings == [] ), "Strings {} didn't appear in thermometer_client_aea output.".format( missing_strings) self.terminate_agents(thermometer_aea_process, thermometer_client_aea_process) assert (self.is_successfully_terminated() ), "Agents weren't successfully terminated." wait_for_localhost_ports_to_close([9000, 9001])
def test_ml_skills(self, pytestconfig): """Run the ml skills sequence.""" data_provider_aea_name = "ml_data_provider" model_trainer_aea_name = "ml_model_trainer" self.create_agents(data_provider_aea_name, model_trainer_aea_name) default_routing = { "fetchai/ledger_api:0.10.0": "fetchai/ledger:0.13.0", "fetchai/oef_search:0.13.0": "fetchai/soef:0.17.0", } # generate random location location = { "latitude": round(uniform(-90, 90), 2), # nosec "longitude": round(uniform(-180, 180), 2), # nosec } # prepare data provider agent self.set_agent_context(data_provider_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.16.0") self.add_item("connection", "fetchai/soef:0.17.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.16.0") self.add_item("connection", "fetchai/ledger:0.13.0") self.add_item("skill", "fetchai/ml_data_provider:0.19.0") setting_path = ( "vendor.fetchai.skills.ml_data_provider.models.strategy.args.is_ledger_tx" ) self.set_config(setting_path, False, "bool") setting_path = "agent.default_routing" self.nested_set_config(setting_path, default_routing) self.run_install() # add keys self.generate_private_key(FETCHAI) self.generate_private_key(FETCHAI, FETCHAI_PRIVATE_KEY_FILE_CONNECTION) self.add_private_key(FETCHAI, FETCHAI_PRIVATE_KEY_FILE) self.add_private_key( FETCHAI, FETCHAI_PRIVATE_KEY_FILE_CONNECTION, connection=True ) self.replace_private_key_in_file( NON_FUNDED_FETCHAI_PRIVATE_KEY_1, FETCHAI_PRIVATE_KEY_FILE_CONNECTION ) setting_path = "vendor.fetchai.connections.p2p_libp2p.config.ledger_id" self.set_config(setting_path, FETCHAI) # replace location setting_path = ( "vendor.fetchai.skills.ml_data_provider.models.strategy.args.location" ) self.nested_set_config(setting_path, location) # prepare model trainer agent self.set_agent_context(model_trainer_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.16.0") self.add_item("connection", "fetchai/soef:0.17.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.16.0") self.add_item("connection", "fetchai/ledger:0.13.0") self.add_item("skill", "fetchai/ml_train:0.21.0") setting_path = ( "vendor.fetchai.skills.ml_train.models.strategy.args.is_ledger_tx" ) self.set_config(setting_path, False, "bool") setting_path = "agent.default_routing" self.nested_set_config(setting_path, default_routing) self.run_install() # add keys self.generate_private_key(FETCHAI) self.generate_private_key(FETCHAI, FETCHAI_PRIVATE_KEY_FILE_CONNECTION) self.add_private_key(FETCHAI, FETCHAI_PRIVATE_KEY_FILE) self.add_private_key( FETCHAI, FETCHAI_PRIVATE_KEY_FILE_CONNECTION, connection=True ) # set p2p configs setting_path = "vendor.fetchai.connections.p2p_libp2p.config" self.nested_set_config(setting_path, NON_GENESIS_CONFIG) # replace location setting_path = "vendor.fetchai.skills.ml_train.models.strategy.args.location" self.nested_set_config(setting_path, location) self.set_agent_context(data_provider_aea_name) self.run_cli_command("build", cwd=self._get_cwd()) self.run_cli_command("issue-certificates", cwd=self._get_cwd()) data_provider_aea_process = self.run_agent() check_strings = ( "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", LIBP2P_SUCCESS_MESSAGE, ) missing_strings = self.missing_from_output( data_provider_aea_process, check_strings, timeout=30, is_terminating=False ) assert ( missing_strings == [] ), "Strings {} didn't appear in data_provider_aea output.".format( missing_strings ) self.set_agent_context(model_trainer_aea_name) self.run_cli_command("build", cwd=self._get_cwd()) self.run_cli_command("issue-certificates", cwd=self._get_cwd()) model_trainer_aea_process = self.run_agent() check_strings = ( "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", LIBP2P_SUCCESS_MESSAGE, ) missing_strings = self.missing_from_output( model_trainer_aea_process, check_strings, timeout=30, is_terminating=False ) assert ( missing_strings == [] ), "Strings {} didn't appear in model_trainer_aea output.".format( missing_strings ) check_strings = ( "registering agent on SOEF.", "registering service on SOEF.", "got a Call for Terms from", "a Terms message:", "got an Accept from", "a Data message:", ) missing_strings = self.missing_from_output( data_provider_aea_process, check_strings, is_terminating=False ) assert ( missing_strings == [] ), "Strings {} didn't appear in data_provider_aea output.".format( missing_strings ) check_strings = ( "found agents=", "sending CFT to agent=", "received terms message from", "sending dummy transaction digest ...", "received data message from", "Loss:", ) missing_strings = self.missing_from_output( model_trainer_aea_process, check_strings, is_terminating=False ) assert ( missing_strings == [] ), "Strings {} didn't appear in model_trainer_aea output.".format( missing_strings ) self.terminate_agents(data_provider_aea_process, model_trainer_aea_process) assert ( self.is_successfully_terminated() ), "Agents weren't successfully terminated." wait_for_localhost_ports_to_close([9000, 9001])
def test_orm_integration_docs_example(self): """Run the weather skills sequence.""" seller_aea_name = "my_thermometer_aea" buyer_aea_name = "my_thermometer_client" self.create_agents(seller_aea_name, buyer_aea_name) default_routing = { "fetchai/ledger_api:0.1.0": "fetchai/ledger:0.2.0", "fetchai/oef_search:0.3.0": "fetchai/soef:0.5.0", } # Setup seller self.set_agent_context(seller_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.5.0") self.add_item("connection", "fetchai/soef:0.5.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.5.0") self.add_item("connection", "fetchai/ledger:0.2.0") self.add_item("skill", "fetchai/thermometer:0.7.0") setting_path = "agent.default_routing" self.force_set_config(setting_path, default_routing) # ejecting changes author and version! self.eject_item("skill", "fetchai/thermometer:0.7.0") seller_skill_config_replacement = yaml.safe_load( seller_strategy_replacement) self.force_set_config( "skills.thermometer.models", seller_skill_config_replacement["models"], ) self.force_set_config( "skills.thermometer.dependencies", seller_skill_config_replacement["dependencies"], ) # Replace the seller strategy seller_stategy_path = Path( seller_aea_name, "skills", "thermometer", "strategy.py", ) self.replace_file_content(seller_stategy_path, ORM_SELLER_STRATEGY_PATH) self.fingerprint_item( "skill", "{}/thermometer:0.1.0".format(self.author), ) self.run_install() # add non-funded key self.generate_private_key(COSMOS) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE, connection=True) self.replace_private_key_in_file(NON_FUNDED_COSMOS_PRIVATE_KEY_1, COSMOS_PRIVATE_KEY_FILE) # Setup Buyer self.set_agent_context(buyer_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.5.0") self.add_item("connection", "fetchai/soef:0.5.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.5.0") self.add_item("connection", "fetchai/ledger:0.2.0") self.add_item("skill", "fetchai/thermometer_client:0.6.0") setting_path = "agent.default_routing" self.force_set_config(setting_path, default_routing) buyer_skill_config_replacement = yaml.safe_load( buyer_strategy_replacement) self.force_set_config( "vendor.fetchai.skills.thermometer_client.models", buyer_skill_config_replacement["models"], ) self.run_install() # add funded key self.generate_private_key(COSMOS) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE, connection=True) self.replace_private_key_in_file(FUNDED_COSMOS_PRIVATE_KEY_1, COSMOS_PRIVATE_KEY_FILE) setting_path = "vendor.fetchai.connections.p2p_libp2p.config" self.force_set_config(setting_path, NON_GENESIS_CONFIG) # Fire the sub-processes and the threads. self.set_agent_context(seller_aea_name) seller_aea_process = self.run_agent() check_strings = ( "Downloading golang dependencies. This may take a while...", "Finished downloading golang dependencies.", "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", "My libp2p addresses:", ) missing_strings = self.missing_from_output(seller_aea_process, check_strings, timeout=240, is_terminating=False) assert ( missing_strings == [] ), "Strings {} didn't appear in thermometer_aea output.".format( missing_strings) self.set_agent_context(buyer_aea_name) buyer_aea_process = self.run_agent() check_strings = ( "Downloading golang dependencies. This may take a while...", "Finished downloading golang dependencies.", "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", "My libp2p addresses:", ) missing_strings = self.missing_from_output( buyer_aea_process, check_strings, timeout=240, is_terminating=False, ) assert ( missing_strings == [] ), "Strings {} didn't appear in thermometer_client_aea output.".format( missing_strings) check_strings = ( "registering agent on SOEF.", "registering service on SOEF.", "received CFP from sender=", "sending a PROPOSE with proposal=", "received ACCEPT from sender=", "sending MATCH_ACCEPT_W_INFORM to sender=", "received INFORM from sender=", "checking whether transaction=", "transaction confirmed, sending data=", ) missing_strings = self.missing_from_output(seller_aea_process, check_strings, timeout=240, is_terminating=False) assert (missing_strings == [] ), "Strings {} didn't appear in seller_aea output.".format( missing_strings) check_strings = ( "found agents=", "sending CFP to agent=", "received proposal=", "accepting the proposal from sender=", "received MATCH_ACCEPT_W_INFORM from sender=", "requesting transfer transaction from ledger api...", "received raw transaction=", "proposing the transaction to the decision maker. Waiting for confirmation ...", "transaction signing was successful.", "sending transaction to ledger.", "transaction was successfully submitted. Transaction digest=", "informing counterparty=", "received INFORM from sender=", "received the following data=", ) missing_strings = self.missing_from_output(buyer_aea_process, check_strings, is_terminating=False) assert (missing_strings == [] ), "Strings {} didn't appear in buyer_aea output.".format( missing_strings) self.terminate_agents(seller_aea_process, buyer_aea_process) assert (self.is_successfully_terminated() ), "Agents weren't successfully terminated." wait_for_localhost_ports_to_close([9000, 9001])
def test_generic(self): """Run the generic skills sequence.""" deploy_aea_name = "deploy_aea" client_aea_name = "client_aea" self.create_agents(deploy_aea_name, client_aea_name) # add ethereum ledger in both configuration files default_routing = { "fetchai/ledger_api:0.10.0": "fetchai/ledger:0.13.0", "fetchai/contract_api:0.11.0": "fetchai/ledger:0.13.0", "fetchai/oef_search:0.13.0": "fetchai/soef:0.17.0", } # generate random location location = { "latitude": round(uniform(-90, 90), 2), # nosec "longitude": round(uniform(-180, 180), 2), # nosec } # add packages for agent one self.set_agent_context(deploy_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.16.0") self.add_item("connection", "fetchai/ledger:0.13.0") self.add_item("connection", "fetchai/soef:0.17.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.16.0") self.set_config("agent.default_ledger", ETHEREUM) setting_path = "agent.default_routing" self.nested_set_config(setting_path, default_routing) self.add_item("skill", "fetchai/erc1155_deploy:0.22.0") diff = self.difference_to_fetched_agent( "fetchai/erc1155_deployer:0.24.0", deploy_aea_name ) assert ( diff == [] ), "Difference between created and fetched project for files={}".format(diff) self.generate_private_key(ETHEREUM) self.add_private_key(ETHEREUM, ETHEREUM_PRIVATE_KEY_FILE) self.replace_private_key_in_file( FUNDED_ETH_PRIVATE_KEY_3, ETHEREUM_PRIVATE_KEY_FILE ) self.generate_private_key(FETCHAI, FETCHAI_PRIVATE_KEY_FILE_CONNECTION) self.add_private_key( FETCHAI, FETCHAI_PRIVATE_KEY_FILE_CONNECTION, connection=True ) self.replace_private_key_in_file( NON_FUNDED_FETCHAI_PRIVATE_KEY_1, FETCHAI_PRIVATE_KEY_FILE_CONNECTION ) setting_path = "vendor.fetchai.connections.soef.config.chain_identifier" self.set_config(setting_path, "ethereum") setting_path = "vendor.fetchai.connections.p2p_libp2p.cert_requests" settings = json.dumps( [ { "identifier": "acn", "ledger_id": ETHEREUM, "not_after": "2022-01-01", "not_before": "2021-01-01", "public_key": FETCHAI, "save_path": ".certs/conn_cert.txt", } ] ) self.set_config(setting_path, settings, type_="list") self.run_install() # replace location setting_path = ( "vendor.fetchai.skills.erc1155_deploy.models.strategy.args.location" ) self.nested_set_config(setting_path, location) # add packages for agent two self.set_agent_context(client_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.16.0") self.add_item("connection", "fetchai/ledger:0.13.0") self.add_item("connection", "fetchai/soef:0.17.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.16.0") self.set_config("agent.default_ledger", ETHEREUM) setting_path = "agent.default_routing" self.nested_set_config(setting_path, default_routing) self.add_item("skill", "fetchai/erc1155_client:0.21.0") diff = self.difference_to_fetched_agent( "fetchai/erc1155_client:0.24.0", client_aea_name ) assert ( diff == [] ), "Difference between created and fetched project for files={}".format(diff) self.generate_private_key(ETHEREUM) self.add_private_key(ETHEREUM, ETHEREUM_PRIVATE_KEY_FILE) self.replace_private_key_in_file( FUNDED_ETH_PRIVATE_KEY_2, ETHEREUM_PRIVATE_KEY_FILE ) self.generate_private_key(FETCHAI, FETCHAI_PRIVATE_KEY_FILE_CONNECTION) self.add_private_key( FETCHAI, FETCHAI_PRIVATE_KEY_FILE_CONNECTION, connection=True ) setting_path = "vendor.fetchai.connections.soef.config.chain_identifier" self.set_config(setting_path, "ethereum") setting_path = "vendor.fetchai.connections.p2p_libp2p.config" self.nested_set_config(setting_path, NON_GENESIS_CONFIG) setting_path = "vendor.fetchai.connections.p2p_libp2p.cert_requests" settings = json.dumps( [ { "identifier": "acn", "ledger_id": ETHEREUM, "not_after": "2022-01-01", "not_before": "2021-01-01", "public_key": FETCHAI, "save_path": ".certs/conn_cert.txt", } ] ) self.set_config(setting_path, settings, type_="list") self.run_install() # replace location setting_path = ( "vendor.fetchai.skills.erc1155_client.models.strategy.args.location" ) self.nested_set_config(setting_path, location) # run agents self.set_agent_context(deploy_aea_name) self.run_cli_command("build", cwd=self._get_cwd()) self.run_cli_command("issue-certificates", cwd=self._get_cwd()) deploy_aea_process = self.run_agent() check_strings = ( "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", LIBP2P_SUCCESS_MESSAGE, ) missing_strings = self.missing_from_output( deploy_aea_process, check_strings, timeout=30, is_terminating=False ) assert ( missing_strings == [] ), "Strings {} didn't appear in deploy_aea output.".format(missing_strings) check_strings = ( "starting balance on ethereum ledger=", "received raw transaction=", "proposing the transaction to the decision maker. Waiting for confirmation ...", "transaction signing was successful.", "sending transaction to ledger.", "transaction was successfully submitted. Transaction digest=", "requesting transaction receipt.", "transaction was successfully settled. Transaction receipt=", "requesting create batch transaction...", "requesting mint batch transaction...", "registering agent on SOEF.", "registering service on SOEF.", ) missing_strings = self.missing_from_output( deploy_aea_process, check_strings, timeout=420, is_terminating=False ) assert ( missing_strings == [] ), "Strings {} didn't appear in deploy_aea output.".format(missing_strings) self.set_agent_context(client_aea_name) self.run_cli_command("build", cwd=self._get_cwd()) self.run_cli_command("issue-certificates", cwd=self._get_cwd()) client_aea_process = self.run_agent() check_strings = ( "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", LIBP2P_SUCCESS_MESSAGE, ) missing_strings = self.missing_from_output( client_aea_process, check_strings, timeout=30, is_terminating=False ) assert ( missing_strings == [] ), "Strings {} didn't appear in client_aea output.".format(missing_strings) check_strings = ( "received CFP from sender=", "sending PROPOSE to agent=", "received ACCEPT_W_INFORM from sender=", "requesting single atomic swap transaction...", "received raw transaction=", "proposing the transaction to the decision maker. Waiting for confirmation ...", "transaction signing was successful.", "sending transaction to ledger.", "transaction was successfully submitted. Transaction digest=", "requesting transaction receipt.", "transaction was successfully settled. Transaction receipt=", "demo finished!", ) missing_strings = self.missing_from_output( deploy_aea_process, check_strings, timeout=360, is_terminating=False ) assert ( missing_strings == [] ), "Strings {} didn't appear in deploy_aea output.".format(missing_strings) check_strings = ( "found agents=", "sending CFP to agent=", "received valid PROPOSE from sender=", "requesting single hash message from contract api...", "received raw message=", "proposing the transaction to the decision maker. Waiting for confirmation ...", "sending ACCEPT_W_INFORM to agent=", ) missing_strings = self.missing_from_output( client_aea_process, check_strings, is_terminating=False ) assert ( missing_strings == [] ), "Strings {} didn't appear in client_aea output.".format(missing_strings) self.terminate_agents(deploy_aea_process, client_aea_process) assert ( self.is_successfully_terminated() ), "Agents weren't successfully terminated." wait_for_localhost_ports_to_close([9000, 9001])
def test_generic(self): """Run the generic skills sequence.""" deploy_aea_name = "deploy_aea" client_aea_name = "client_aea" self.create_agents(deploy_aea_name, client_aea_name) # add ethereum ledger in both configuration files default_routing = { "fetchai/ledger_api:0.2.0": "fetchai/ledger:0.3.0", "fetchai/contract_api:0.2.0": "fetchai/ledger:0.3.0", "fetchai/oef_search:0.4.0": "fetchai/soef:0.6.0", } # generate random location location = { "latitude": round(uniform(-90, 90), 2), # nosec "longitude": round(uniform(-180, 180), 2), # nosec } # add packages for agent one self.set_agent_context(deploy_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.7.0") self.add_item("connection", "fetchai/ledger:0.3.0") self.add_item("connection", "fetchai/soef:0.6.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.7.0") self.set_config("agent.default_ledger", ETHEREUM) setting_path = "agent.default_routing" self.force_set_config(setting_path, default_routing) self.add_item("skill", "fetchai/erc1155_deploy:0.11.0") diff = self.difference_to_fetched_agent( "fetchai/erc1155_deployer:0.11.0", deploy_aea_name) assert ( diff == [] ), "Difference between created and fetched project for files={}".format( diff) self.generate_private_key(ETHEREUM) self.add_private_key(ETHEREUM, ETHEREUM_PRIVATE_KEY_FILE) self.replace_private_key_in_file(FUNDED_ETH_PRIVATE_KEY_3, ETHEREUM_PRIVATE_KEY_FILE) self.generate_private_key(COSMOS) self.generate_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE_CONNECTION) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE_CONNECTION, connection=True) self.replace_private_key_in_file(NON_FUNDED_COSMOS_PRIVATE_KEY_1, COSMOS_PRIVATE_KEY_FILE_CONNECTION) setting_path = "vendor.fetchai.connections.soef.config.chain_identifier" self.set_config(setting_path, "ethereum") # stdout = self.get_wealth(ETHEREUM) # if int(stdout) < 100000000000000000: # pytest.skip("The agent needs more funds for the test to pass.") self.run_install() # replace location setting_path = ( "vendor.fetchai.skills.erc1155_deploy.models.strategy.args.location" ) self.force_set_config(setting_path, location) # add packages for agent two self.set_agent_context(client_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.7.0") self.add_item("connection", "fetchai/ledger:0.3.0") self.add_item("connection", "fetchai/soef:0.6.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.7.0") self.set_config("agent.default_ledger", ETHEREUM) setting_path = "agent.default_routing" self.force_set_config(setting_path, default_routing) self.add_item("skill", "fetchai/erc1155_client:0.10.0") diff = self.difference_to_fetched_agent( "fetchai/erc1155_client:0.11.0", client_aea_name) assert ( diff == [] ), "Difference between created and fetched project for files={}".format( diff) self.generate_private_key(ETHEREUM) self.add_private_key(ETHEREUM, ETHEREUM_PRIVATE_KEY_FILE) self.replace_private_key_in_file(FUNDED_ETH_PRIVATE_KEY_2, ETHEREUM_PRIVATE_KEY_FILE) self.generate_private_key(COSMOS) self.generate_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE_CONNECTION) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE_CONNECTION, connection=True) setting_path = "vendor.fetchai.connections.soef.config.chain_identifier" self.set_config(setting_path, "ethereum") setting_path = "vendor.fetchai.connections.p2p_libp2p.config" self.force_set_config(setting_path, NON_GENESIS_CONFIG) # stdout = self.get_wealth(ETHEREUM) # if int(stdout) < 100000000000000000: # pytest.skip("The agent needs more funds for the test to pass.") self.run_install() # replace location setting_path = ( "vendor.fetchai.skills.erc1155_client.models.strategy.args.location" ) self.force_set_config(setting_path, location) # run agents self.set_agent_context(deploy_aea_name) deploy_aea_process = self.run_agent() check_strings = ( "Downloading golang dependencies. This may take a while...", "Finished downloading golang dependencies.", "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", "My libp2p addresses:", ) missing_strings = self.missing_from_output(deploy_aea_process, check_strings, timeout=240, is_terminating=False) assert (missing_strings == [] ), "Strings {} didn't appear in deploy_aea output.".format( missing_strings) check_strings = ( "starting balance on ethereum ledger=", "received raw transaction=", "proposing the transaction to the decision maker. Waiting for confirmation ...", "transaction signing was successful.", "sending transaction to ledger.", "transaction was successfully submitted. Transaction digest=", "requesting transaction receipt.", "transaction was successfully settled. Transaction receipt=", "requesting create batch transaction...", "requesting mint batch transaction...", "registering agent on SOEF.", "registering service on SOEF.", ) missing_strings = self.missing_from_output(deploy_aea_process, check_strings, timeout=420, is_terminating=False) assert (missing_strings == [] ), "Strings {} didn't appear in deploy_aea output.".format( missing_strings) self.set_agent_context(client_aea_name) client_aea_process = self.run_agent() check_strings = ( "Downloading golang dependencies. This may take a while...", "Finished downloading golang dependencies.", "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", "My libp2p addresses:", ) missing_strings = self.missing_from_output(client_aea_process, check_strings, timeout=240, is_terminating=False) assert (missing_strings == [] ), "Strings {} didn't appear in client_aea output.".format( missing_strings) check_strings = ( "received CFP from sender=", "sending PROPOSE to agent=", "received ACCEPT_W_INFORM from sender=", "requesting single atomic swap transaction...", "received raw transaction=", "proposing the transaction to the decision maker. Waiting for confirmation ...", "transaction signing was successful.", "sending transaction to ledger.", "transaction was successfully submitted. Transaction digest=", "requesting transaction receipt.", "transaction was successfully settled. Transaction receipt=", "demo finished!", ) missing_strings = self.missing_from_output(deploy_aea_process, check_strings, timeout=360, is_terminating=False) assert (missing_strings == [] ), "Strings {} didn't appear in deploy_aea output.".format( missing_strings) check_strings = ( "found agents=", "sending CFP to agent=", "received valid PROPOSE from sender=", "requesting single hash message from contract api...", "received raw message=", "proposing the transaction to the decision maker. Waiting for confirmation ...", "sending ACCEPT_W_INFORM to agent=", ) missing_strings = self.missing_from_output(client_aea_process, check_strings, is_terminating=False) assert (missing_strings == [] ), "Strings {} didn't appear in client_aea output.".format( missing_strings) self.terminate_agents(deploy_aea_process, client_aea_process) assert (self.is_successfully_terminated() ), "Agents weren't successfully terminated." wait_for_localhost_ports_to_close([9000, 9001])
def test_generic(self, pytestconfig): """Run the generic skills sequence.""" seller_aea_name = "my_generic_seller" buyer_aea_name = "my_generic_buyer" self.create_agents(seller_aea_name, buyer_aea_name) default_routing = { "fetchai/ledger_api:0.2.0": "fetchai/ledger:0.3.0", "fetchai/oef_search:0.4.0": "fetchai/soef:0.6.0", } # generate random location location = { "latitude": round(uniform(-90, 90), 2), # nosec "longitude": round(uniform(-180, 180), 2), # nosec } # prepare seller agent self.set_agent_context(seller_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.7.0") self.add_item("connection", "fetchai/soef:0.6.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.7.0") self.add_item("connection", "fetchai/ledger:0.3.0") self.add_item("skill", "fetchai/generic_seller:0.10.0") setting_path = ( "vendor.fetchai.skills.generic_seller.models.strategy.args.is_ledger_tx" ) self.set_config(setting_path, False, "bool") setting_path = "agent.default_routing" self.force_set_config(setting_path, default_routing) self.run_install() # add keys self.generate_private_key(COSMOS) self.generate_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE_CONNECTION) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE_CONNECTION, connection=True) self.replace_private_key_in_file(NON_FUNDED_COSMOS_PRIVATE_KEY_1, COSMOS_PRIVATE_KEY_FILE_CONNECTION) # make runable: setting_path = "vendor.fetchai.skills.generic_seller.is_abstract" self.set_config(setting_path, False, "bool") # replace location setting_path = ( "vendor.fetchai.skills.generic_seller.models.strategy.args.location" ) self.force_set_config(setting_path, location) # prepare buyer agent self.set_agent_context(buyer_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.7.0") self.add_item("connection", "fetchai/soef:0.6.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.7.0") self.add_item("connection", "fetchai/ledger:0.3.0") self.add_item("skill", "fetchai/generic_buyer:0.9.0") setting_path = ( "vendor.fetchai.skills.generic_buyer.models.strategy.args.is_ledger_tx" ) self.set_config(setting_path, False, "bool") setting_path = "agent.default_routing" self.force_set_config(setting_path, default_routing) self.run_install() # add keys self.generate_private_key(COSMOS) self.generate_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE_CONNECTION) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE_CONNECTION, connection=True) # set p2p configs setting_path = "vendor.fetchai.connections.p2p_libp2p.config" self.force_set_config(setting_path, NON_GENESIS_CONFIG) # make runable: setting_path = "vendor.fetchai.skills.generic_buyer.is_abstract" self.set_config(setting_path, False, "bool") # replace location setting_path = ( "vendor.fetchai.skills.generic_buyer.models.strategy.args.location" ) self.force_set_config(setting_path, location) # run AEAs self.set_agent_context(seller_aea_name) seller_aea_process = self.run_agent() check_strings = ( "Downloading golang dependencies. This may take a while...", "Finished downloading golang dependencies.", "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", "My libp2p addresses:", ) missing_strings = self.missing_from_output(seller_aea_process, check_strings, timeout=240, is_terminating=False) assert (missing_strings == [] ), "Strings {} didn't appear in seller_aea output.".format( missing_strings) self.set_agent_context(buyer_aea_name) buyer_aea_process = self.run_agent() check_strings = ( "Downloading golang dependencies. This may take a while...", "Finished downloading golang dependencies.", "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", "My libp2p addresses:", ) missing_strings = self.missing_from_output(buyer_aea_process, check_strings, timeout=240, is_terminating=False) assert (missing_strings == [] ), "Strings {} didn't appear in buyer_aea output.".format( missing_strings) check_strings = ( "registering agent on SOEF.", "registering service on SOEF.", "received CFP from sender=", "sending a PROPOSE with proposal=", "received ACCEPT from sender=", "sending MATCH_ACCEPT_W_INFORM to sender=", "received INFORM from sender=", "transaction confirmed, sending data=", ) missing_strings = self.missing_from_output(seller_aea_process, check_strings, is_terminating=False) assert (missing_strings == [] ), "Strings {} didn't appear in seller_aea output.".format( missing_strings) check_strings = ( "found agents=", "sending CFP to agent=", "received proposal=", "accepting the proposal from sender=", "received MATCH_ACCEPT_W_INFORM from sender=", "informing counterparty=", "received INFORM from sender=", "received the following data=", ) missing_strings = self.missing_from_output(buyer_aea_process, check_strings, is_terminating=False) assert (missing_strings == [] ), "Strings {} didn't appear in buyer_aea output.".format( missing_strings) self.terminate_agents(seller_aea_process, buyer_aea_process) assert (self.is_successfully_terminated() ), "Agents weren't successfully terminated." wait_for_localhost_ports_to_close([9000, 9001])
def test_generic(self, pytestconfig): """Run the generic skills sequence.""" seller_aea_name = "my_generic_seller" buyer_aea_name = "my_generic_buyer" self.create_agents(seller_aea_name, buyer_aea_name) default_routing = { "fetchai/ledger_api:0.1.0": "fetchai/ledger:0.2.0", "fetchai/oef_search:0.3.0": "fetchai/soef:0.5.0", } # prepare seller agent self.set_agent_context(seller_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.5.0") self.add_item("connection", "fetchai/soef:0.5.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.5.0") self.add_item("connection", "fetchai/ledger:0.2.0") self.add_item("skill", "fetchai/generic_seller:0.8.0") setting_path = "agent.default_routing" self.force_set_config(setting_path, default_routing) self.run_install() diff = self.difference_to_fetched_agent("fetchai/generic_seller:0.5.0", seller_aea_name) assert ( diff == [] ), "Difference between created and fetched project for files={}".format( diff) # add non-funded key self.generate_private_key(COSMOS) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE, connection=True) self.replace_private_key_in_file(NON_FUNDED_COSMOS_PRIVATE_KEY_1, COSMOS_PRIVATE_KEY_FILE) # make runable: setting_path = "vendor.fetchai.skills.generic_seller.is_abstract" self.set_config(setting_path, False, "bool") # prepare buyer agent self.set_agent_context(buyer_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.5.0") self.add_item("connection", "fetchai/soef:0.5.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.5.0") self.add_item("connection", "fetchai/ledger:0.2.0") self.add_item("skill", "fetchai/generic_buyer:0.7.0") setting_path = "agent.default_routing" self.force_set_config(setting_path, default_routing) self.run_install() diff = self.difference_to_fetched_agent("fetchai/generic_buyer:0.5.0", buyer_aea_name) assert ( diff == [] ), "Difference between created and fetched project for files={}".format( diff) setting_path = "vendor.fetchai.skills.generic_buyer.is_abstract" self.set_config(setting_path, False, "bool") # add funded key self.generate_private_key(COSMOS) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE) self.add_private_key(COSMOS, COSMOS_PRIVATE_KEY_FILE, connection=True) self.replace_private_key_in_file(FUNDED_COSMOS_PRIVATE_KEY_1, COSMOS_PRIVATE_KEY_FILE) setting_path = "vendor.fetchai.connections.p2p_libp2p.config" self.force_set_config(setting_path, NON_GENESIS_CONFIG) # run AEAs self.set_agent_context(seller_aea_name) seller_aea_process = self.run_agent() check_strings = ( "Downloading golang dependencies. This may take a while...", "Finished downloading golang dependencies.", "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", "My libp2p addresses:", ) missing_strings = self.missing_from_output(seller_aea_process, check_strings, timeout=240, is_terminating=False) assert (missing_strings == [] ), "Strings {} didn't appear in seller_aea output.".format( missing_strings) self.set_agent_context(buyer_aea_name) buyer_aea_process = self.run_agent() check_strings = ( "Downloading golang dependencies. This may take a while...", "Finished downloading golang dependencies.", "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", "My libp2p addresses:", ) missing_strings = self.missing_from_output(buyer_aea_process, check_strings, timeout=240, is_terminating=False) assert (missing_strings == [] ), "Strings {} didn't appear in buyer_aea output.".format( missing_strings) check_strings = ( "registering agent on SOEF.", "registering service on SOEF.", "received CFP from sender=", "sending a PROPOSE with proposal=", "received ACCEPT from sender=", "sending MATCH_ACCEPT_W_INFORM to sender=", "received INFORM from sender=", "checking whether transaction=", "transaction confirmed, sending data=", ) missing_strings = self.missing_from_output(seller_aea_process, check_strings, timeout=240, is_terminating=False) assert (missing_strings == [] ), "Strings {} didn't appear in seller_aea output.".format( missing_strings) check_strings = ( "found agents=", "sending CFP to agent=", "received proposal=", "accepting the proposal from sender=", "received MATCH_ACCEPT_W_INFORM from sender=", "requesting transfer transaction from ledger api...", "received raw transaction=", "proposing the transaction to the decision maker. Waiting for confirmation ...", "transaction signing was successful.", "sending transaction to ledger.", "transaction was successfully submitted. Transaction digest=", "informing counterparty=", "received INFORM from sender=", "received the following data=", ) missing_strings = self.missing_from_output(buyer_aea_process, check_strings, is_terminating=False) assert (missing_strings == [] ), "Strings {} didn't appear in buyer_aea output.".format( missing_strings) self.terminate_agents(seller_aea_process, buyer_aea_process) assert (self.is_successfully_terminated() ), "Agents weren't successfully terminated." wait_for_localhost_ports_to_close([9000, 9001])
def test_orm_integration_docs_example(self): """Run the weather skills sequence.""" seller_aea_name = "my_thermometer_aea" buyer_aea_name = "my_thermometer_client" self.create_agents(seller_aea_name, buyer_aea_name) default_routing = { "fetchai/ledger_api:0.10.0": "fetchai/ledger:0.13.0", "fetchai/oef_search:0.13.0": "fetchai/soef:0.17.0", } # generate random location location = { "latitude": round(uniform(-90, 90), 2), # nosec "longitude": round(uniform(-180, 180), 2), # nosec } # Setup seller self.set_agent_context(seller_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.16.0") self.add_item("connection", "fetchai/soef:0.17.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.16.0") self.add_item("connection", "fetchai/ledger:0.13.0") self.add_item("skill", "fetchai/thermometer:0.19.0") setting_path = "agent.default_routing" self.nested_set_config(setting_path, default_routing) # ejecting changes author and version! self.eject_item("skill", "fetchai/thermometer:0.19.0") seller_skill_config_replacement = yaml.safe_load(seller_strategy_replacement) self.nested_set_config( "skills.thermometer.models.strategy.args", seller_skill_config_replacement["models"]["strategy"]["args"], ) self.nested_set_config( "skills.thermometer.dependencies", seller_skill_config_replacement["dependencies"], ) # Replace the seller strategy seller_stategy_path = Path( seller_aea_name, "skills", "thermometer", "strategy.py", ) self.replace_file_content(ORM_SELLER_STRATEGY_PATH, seller_stategy_path) self.fingerprint_item( "skill", "{}/thermometer:0.1.0".format(self.author), ) self.run_install() # add keys self.generate_private_key(FETCHAI) self.generate_private_key(FETCHAI, FETCHAI_PRIVATE_KEY_FILE_CONNECTION) self.add_private_key(FETCHAI, FETCHAI_PRIVATE_KEY_FILE) self.add_private_key( FETCHAI, FETCHAI_PRIVATE_KEY_FILE_CONNECTION, connection=True ) self.replace_private_key_in_file( NON_FUNDED_FETCHAI_PRIVATE_KEY_1, FETCHAI_PRIVATE_KEY_FILE_CONNECTION ) setting_path = "vendor.fetchai.connections.p2p_libp2p.config.ledger_id" self.set_config(setting_path, FETCHAI) # replace location setting_path = "skills.thermometer.models.strategy.args.location" self.nested_set_config(setting_path, location) # Setup Buyer self.set_agent_context(buyer_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.16.0") self.add_item("connection", "fetchai/soef:0.17.0") self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.16.0") self.add_item("connection", "fetchai/ledger:0.13.0") self.add_item("skill", "fetchai/thermometer_client:0.19.0") setting_path = "agent.default_routing" self.nested_set_config(setting_path, default_routing) buyer_skill_config_replacement = yaml.safe_load(buyer_strategy_replacement) self.nested_set_config( "vendor.fetchai.skills.thermometer_client.models.strategy.args", buyer_skill_config_replacement["models"]["strategy"]["args"], ) self.run_install() # add keys self.generate_private_key(FETCHAI) self.generate_private_key(FETCHAI, FETCHAI_PRIVATE_KEY_FILE_CONNECTION) self.add_private_key(FETCHAI, FETCHAI_PRIVATE_KEY_FILE) self.add_private_key( FETCHAI, FETCHAI_PRIVATE_KEY_FILE_CONNECTION, connection=True ) # fund key self.generate_wealth(FETCHAI) # set p2p configs setting_path = "vendor.fetchai.connections.p2p_libp2p.config" self.nested_set_config(setting_path, NON_GENESIS_CONFIG) # replace location setting_path = ( "vendor.fetchai.skills.thermometer_client.models.strategy.args.location" ) self.nested_set_config(setting_path, location) # Fire the sub-processes and the threads. self.set_agent_context(seller_aea_name) self.run_cli_command("build", cwd=self._get_cwd()) self.run_cli_command("issue-certificates", cwd=self._get_cwd()) seller_aea_process = self.run_agent() check_strings = ( "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", LIBP2P_SUCCESS_MESSAGE, ) missing_strings = self.missing_from_output( seller_aea_process, check_strings, timeout=30, is_terminating=False ) assert ( missing_strings == [] ), "Strings {} didn't appear in thermometer_aea output.".format(missing_strings) self.set_agent_context(buyer_aea_name) self.run_cli_command("build", cwd=self._get_cwd()) self.run_cli_command("issue-certificates", cwd=self._get_cwd()) buyer_aea_process = self.run_agent() check_strings = ( "Starting libp2p node...", "Connecting to libp2p node...", "Successfully connected to libp2p node!", LIBP2P_SUCCESS_MESSAGE, ) missing_strings = self.missing_from_output( buyer_aea_process, check_strings, timeout=30, is_terminating=False, ) assert ( missing_strings == [] ), "Strings {} didn't appear in thermometer_client_aea output.".format( missing_strings ) check_strings = ( "registering agent on SOEF.", "registering service on SOEF.", "received CFP from sender=", "sending a PROPOSE with proposal=", "received ACCEPT from sender=", "sending MATCH_ACCEPT_W_INFORM to sender=", "received INFORM from sender=", "checking whether transaction=", "transaction confirmed, sending data=", ) missing_strings = self.missing_from_output( seller_aea_process, check_strings, timeout=120, is_terminating=False ) assert ( missing_strings == [] ), "Strings {} didn't appear in seller_aea output.".format(missing_strings) check_strings = ( "found agents=", "sending CFP to agent=", "received proposal=", "accepting the proposal from sender=", "received MATCH_ACCEPT_W_INFORM from sender=", "requesting transfer transaction from ledger api for message=", "received raw transaction=", "proposing the transaction to the decision maker. Waiting for confirmation ...", "transaction signing was successful.", "sending transaction to ledger.", "transaction was successfully submitted. Transaction digest=", "informing counterparty=", "received INFORM from sender=", "received the following data=", ) missing_strings = self.missing_from_output( buyer_aea_process, check_strings, is_terminating=False ) assert ( missing_strings == [] ), "Strings {} didn't appear in buyer_aea output.".format(missing_strings) self.terminate_agents(seller_aea_process, buyer_aea_process) assert ( self.is_successfully_terminated() ), "Agents weren't successfully terminated." wait_for_localhost_ports_to_close([9000, 9001])