Exemplo n.º 1
0
def test_keeper_networks():
    keeper = Keeper()
    assert isinstance(keeper.get_network_id(), int)
    assert keeper.get_network_name(1) == Keeper._network_name_map.get(1)
    assert keeper.get_network_name(2) == Keeper._network_name_map.get(2)
    assert keeper.get_network_name(3) == Keeper._network_name_map.get(3)
    assert keeper.get_network_name(4) == Keeper._network_name_map.get(4)
    assert keeper.get_network_name(42) == Keeper._network_name_map.get(42)
    assert keeper.get_network_name(77) == Keeper._network_name_map.get(77)
    assert keeper.get_network_name(99) == Keeper._network_name_map.get(99)
    assert keeper.get_network_name(8995) == Keeper._network_name_map.get(8995)
    assert keeper.get_network_name(8996) == Keeper._network_name_map.get(8996)
    assert keeper.get_network_name(0) == 'development'
Exemplo n.º 2
0
    def __init__(self,
                 config_file,
                 http_client=None,
                 secret_store_client=None):
        """
        The Ocean class is the entry point into Ocean Protocol.
        This class is an aggregation of
         * the smart contracts via the Keeper class
         * the metadata store
         * and utilities
        Ocean is also a wrapper for the web3.py interface (https://github.com/ethereum/web3.py)
        An instance of Ocean is parameterized by a configuration file.

        :param config_file: path to configuration file
        :param http_client: http client used for sending http requests such as `requests`
        :param secret_store_client: reference to `secret_store_client.client.Client` class or similar
        """

        # Configuration information for the market is stored in the Config class
        self.config = Config(config_file)

        # For development, we use the HTTPProvider Web3 interface
        self._web3 = Web3(HTTPProvider(self.config.keeper_url))

        # With the interface loaded, the Keeper node is connected with all contracts
        self.keeper = Keeper(self._web3, self.config.keeper_path)

        # Add the Metadata store to the interface
        if self.config.aquarius_url:
            self.metadata_store = AquariusWrapper(self.config.aquarius_url)
        else:
            self.metadata_store = None

        downloads_path = os.path.join(os.getcwd(), 'downloads')
        if self.config.has_option('resources', 'downloads.path'):
            downloads_path = self.config.get(
                'resources', 'downloads.path') or downloads_path
        self._downloads_path = downloads_path

        # Collect the accounts
        self.accounts = self.get_accounts()
        assert self.accounts

        parity_address = self._web3.toChecksumAddress(
            self.config.parity_address) if self.config.parity_address else None
        if parity_address and parity_address in self.accounts:
            self.main_account = self.accounts[parity_address]
            self.main_account.password = self.config.parity_password
        else:
            self.main_account = self.accounts[self._web3.eth.accounts[0]]

        self.did_resolver = DIDResolver(self._web3, self.keeper.didregistry)

        self._http_client = http_client
        if not http_client:
            import requests
            self._http_client = requests

        self._secret_store_client = secret_store_client
        if not secret_store_client:
            from secret_store_client.client import Client
            self._secret_store_client = Client
Exemplo n.º 3
0
def test_keeper_instance():
    keeper = Keeper()
    assert keeper
    assert isinstance(keeper.get_instance(), Keeper)