Skip to content

Commit

Permalink
Merge pull request #2365 from fetchai/aea-1383
Browse files Browse the repository at this point in the history
AEA-1383 update 'difference_to_fetched_agent' to load all pages of agent yaml config
  • Loading branch information
DavidMinarsch authored Mar 17, 2021
2 parents e297268 + 59bd461 commit 73b8f7a
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 104 deletions.
57 changes: 43 additions & 14 deletions aea/test_tools/test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,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

Expand Down Expand Up @@ -297,35 +297,64 @@ 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:
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)

# check only agent part
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",
"description",
"version",
"connection_private_key_paths",
"private_key_paths",
"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
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")
Expand Down
5 changes: 5 additions & 0 deletions packages/fetchai/agents/erc1155_client/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions packages/fetchai/agents/erc1155_deployer/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions packages/hashes.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 3 additions & 16 deletions tests/test_packages/test_skills_integration/test_coin_price.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,13 @@
"""This test module contains the integration test for the coin price skill."""

import time
from pathlib import Path
from typing import Dict

import pytest

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}"""
Expand Down Expand Up @@ -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",
Expand Down
28 changes: 14 additions & 14 deletions tests/test_packages/test_skills_integration/test_erc1155.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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")
Expand All @@ -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(
Expand Down Expand Up @@ -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())
Expand Down
52 changes: 27 additions & 25 deletions tests/test_packages/test_skills_integration/test_simple_oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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")
Expand All @@ -155,24 +156,25 @@ 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
)
assert (
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())
Expand Down
Loading

0 comments on commit 73b8f7a

Please sign in to comment.