def test_store_token():
    ocn_auth = OceanAuth(":memory:")
    wallet = get_publisher_wallet()
    token = ocn_auth.store(wallet)
    assert ocn_auth.check(token) == wallet.address, "invalid token, check failed."
    # verify it is saved
    assert ocn_auth.restore(wallet) == token, "Restoring token failed."
Esempio n. 2
0
def test_known_token():
    """Test that a known token is invalid if its address has been changed."""
    token = (
        "0x1d2741dee30e64989ef0203957c01b14f250f5d2f6ccb0c"
        "88c9518816e4fcec16f84e545094eb3f377b7e214ded22676"
        "fbde8ca2e41b4eb1b3565047ecd9acf300-1568372035"
    )
    pub_address = "0xe2DD09d719Da89e5a3D0F2549c7E24566e947260"

    ocn_auth = OceanAuth(":memory:")
    assert ocn_auth.is_token_valid(
        token
    ), "Invalid token!! has the token specs changed?"

    def _get_timestamp():
        return int("1568372035") + 10000

    ocn_auth._get_timestamp = _get_timestamp
    address = ocn_auth.check(token)
    assert address.lower() == pub_address.lower(), (
        f"Recovered address {address} does not match "
        f"known signer address {pub_address}, if the "
        f"token generation method is changed please update "
        f"the token in this test with the new format."
    )
Esempio n. 3
0
def test_check_token(web3_instance):
    ocn_auth = OceanAuth(':memory:')
    wallet = get_publisher_wallet()

    token = ocn_auth.get(wallet)
    address = ocn_auth.check(token)
    assert address != '0x0', 'Verifying token failed.'

    sig = token.split('-')[0]
    assert ocn_auth.check(sig) == '0x0'
def test_check_token(web3_instance):
    ocn_auth = OceanAuth(":memory:")
    wallet = get_publisher_wallet()

    token = ocn_auth.get(wallet)
    address = ocn_auth.check(token)
    assert address != "0x0", "Verifying token failed."

    sig = token.split("-")[0]
    assert ocn_auth.check(sig) == "0x0"
Esempio n. 5
0
def test_get_token():
    ocn_auth = OceanAuth(':memory:')
    wallet = get_publisher_wallet()
    token = ocn_auth.get(wallet)
    assert isinstance(token, str), 'Invalid auth token type.'
    assert token.startswith('0x'), 'Invalid auth token.'
    parts = token.split('-')
    assert len(parts) == 2, 'Invalid token, timestamp separator is not found.'

    address = ocn_auth.check(token)
    assert address != '0x0', 'Verifying token failed.'
def test_get_token():
    ocn_auth = OceanAuth(":memory:")
    wallet = get_publisher_wallet()
    token = ocn_auth.get(wallet)
    assert isinstance(token, str), "Invalid auth token type."
    assert token.startswith("0x"), "Invalid auth token."
    parts = token.split("-")
    assert len(parts) == 2, "Invalid token, timestamp separator is not found."

    address = ocn_auth.check(token)
    assert address != "0x0", "Verifying token failed."
Esempio n. 7
0
def trying_algorithm_run(did, wallet, order_tx_id, nonce):
    load_dotenv(".env")
    config = Config(os.getenv('config.ini'))
    print(config.network_url)
    # config.network_url="https://rinkeby.infura.io/v3/31d95be121a545b688a0e07e4de4d256"
    ConfigProvider.set_config(config)
    ocean_auth = OceanAuth("./storage_tokens")
    token = ocean_auth.get(wallet)
    print(config.provider_url)
    ocean_compute = OceanCompute(ocean_auth, config, config.provider_url)

    job_id = ocean_compute.start(did,
                                 wallet,
                                 order_tx_id,
                                 nonce,
                                 algorithm_meta=algo_metadata)
    return job_id
Esempio n. 8
0
def test_known_token():
    token = "0x1d2741dee30e64989ef0203957c01b14f250f5d2f6ccb0c" \
            "88c9518816e4fcec16f84e545094eb3f377b7e214ded22676" \
            "fbde8ca2e41b4eb1b3565047ecd9acf300-1568372035"
    pub_address = "0xe2DD09d719Da89e5a3D0F2549c7E24566e947260"

    ocn_auth = OceanAuth(':memory:')
    assert ocn_auth.is_token_valid(
        token), f'Invalid token!! has the token specs changed?'

    def _get_timestamp():
        return int('1568372035') + 10000

    ocn_auth._get_timestamp = _get_timestamp
    address = ocn_auth.check(token)
    assert address.lower() == pub_address.lower(), f'Recovered address {address} does not match ' \
                                                   f'known signer address {pub_address}, if the ' \
                                                   f'token generation method is changed please update ' \
                                                   f'the token in this test with the new format.'
