From febb5dcfe40e3d4d257626d479bd0744efd9b96e Mon Sep 17 00:00:00 2001 From: MarcoFavorito Date: Wed, 17 Mar 2021 09:23:39 +0100 Subject: [PATCH 1/4] update 'difference_to_fetched_agent' to load all pages of agent yaml config --- aea/test_tools/test_cases.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/aea/test_tools/test_cases.py b/aea/test_tools/test_cases.py index 18edf24dc0..fa365849ee 100644 --- a/aea/test_tools/test_cases.py +++ b/aea/test_tools/test_cases.py @@ -301,16 +301,19 @@ def is_allowed_diff_in_agent_config( with open_file( os.path.join(path_to_fetched_aea, "aea-config.yaml"), "r" ) as file: - content1 = list(yaml.safe_load_all(file))[0] # only load first page + content1 = list(yaml.safe_load_all(file)) # load all contents with open_file( os.path.join(path_to_manually_created_aea, "aea-config.yaml"), "r" ) as file: - content2 = list(yaml.safe_load_all(file))[0] - content1c = copy.deepcopy(content1) - for key, value in content1c.items(): - if content2[key] == value: - content1.pop(key) - content2.pop(key) + content2 = list(yaml.safe_load_all(file)) + + content1_agentconfig = content1[0] + content2_agentconfig = content2[0] + content1_agentconfig_copy = copy.deepcopy(content1_agentconfig) + for key, value in content1_agentconfig_copy.items(): + if content2_agentconfig[key] == value: + content1_agentconfig.pop(key) + content2_agentconfig.pop(key) allowed_diff_keys = [ "aea_version", "author", @@ -319,13 +322,15 @@ def is_allowed_diff_in_agent_config( "registry_path", "dependencies", # temporary ] - result = all([key in allowed_diff_keys for key in content1.keys()]) + result = all( + [key in allowed_diff_keys for key in content1_agentconfig.keys()] + ) result = result and all( - [key in allowed_diff_keys for key in content2.keys()] + [key in allowed_diff_keys for key in content2_agentconfig.keys()] ) if result: return result, {}, {} - return result, content1, content2 + return result, content1_agentconfig, content2_agentconfig path_to_manually_created_aea = os.path.join(cls.t, agent_name) new_cwd = os.path.join(cls.t, "fetch_dir") From 7cd0c9c8588b24f42b46454e027cf5e8669a67be Mon Sep 17 00:00:00 2001 From: MarcoFavorito Date: Wed, 17 Mar 2021 10:56:06 +0100 Subject: [PATCH 2/4] update comparison with fetched agent: add component overrides --- aea/test_tools/test_cases.py | 38 ++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/aea/test_tools/test_cases.py b/aea/test_tools/test_cases.py index fa365849ee..825317f987 100644 --- a/aea/test_tools/test_cases.py +++ b/aea/test_tools/test_cases.py @@ -20,6 +20,7 @@ import copy import logging import os +import pprint import random import shutil import string @@ -33,7 +34,7 @@ from io import TextIOWrapper from pathlib import Path from threading import Thread -from typing import Any, Callable, Dict, List, Optional, Sequence, Set, Tuple +from typing import Any, Callable, Dict, List, Optional, Sequence, Set, Tuple, Union import yaml @@ -297,7 +298,9 @@ def difference_to_fetched_agent(cls, public_id: str, agent_name: str) -> List[st # for pydocstyle def is_allowed_diff_in_agent_config( path_to_fetched_aea: str, path_to_manually_created_aea: str - ) -> Tuple[bool, Dict[str, str], Dict[str, str]]: + ) -> Tuple[ + bool, Union[Dict[str, str], List[Any]], Union[Dict[str, str], List[Any]] + ]: with open_file( os.path.join(path_to_fetched_aea, "aea-config.yaml"), "r" ) as file: @@ -310,6 +313,8 @@ def is_allowed_diff_in_agent_config( content1_agentconfig = content1[0] content2_agentconfig = content2[0] content1_agentconfig_copy = copy.deepcopy(content1_agentconfig) + + # check only agent part for key, value in content1_agentconfig_copy.items(): if content2_agentconfig[key] == value: content1_agentconfig.pop(key) @@ -328,9 +333,27 @@ def is_allowed_diff_in_agent_config( result = result and all( [key in allowed_diff_keys for key in content2_agentconfig.keys()] ) - if result: - return result, {}, {} - return result, content1_agentconfig, content2_agentconfig + if not result: + return result, content1_agentconfig, content2_agentconfig + + # else, additionally check the other YAML pages + # (i.e. the component configuration overrides) + content1_component_overrides = content1[1:] + content2_component_overrides = content2[1:] + + if len(content1_component_overrides) != len(content2_component_overrides): + return False, content1_component_overrides, content2_component_overrides + + diff_1, diff_2 = [], [] + for index, (override_1, override_2) in enumerate( + zip(content1_component_overrides, content2_component_overrides) + ): + if override_1 != override_2: + result = False + diff_1.append((index, override_1)) + diff_2.append((index, override_2)) + + return result, diff_1, diff_2 path_to_manually_created_aea = os.path.join(cls.t, agent_name) new_cwd = os.path.join(cls.t, "fetch_dir") @@ -353,7 +376,10 @@ def is_allowed_diff_in_agent_config( file_diff.remove("aea-config.yaml") # won't match! else: file_diff.append( - "Difference in aea-config.yaml: " + str(diff1) + " vs. " + str(diff2) + "Difference in aea-config.yaml: " + + pprint.pformat(diff1) + + " vs. " + + pprint.pformat(diff2) ) with suppress(OSError, IOError): From 14e96b9b4992bcb8aa06180ffabf50012d761bee Mon Sep 17 00:00:00 2001 From: MarcoFavorito Date: Wed, 17 Mar 2021 13:09:46 +0100 Subject: [PATCH 3/4] update skill integration tests for component overrides --- aea/test_tools/test_cases.py | 8 +- .../agents/erc1155_client/aea-config.yaml | 5 ++ .../agents/erc1155_deployer/aea-config.yaml | 5 ++ packages/hashes.csv | 4 +- .../test_skills_integration/test_erc1155.py | 28 +++---- .../test_simple_oracle.py | 52 ++++++------- .../test_skills_integration/test_tac.py | 75 +++++++++++-------- 7 files changed, 98 insertions(+), 79 deletions(-) diff --git a/aea/test_tools/test_cases.py b/aea/test_tools/test_cases.py index 825317f987..e26c7af2e0 100644 --- a/aea/test_tools/test_cases.py +++ b/aea/test_tools/test_cases.py @@ -20,7 +20,6 @@ import copy import logging import os -import pprint import random import shutil import string @@ -324,6 +323,8 @@ def is_allowed_diff_in_agent_config( "author", "description", "version", + "connection_private_key_paths", + "private_key_paths", "registry_path", "dependencies", # temporary ] @@ -376,10 +377,7 @@ def is_allowed_diff_in_agent_config( file_diff.remove("aea-config.yaml") # won't match! else: file_diff.append( - "Difference in aea-config.yaml: " - + pprint.pformat(diff1) - + " vs. " - + pprint.pformat(diff2) + "Difference in aea-config.yaml: " + str(diff1) + " vs. " + str(diff2) ) with suppress(OSError, IOError): diff --git a/packages/fetchai/agents/erc1155_client/aea-config.yaml b/packages/fetchai/agents/erc1155_client/aea-config.yaml index 8d622b5cf3..2e42d4b11d 100644 --- a/packages/fetchai/agents/erc1155_client/aea-config.yaml +++ b/packages/fetchai/agents/erc1155_client/aea-config.yaml @@ -42,6 +42,11 @@ dependencies: aea-ledger-fetchai: version: <0.2.0,>=0.1.0 --- +public_id: fetchai/soef:0.18.0 +type: connection +config: + chain_identifier: ethereum +--- public_id: fetchai/p2p_libp2p:0.17.0 type: connection cert_requests: diff --git a/packages/fetchai/agents/erc1155_deployer/aea-config.yaml b/packages/fetchai/agents/erc1155_deployer/aea-config.yaml index 5c19144c47..36b92235cd 100644 --- a/packages/fetchai/agents/erc1155_deployer/aea-config.yaml +++ b/packages/fetchai/agents/erc1155_deployer/aea-config.yaml @@ -42,6 +42,11 @@ dependencies: aea-ledger-fetchai: version: <0.2.0,>=0.1.0 --- +public_id: fetchai/soef:0.18.0 +type: connection +config: + chain_identifier: ethereum +--- public_id: fetchai/p2p_libp2p:0.17.0 type: connection cert_requests: diff --git a/packages/hashes.csv b/packages/hashes.csv index ed11e0f8db..d59f3f423e 100644 --- a/packages/hashes.csv +++ b/packages/hashes.csv @@ -8,8 +8,8 @@ fetchai/agents/coin_price_oracle_client,QmWyJvNu9Kw2yaE25NgGfhcQQFruMp4BQ2rD7T8Y fetchai/agents/confirmation_aea_aw1,QmfJvmeF1jt8TQ3YcjsYgairCjPGjdsnBzRt1YLNQ5Zgee fetchai/agents/confirmation_aea_aw2,QmTcBTTZxstFxoxJwsMGLBSvtaNh1a8g36n7GpidvzuAs7 fetchai/agents/confirmation_aea_aw3,QmRXHzLxwp7namnSdQ5irb8VEN7LqmmGW7axs6mwn2G2FZ -fetchai/agents/erc1155_client,QmQwqHP3gB1M4ekm8PnumKEGrcpEGMWsvhwTJcf75Pks5S -fetchai/agents/erc1155_deployer,QmRC9CcKcJ84BsL99hCqMHDPEhB3z1qwjwugL7ebjnnDR8 +fetchai/agents/erc1155_client,QmcvRb96dxx8doqPXjqX13A4jus1ixkHVmvgZrxyqnihnH +fetchai/agents/erc1155_deployer,Qmb6SS5DPvAGV1hspu9yapfdLijFaR7YNCpt6FbiDDpzfm fetchai/agents/generic_buyer,QmX8wGurQ3Lf3Ehup1FX518E1DSvhcWajVT5JcNqaifz8E fetchai/agents/generic_seller,QmU3MnSPfqQhj5fQkBN8M93vrZ4qYaxcNrACmBBg8RJ9eb fetchai/agents/gym_aea,QmTk2SRz17q5Hgk5WMswyVbVxWJUkqcMvbpjvnmxyRgVbt diff --git a/tests/test_packages/test_skills_integration/test_erc1155.py b/tests/test_packages/test_skills_integration/test_erc1155.py index 33ea2245d1..53e256530e 100644 --- a/tests/test_packages/test_skills_integration/test_erc1155.py +++ b/tests/test_packages/test_skills_integration/test_erc1155.py @@ -79,13 +79,6 @@ def test_generic(self): self.nested_set_config(setting_path, default_routing) self.add_item("skill", "fetchai/erc1155_deploy:0.23.0") - diff = self.difference_to_fetched_agent( - "fetchai/erc1155_deployer:0.25.0", deploy_aea_name - ) - assert ( - diff == [] - ), "Difference between created and fetched project for files={}".format(diff) - self.generate_private_key(EthereumCrypto.identifier) self.add_private_key(EthereumCrypto.identifier, ETHEREUM_PRIVATE_KEY_FILE) self.replace_private_key_in_file( @@ -126,6 +119,13 @@ def test_generic(self): ) self.nested_set_config(setting_path, location) + diff = self.difference_to_fetched_agent( + "fetchai/erc1155_deployer:0.25.0", deploy_aea_name + ) + assert ( + diff == [] + ), "Difference between created and fetched project for files={}".format(diff) + # add packages for agent two self.set_agent_context(client_aea_name) self.add_item("connection", "fetchai/p2p_libp2p:0.17.0") @@ -137,13 +137,6 @@ def test_generic(self): self.nested_set_config(setting_path, default_routing) self.add_item("skill", "fetchai/erc1155_client:0.22.0") - diff = self.difference_to_fetched_agent( - "fetchai/erc1155_client:0.25.0", client_aea_name - ) - assert ( - diff == [] - ), "Difference between created and fetched project for files={}".format(diff) - self.generate_private_key(EthereumCrypto.identifier) self.add_private_key(EthereumCrypto.identifier, ETHEREUM_PRIVATE_KEY_FILE) self.replace_private_key_in_file( @@ -183,6 +176,13 @@ def test_generic(self): ) self.nested_set_config(setting_path, location) + diff = self.difference_to_fetched_agent( + "fetchai/erc1155_client:0.25.0", client_aea_name + ) + assert ( + diff == [] + ), "Difference between created and fetched project for files={}".format(diff) + # run agents self.set_agent_context(deploy_aea_name) self.run_cli_command("build", cwd=self._get_cwd()) diff --git a/tests/test_packages/test_skills_integration/test_simple_oracle.py b/tests/test_packages/test_skills_integration/test_simple_oracle.py index 3202361483..f1c4cffb70 100644 --- a/tests/test_packages/test_skills_integration/test_simple_oracle.py +++ b/tests/test_packages/test_skills_integration/test_simple_oracle.py @@ -48,6 +48,9 @@ def test_oracle(self, erc20_contract, oracle_contract): oracle_agent_name = "oracle_aea" client_agent_name = "client_aea" + _, erc20_address = erc20_contract + _, oracle_address = oracle_contract + self.create_agents(oracle_agent_name, client_agent_name) # add ethereum ledger in both configuration files @@ -84,30 +87,11 @@ def test_oracle(self, erc20_contract, oracle_contract): type_="list", ) - # set erc20 address - _, erc20_address = erc20_contract - _, oracle_address = oracle_contract - - setting_path = ( - "vendor.fetchai.skills.simple_oracle.models.strategy.args.erc20_address" - ) - self.set_config(setting_path, erc20_address) - setting_path = ( - "vendor.fetchai.skills.simple_oracle.models.strategy.args.contract_address" - ) - self.set_config(setting_path, oracle_address) setting_path = ( "vendor.fetchai.skills.simple_oracle.models.strategy.args.oracle_value_name" ) self.set_config(setting_path, "price") - diff = self.difference_to_fetched_agent( - "fetchai/coin_price_oracle:0.8.0", oracle_agent_name - ) - assert ( - diff == [] - ), "Difference between created and fetched project for files={}".format(diff) - self.generate_private_key(EthereumCrypto.identifier) self.add_private_key(EthereumCrypto.identifier, ETHEREUM_PRIVATE_KEY_FILE) self.replace_private_key_in_file( @@ -137,6 +121,23 @@ def test_oracle(self, erc20_contract, oracle_contract): self.set_config(setting_path, settings, type_="list") self.run_install() + diff = self.difference_to_fetched_agent( + "fetchai/coin_price_oracle:0.8.0", oracle_agent_name + ) + assert ( + diff == [] + ), "Difference between created and fetched project for files={}".format(diff) + + # set erc20 address + setting_path = ( + "vendor.fetchai.skills.simple_oracle.models.strategy.args.erc20_address" + ) + self.set_config(setting_path, erc20_address) + setting_path = ( + "vendor.fetchai.skills.simple_oracle.models.strategy.args.contract_address" + ) + self.set_config(setting_path, oracle_address) + # add packages for oracle client agent self.set_agent_context(client_agent_name) self.add_item("connection", "fetchai/ledger:0.14.0") @@ -155,6 +156,12 @@ def test_oracle(self, erc20_contract, oracle_contract): self.add_item("contract", "fetchai/fet_erc20:0.4.0") self.add_item("skill", "fetchai/simple_oracle_client:0.5.0") + self.generate_private_key(EthereumCrypto.identifier) + self.add_private_key(EthereumCrypto.identifier, ETHEREUM_PRIVATE_KEY_FILE) + self.replace_private_key_in_file( + FUNDED_ETH_PRIVATE_KEY_2, ETHEREUM_PRIVATE_KEY_FILE + ) + diff = self.difference_to_fetched_agent( "fetchai/coin_price_oracle_client:0.5.0", client_agent_name ) @@ -162,17 +169,12 @@ def test_oracle(self, erc20_contract, oracle_contract): diff == [] ), "Difference between created and fetched project for files={}".format(diff) + # set addresses *after* comparison with fetched agent! setting_path = "vendor.fetchai.skills.simple_oracle_client.models.strategy.args.erc20_address" self.set_config(setting_path, erc20_address) setting_path = "vendor.fetchai.skills.simple_oracle_client.models.strategy.args.oracle_contract_address" self.set_config(setting_path, oracle_address) - self.generate_private_key(EthereumCrypto.identifier) - self.add_private_key(EthereumCrypto.identifier, ETHEREUM_PRIVATE_KEY_FILE) - self.replace_private_key_in_file( - FUNDED_ETH_PRIVATE_KEY_2, ETHEREUM_PRIVATE_KEY_FILE - ) - # run oracle agent self.set_agent_context(oracle_agent_name) self.run_cli_command("build", cwd=self._get_cwd()) diff --git a/tests/test_packages/test_skills_integration/test_tac.py b/tests/test_packages/test_skills_integration/test_tac.py index 4c8ad19761..e445497580 100644 --- a/tests/test_packages/test_skills_integration/test_tac.py +++ b/tests/test_packages/test_skills_integration/test_tac.py @@ -340,6 +340,7 @@ def test_tac(self): tac_aea_one, tac_aea_two, tac_controller_name, ) + # default routing (both for controller and participants) default_routing = { "fetchai/contract_api:0.12.0": "fetchai/ledger:0.14.0", "fetchai/ledger_api:0.11.0": "fetchai/ledger:0.14.0", @@ -367,13 +368,6 @@ def test_tac(self): self.nested_set_config(setting_path, default_routing) self.run_install() - diff = self.difference_to_fetched_agent( - "fetchai/tac_controller_contract:0.23.0", tac_controller_name - ) - assert ( - diff == [] - ), "Difference between created and fetched project for files={}".format(diff) - # add keys self.generate_private_key(EthereumCrypto.identifier) self.generate_private_key( @@ -421,11 +415,13 @@ def test_tac(self): setting_path = "vendor.fetchai.skills.tac_control_contract.models.parameters.args.service_data" self.nested_set_config(setting_path, data) - default_routing = { - "fetchai/contract_api:0.12.0": "fetchai/ledger:0.14.0", - "fetchai/ledger_api:0.11.0": "fetchai/ledger:0.14.0", - "fetchai/oef_search:0.14.0": "fetchai/soef:0.18.0", - } + # check manually built agent is the same as the fetched one + diff = self.difference_to_fetched_agent( + "fetchai/tac_controller_contract:0.23.0", tac_controller_name + ) + assert ( + diff == [] + ), "Difference between created and fetched project for files={}".format(diff) # prepare agents for test for agent_name, config, private_key in ( @@ -433,40 +429,28 @@ def test_tac(self): (tac_aea_two, NON_GENESIS_CONFIG_TWO, FUNDED_ETH_PRIVATE_KEY_3), ): self.set_agent_context(agent_name) + + # add items self.add_item("connection", "fetchai/p2p_libp2p:0.17.0") - self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.17.0") self.add_item("connection", "fetchai/soef:0.18.0") self.add_item("connection", "fetchai/ledger:0.14.0") self.add_item("skill", "fetchai/tac_participation:0.18.0") self.add_item("skill", "fetchai/tac_negotiation:0.21.0") + + # set AEA config (no component overrides) + self.set_config("agent.default_connection", "fetchai/p2p_libp2p:0.17.0") self.set_config("agent.default_ledger", EthereumCrypto.identifier) setting_path = "agent.default_routing" self.nested_set_config(setting_path, default_routing) - self.set_config( - "vendor.fetchai.skills.tac_participation.models.game.args.is_using_contract", - True, - "bool", - ) - self.set_config( - "vendor.fetchai.skills.tac_negotiation.models.strategy.args.is_contract_tx", - True, - "bool", - ) data = { "dotted_path": "aea.decision_maker.gop:DecisionMakerHandler", "file_path": None, } setting_path = "agent.decision_maker_handler" self.nested_set_config(setting_path, data) + + # install PyPI dependencies self.run_install() - diff = self.difference_to_fetched_agent( - "fetchai/tac_participant_contract:0.13.0", agent_name - ) - assert ( - diff == [] - ), "Difference between created and fetched project for files={}".format( - diff - ) # add keys self.generate_private_key(EthereumCrypto.identifier) @@ -499,6 +483,24 @@ def test_tac(self): ) self.set_config(setting_path, settings, type_="list") + # set SOEF configuration + setting_path = "vendor.fetchai.connections.soef.config.chain_identifier" + self.set_config(setting_path, EthereumCrypto.identifier) + + # set tac participant configuration + self.set_config( + "vendor.fetchai.skills.tac_participation.models.game.args.is_using_contract", + True, + "bool", + ) + + # set tac negotiation configuration + self.set_config( + "vendor.fetchai.skills.tac_negotiation.models.strategy.args.is_contract_tx", + True, + "bool", + ) + # replace location setting_path = ( "vendor.fetchai.skills.tac_participation.models.game.args.location" @@ -515,8 +517,15 @@ def test_tac(self): "vendor.fetchai.skills.tac_participation.models.game.args.search_query" ) self.nested_set_config(setting_path, data) - setting_path = "vendor.fetchai.connections.soef.config.chain_identifier" - self.set_config(setting_path, EthereumCrypto.identifier) + + diff = self.difference_to_fetched_agent( + "fetchai/tac_participant_contract:0.13.0", agent_name + ) + assert ( + diff == [] + ), "Difference between created and fetched project for files={}".format( + diff + ) # run tac controller self.set_agent_context(tac_controller_name) From 59bd461c557ab60decb4cae14e7f29d62c6cb8cd Mon Sep 17 00:00:00 2001 From: MarcoFavorito Date: Wed, 17 Mar 2021 15:18:23 +0100 Subject: [PATCH 4/4] fix 'TestCoinPriceSkill' test --- .../test_coin_price.py | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/tests/test_packages/test_skills_integration/test_coin_price.py b/tests/test_packages/test_skills_integration/test_coin_price.py index 0bbdcb29a1..002ea7a936 100644 --- a/tests/test_packages/test_skills_integration/test_coin_price.py +++ b/tests/test_packages/test_skills_integration/test_coin_price.py @@ -20,7 +20,6 @@ """This test module contains the integration test for the coin price skill.""" import time -from pathlib import Path from typing import Dict import pytest @@ -28,20 +27,6 @@ from aea.helpers import http_requests as requests from aea.test_tools.test_cases import AEATestCaseEmpty -from tests.conftest import ROOT_DIR - - -API_SPEC_PATH = str( - Path( - ROOT_DIR, - "packages", - "fetchai", - "skills", - "advanced_data_request", - "api_spec.yaml", - ).absolute() -) - def parse_prometheus_output(prom_data: bytes) -> Dict[str, float]: """Convert prometheus text output to a dict of {"metric": value}""" @@ -75,8 +60,10 @@ def test_coin_price(self): setting_path = "agent.default_routing" self.nested_set_config(setting_path, default_routing) + # set 'api spec path' *after* comparison with fetched agent. self.set_config( - "vendor.fetchai.connections.http_server.config.api_spec_path", API_SPEC_PATH + "vendor.fetchai.connections.http_server.config.api_spec_path", + "vendor/fetchai/skills/advanced_data_request/api_spec.yaml", ) self.set_config( "vendor.fetchai.connections.http_server.config.target_skill_id",