コード例 #1
0
def dummy_contract(request):
    directory = Path(ROOT_DIR, "tests", "data", "dummy_contract")
    configuration = ComponentConfiguration.load(ComponentType.CONTRACT,
                                                directory)
    configuration._directory = directory
    configuration = cast(ContractConfig, configuration)

    if str(configuration.public_id) in contract_registry.specs:
        contract_registry.specs.pop(str(configuration.public_id))

    # load into sys modules
    Contract.from_config(configuration)

    # load into registry
    path = Path(configuration.directory,
                configuration.path_to_contract_interface)
    with open(path, "r") as interface_file:
        contract_interface = json.load(interface_file)

    contract_registry.register(
        id_=str(configuration.public_id),
        entry_point=
        f"{configuration.prefix_import_path}.contract:{configuration.class_name}",
        class_kwargs={"contract_interface": contract_interface},
        contract_config=configuration,
    )
    contract = contract_registry.make(str(configuration.public_id))
    yield contract
    contract_registry.specs.pop(str(configuration.public_id))
コード例 #2
0
    def set_contract(self):
        """Set contract."""
        directory = Path(ROOT_DIR, "packages", "fetchai", "contracts",
                         "erc1155")
        configuration = load_component_configuration(ComponentType.CONTRACT,
                                                     directory)
        configuration._directory = directory
        configuration = cast(ContractConfig, configuration)

        if str(configuration.public_id) not in contract_registry.specs:
            # load contract into sys modules
            Contract.from_config(configuration)

        self.contract = contract_registry.make(str(configuration.public_id))
コード例 #3
0
def test_from_config_and_registration():
    """Tests the from config method and contract registry registration."""

    directory = Path(ROOT_DIR, "tests", "data", "dummy_contract")
    configuration = ComponentConfiguration.load(ComponentType.CONTRACT, directory)
    configuration._directory = directory
    configuration = cast(ContractConfig, configuration)

    if str(configuration.public_id) in contract_registry.specs:
        contract_registry.specs.pop(str(configuration.public_id))

    contract = Contract.from_config(configuration)
    assert contract is not None
    assert contract.contract_interface is None
    assert contract.configuration == configuration
    assert contract.id == configuration.public_id

    contract_registry.register(
        id_=str(configuration.public_id),
        entry_point=f"{configuration.prefix_import_path}.contract:{configuration.class_name}",
        class_kwargs={"contract_interface": configuration.contract_interfaces},
        contract_config=configuration,
    )

    contract = contract_registry.make(str(configuration.public_id))
    assert contract is not None
    assert contract.configuration == configuration
    assert contract.contract_interface is not None
コード例 #4
0
def test_from_config_and_registration():
    """Tests the from config method and contract registry registration."""

    directory = Path(ROOT_DIR, "tests", "data", "dummy_contract")
    configuration = load_component_configuration(ComponentType.CONTRACT,
                                                 directory)
    configuration._directory = directory
    configuration = cast(ContractConfig, configuration)

    if str(configuration.public_id) in contract_registry.specs:
        contract_registry.specs.pop(str(configuration.public_id))

    contract = Contract.from_config(configuration)
    assert contract is not None
    assert contract.contract_interface is not None
    assert isinstance(contract.contract_interface, dict)
    assert contract.configuration == configuration
    assert contract.id == configuration.public_id

    # the contract is registered as side-effect
    assert str(contract.public_id) in contract_registry.specs

    try:
        contract_registry.specs.pop(str(configuration.public_id))
    except Exception as e:
        logger.exception(e)
コード例 #5
0
ファイル: conftest.py プロジェクト: hame58gp/agents-aea
def erc1155_contract():
    """
    Instantiate an ERC1155 contract instance.

    As a side effect, register it to the registry, if not already registered.
    """
    directory = Path(ROOT_DIR, "packages", "fetchai", "contracts", "erc1155")
    configuration = load_component_configuration(ComponentType.CONTRACT,
                                                 directory)
    configuration._directory = directory
    configuration = cast(ContractConfig, configuration)

    if str(configuration.public_id) not in contract_registry.specs:
        # load contract into sys modules
        Contract.from_config(configuration)

    contract = contract_registry.make(str(configuration.public_id))
    yield contract
コード例 #6
0
ファイル: aea_builder.py プロジェクト: pbukva/agents-aea
 def _load_and_add_contracts(self) -> None:
     for configuration in self._package_dependency_manager.contracts.values():
         configuration = cast(ContractConfig, configuration)
         try:
             contract = Contract.from_config(configuration)
         except Exception as e:
             raise Exception(
                 "An error occurred while loading contract {}: {}".format(
                     configuration.public_id, str(e)
                 )
             )
         self._add_component_to_resources(contract)
コード例 #7
0
ファイル: test_base.py プロジェクト: hame58gp/agents-aea
def dummy_contract(request):
    """Dummy contract fixture."""
    directory = Path(ROOT_DIR, "tests", "data", "dummy_contract")
    configuration = load_component_configuration(ComponentType.CONTRACT, directory)
    configuration._directory = directory
    configuration = cast(ContractConfig, configuration)

    if str(configuration.public_id) in contract_registry.specs:
        contract_registry.specs.pop(str(configuration.public_id))

    # load into sys modules and register into contract registry
    contract = Contract.from_config(configuration)
    yield contract
    contract_registry.specs.pop(str(configuration.public_id))
コード例 #8
0
def test_from_config_negative():
    """Tests the from config method raises."""

    directory = Path(ROOT_DIR, "tests", "data", "dummy_contract")
    configuration = load_component_configuration(ComponentType.CONTRACT,
                                                 directory)
    configuration._directory = directory
    configuration = cast(ContractConfig, configuration)

    if str(configuration.public_id) in contract_registry.specs:
        contract_registry.specs.pop(str(configuration.public_id))

    configuration.class_name = "WrongName"
    with pytest.raises(AEAComponentLoadException):
        _ = Contract.from_config(configuration)

    try:
        contract_registry.specs.pop(str(configuration.public_id))
    except Exception as e:
        logger.exception(e)