Esempio n. 9
0
def trying_compute(wallet):
    load_dotenv(".env")
    config = Config(os.getenv('config.ini'))
    print(config.network_url)
    # config.network_url="https://rinkeby.infura.io/v3/31d95be121a545b688a0e07e4de4d256"
    ConfigProvider.set_config(config)
    ocean_auth = OceanAuth("./storage_tokens")
    token = ocean_auth.get(wallet)
    # config=ConfigProvider()
    print(config.provider_url)
    ocean_compute = OceanCompute(ocean_auth, config, config.provider_url)
    build_server_attributes = OceanCompute.build_server_attributes(
        server_id="1",
        server_type="homemade",
        cpu=2,
        gpu=0,
        memory=2,
        disk=10,
        max_run_time=5000)
    compute_service_cluster_attribute = OceanCompute.build_cluster_attributes(
        cluster_type="Kubernetes", url="http://10.96.0.1/")
    compute_service_container_attributes = OceanCompute.build_container_attributes(
        image="patanae", tag="patanae", entrypoint="python")

    compute_service_provider_attributes = OceanCompute.build_service_provider_attributes(
        "forgeeks",
        description="providecompute",
        cluster=compute_service_cluster_attribute,
        containers=compute_service_container_attributes,
        servers=build_server_attributes)
    created_compute_service_attributes = OceanCompute.create_compute_service_attributes(
        creator="hello",
        provider_attributes=compute_service_provider_attributes,
        date_published="",
        timeout=20000)
    compute_service_descriptor = ocean_compute.create_compute_service_descriptor(
        created_compute_service_attributes)
Esempio n. 10
0
def test_restore_token():
    ocn_auth = OceanAuth(':memory:')
    wallet = get_publisher_wallet()
    assert ocn_auth.restore(
        wallet) is None, 'Expecting None when restoring non-existing token.'

    token = ocn_auth.store(wallet)
    assert ocn_auth.check(
        token) == wallet.address, 'invalid token, check failed.'
    # verify it is saved
    assert ocn_auth.restore(wallet) == token, 'Restoring token failed.'
def test_restore_token():
    ocn_auth = OceanAuth(":memory:")
    wallet = get_publisher_wallet()
    assert (
        ocn_auth.restore(wallet) is None
    ), "Expecting None when restoring non-existing token."

    token = ocn_auth.store(wallet)
    assert ocn_auth.check(token) == wallet.address, "invalid token, check failed."
    # verify it is saved
    assert ocn_auth.restore(wallet) == token, "Restoring token failed."
Esempio n. 12
0
    def __init__(self, config=None, data_provider=None):
        """Initialize Ocean class.

           >> # Make a new Ocean instance
           >> ocean = Ocean({...})

        This class provides the main top-level functions in ocean protocol:
         * Publish assets metadata and associated services
            * Each asset is assigned a unique DID and a DID Document (DDO)
            * The DDO contains the asset's services including the metadata
            * The DID is registered on-chain with a URL of the metadata store
              to retrieve the DDO from

            >> asset = ocean.assets.create(metadata, publisher_wallet)

         * Discover/Search assets via the current configured metadata store (Aquarius)
            >> assets_list = ocean.assets.search('search text')

        An instance of Ocean is parameterized by a `Config` instance.

        :param config: Config instance
        :param data_provider: DataServiceProvider instance
        """
        # Configuration information for the market is stored in the Config class
        # config = Config(filename=config_file, options_dict=config_dict)
        if not config:
            try:
                config = ConfigProvider.get_config()
            except AssertionError:
                config = Config(os.getenv(ENV_CONFIG_FILE))
                ConfigProvider.set_config(config)
        if isinstance(config, dict):
            # fallback to metadataStoreUri
            cache_key = ("metadataCacheUri" if ("metadataCacheUri" in config)
                         else "metadataStoreUri")
            aqua_url = config.get(
                cache_key, config.get("aquarius.url", "http://localhost:5000"))
            config_dict = {
                "eth-network": {
                    "network": config.get("network", "")
                },
                "resources": {
                    "aquarius.url":
                    aqua_url,
                    "provider.url":
                    config.get("providerUri", "http://localhost:8030"),
                },
            }
            config = Config(options_dict=config_dict)
        ConfigProvider.set_config(config)
        self._config = config
        ContractHandler.set_artifacts_path(self._config.artifacts_path)
        Web3Provider.init_web3(
            provider=get_web3_connection_provider(self._config.network_url))

        self._web3 = Web3Provider.get_web3()

        if not data_provider:
            data_provider = DataServiceProvider

        network = Web3Helper.get_network_name()
        addresses = get_contracts_addresses(network, self._config)
        self.assets = OceanAssets(
            self._config, data_provider,
            addresses.get(MetadataContract.CONTRACT_NAME))
        self.services = OceanServices()
        self.auth = OceanAuth(self._config.storage_path)
        self.compute = OceanCompute(self.auth, self._config, data_provider)

        ocean_address = get_ocean_token_address(network)
        self.pool = OceanPool(ocean_address, get_bfactory_address(network))
        self.exchange = OceanExchange(
            ocean_address,
            FixedRateExchange.configured_address(
                network or Web3Helper.get_network_name(),
                ConfigProvider.get_config().address_file,
            ),
            self.config,
        )

        logger.debug("Ocean instance initialized: ")
Esempio n. 13
0
def auth_ocean_token(wallet):
    ocean_auth = OceanAuth("./storage_tokens")
    token = ocean_auth.get(wallet)
    return ocean_auth