Skip to content

Commit

Permalink
Merge pull request #271 from valory-xyz/feat/contract-dependencies
Browse files Browse the repository at this point in the history
Feat/contract dependencies
DavidMinarsch authored Aug 19, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents fd6d615 + 6f768c3 commit 166c9a9
Showing 11 changed files with 62 additions and 13 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ AEA:
- Adds check to make sure all the packages in an AEA project are listed in the `aea-config.yaml`
- Fixes a bug related to async function call on `TCPSocketProtocol`
- Updates transaction building to handle gas estimation properly
- Update `ContractConfig` class to include contract dependencies in the depedency list

Docs:
- Adds missing command on the `http-echo-demo.md` doc.
2 changes: 1 addition & 1 deletion aea/components/base.py
Original file line number Diff line number Diff line change
@@ -185,7 +185,7 @@ def _extract_imported_packages_as_ids(
# import packages.{author}.{type_plural}.{name}
#
import_statements = re.findall(
rf"^(from|import) ({PACKAGES}\.[A-Za-z0-9_]+\.{cls.package_type_plural_regex}\.[A-Za-z0-9_]+)",
rf"^( from|from| import|import) ({PACKAGES}\.[A-Za-z0-9_]+\.{cls.package_type_plural_regex}\.[A-Za-z0-9_]+)",
module_content,
flags=re.MULTILINE,
)
8 changes: 8 additions & 0 deletions aea/configurations/base.py
Original file line number Diff line number Diff line change
@@ -1848,6 +1848,14 @@ def _create_or_update_from_json(

return instance

@property
def package_dependencies(self) -> Set[ComponentId]:
"""Get the contract dependencies."""
return {
ComponentId(ComponentType.CONTRACT, contract_id)
for contract_id in self.contracts
}


"""The following functions are called from aea.cli.utils."""

9 changes: 9 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -14,3 +14,12 @@ markers =
filterwarnings =
ignore:the imp module is deprecated in favour of importlib:DeprecationWarning
ignore:Call to deprecated create function FileDescriptor().
ignore:Call to deprecated create function Descriptor().
ignore:Call to deprecated create function FieldDescriptor().
ignore:Call to deprecated create function EnumValueDescriptor().
ignore:Call to deprecated create function EnumDescriptor().
ignore:The 'asyncio_mode' default value will change to 'strict' in future, please explicitly use 'asyncio_mode=strict' or 'asyncio_mode=auto' in pytest configuration file.
ignore:'resultcallback' has been renamed to 'result_callback'. The old name will be removed in Click 8.1.
ignore:There is no current event loop
ignore::DeprecationWarning
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2021 Valory AG
# Copyright 2021-2022 Valory AG
# Copyright 2018-2019 Fetch.AI Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -31,7 +31,7 @@
class MyScaffoldContract(Contract):
"""The scaffold contract class for a smart contract."""

contract_id = PublicId.from_str("open_aea/scaffold:0.1.0")
contract_id = PublicId.from_str("default_author/stub_0:0.1.0")

def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Init contract."""
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ license: Apache-2.0
aea_version: '>=1.0.0, <2.0.0'
fingerprint:
__init__.py: bafybeiajra74lxu4xlg4qcvqlhj7yndibsorbu24zgqgv7p3s2arjdhsdu
contract.py: bafybeifgzosz4kxg3b5yx5ovcg5cvektmewkpg27wkqqyfub43rrscvcge
contract.py: bafybeic4b3o5dx3by2wk6lvhxi4saektzargwua6slra6jvxl4env2m4zm
fingerprint_ignore_patterns: []
class_name: MyScaffoldContract
contract_interface_paths: {}
16 changes: 13 additions & 3 deletions tests/data/packages/default_author/contracts/stub_1/contract.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2021 Valory AG
# Copyright 2021-2022 Valory AG
# Copyright 2018-2019 Fetch.AI Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,16 +28,26 @@
from aea.crypto.base import LedgerApi


try:
from tests.data.packages.default_author.contracts.stub_0.contract import ( # type: ignore # noqa: F401
MyScaffoldContract as MC,
)
except ModuleNotFoundError:
from packages.default_author.contracts.stub_0.contract import ( # type: ignore # noqa: F401
MyScaffoldContract as MC,
)


class MyScaffoldContract(Contract):
"""The scaffold contract class for a smart contract."""

contract_id = PublicId.from_str("open_aea/scaffold:0.1.0")
contract_id = PublicId.from_str("default_author/stub_1:0.1.0")

def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Init contract."""
super().__init__(*args, **kwargs)
print("Contract stub_1 initialized.")
raise Exception()
raise Exception("Raised on purpose!")

@classmethod
def get_raw_transaction(
Original file line number Diff line number Diff line change
@@ -7,10 +7,10 @@ license: Apache-2.0
aea_version: '>=1.0.0, <2.0.0'
fingerprint:
__init__.py: bafybeiajra74lxu4xlg4qcvqlhj7yndibsorbu24zgqgv7p3s2arjdhsdu
contract.py: bafybeib24p4e4y7grq7lh77sgvum6ybcr24etysvrefuq5zwvz5kywdegi
contract.py: bafybeihxbf5fw25u6kqis446cbkptg7pj2n5o7xfmrbcnunttywyktknj4
fingerprint_ignore_patterns: []
class_name: MyScaffoldContract
contract_interface_paths: {}
dependencies: {}
contracts:
- default_author/stub_0:0.1.0:bafybeictk6c34rpit3ds3hw4lnnbcxdzjca4q7vjb35ukejghvsta4vtly
- default_author/stub_0:0.1.0:bafybeidicpfgwqbr54v5pca77wu6ifnf23idf5htpdrudhbwxzaavm3wyy
4 changes: 2 additions & 2 deletions tests/data/packages/hashes.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_author/contracts/stub_0,bafybeictk6c34rpit3ds3hw4lnnbcxdzjca4q7vjb35ukejghvsta4vtly
default_author/contracts/stub_1,bafybeifr6vi6svkmzzgszti3cyb4o7ckhevlafmlaltnxmgruvvbre6kba
default_author/contracts/stub_0,bafybeidicpfgwqbr54v5pca77wu6ifnf23idf5htpdrudhbwxzaavm3wyy
default_author/contracts/stub_1,bafybeibpmdrfhgz33ubww57rmmzn56g67e5xe462xiulk2p2ttezgujn5a
fetchai/protocols/t_protocol,bafybeih4ciqba3x4b2yijkxurkqwiafixxy7jgghfkvtzmsxxuawq4rmvm
fetchai/protocols/t_protocol_no_ct,bafybeibf4fp2loabpr334vko47o64dkbumso2gmpeylvk35yzkdbup4wti
open_aea/connections/scaffold,bafybeifucsl5zfe4if4zfaddud77lzwgg7emv3mr3x3us57py7vbhktb24
4 changes: 2 additions & 2 deletions tests/test_cli/test_add/test_contract_dependency.py
Original file line number Diff line number Diff line change
@@ -115,8 +115,8 @@ def _print_patch(line: str, *args, **kwargs) -> None:
with mock.patch("builtins.print", new=_print_patch):
result = self._run_command(["run"], False)

assert "Contract stub_0 initialized." in outputs
assert "Contract stub_1 initialized." in outputs
assert "Contract stub_0 initialized." in outputs
assert "Contract stub_1 initialized." in outputs

def teardown(
self,
21 changes: 21 additions & 0 deletions tests/test_configurations/test_base.py
Original file line number Diff line number Diff line change
@@ -153,6 +153,27 @@ def test_from_json_and_to_json(self, contract_path):
actual_json = actual_config.json
assert expected_json == actual_json

def test_dependencies_list(
self,
) -> None:
"""Test dependencies list property."""

dummy_contract = PublicId(author="dummy_author", name="contract")

config_file, *_ = contract_config_files
f = open(config_file)
original_json = yaml.safe_load(f)
original_json["build_directory"] = "some"
original_json["contracts"] = [
str(dummy_contract),
]

expected_config = ContractConfig.from_json(original_json)
assert isinstance(expected_config, ContractConfig)
assert expected_config.package_dependencies == {
PackageId(PackageType.CONTRACT, dummy_contract),
}


class TestConnectionConfig:
"""Test the connection configuration class."""

0 comments on commit 166c9a9

Please sign in to comment.