Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix validUntil usage #487

Merged
merged 10 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.0.18
current_version = 1.0.19
commit = True
tag = True

Expand Down
1 change: 0 additions & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
with:
repository: "oceanprotocol/barge"
path: 'barge'
ref: v4
- name: Login to Docker Hub
if: ${{ env.DOCKERHUB_PASSWORD && env.DOCKERHUB_USERNAME }}
run: |
Expand Down
6 changes: 3 additions & 3 deletions ocean_provider/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def __init__(self, filename=None, options_dict=None, **kwargs):
self._logger = logging.getLogger("config")

if filename:
self._logger.info(f"Config: loading config file {filename}")
self._logger.debug(f"Config: loading config file {filename}")
with open(filename) as fp:
text = fp.read()
self.read_string(text)
Expand All @@ -100,7 +100,7 @@ def __init__(self, filename=None, options_dict=None, **kwargs):
self.read_string(kwargs["text"])

if options_dict:
self._logger.info(f"Config: loading from dict {options_dict}")
self._logger.debug(f"Config: loading from dict {options_dict}")
self.read_dict(options_dict)

self._load_environ()
Expand All @@ -109,7 +109,7 @@ def _load_environ(self):
for option_name, environ_item in environ_names.items():
value = os.environ.get(environ_item[0])
if value is not None:
self._logger.info(f"Config: setting environ {option_name} = {value}")
self._logger.debug(f"Config: setting environ {option_name} = {value}")
self.set(environ_item[2], option_name, value)

@property
Expand Down
6 changes: 5 additions & 1 deletion ocean_provider/utils/basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX-License-Identifier: Apache-2.0
#
from datetime import datetime
import logging
import os
from typing import Optional, Union

Expand All @@ -15,6 +16,8 @@
from web3 import WebsocketProvider
from web3.main import Web3

logger = logging.getLogger(__name__)


def get_config(config_file: Optional[str] = None) -> Config:
"""
Expand Down Expand Up @@ -125,5 +128,6 @@ def validate_timestamp(value):
now = datetime.utcnow()

return valid_until > now
except Exception:
except Exception as e:
logger.error(f"Failed to validate timestamp {value}: {e}\n")
return False
2 changes: 1 addition & 1 deletion ocean_provider/utils/provider_fees.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def get_provider_fees_or_remote(
allow_expired_provider_fees=True,
)
log_valid_until = _provider_fees_log.args.validUntil
if datetime.utcnow().timestamp() <= log_valid_until:
if valid_until <= log_valid_until:
# already paid provider fees and both order and provider fees are still valid
return {"validOrder": dataset["transferTxId"]}
else:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
url="https://github.com/oceanprotocol/provider-py",
# fmt: off
# bumpversion needs single quotes
version='1.0.18',
version='1.0.19',
# fmt: on
zip_safe=False,
)
8 changes: 5 additions & 3 deletions tests/helpers/compute_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ def build_and_send_ddo_with_compute_service(
asset_type=None,
c2d_address=None,
do_send=True,
short_valid_until=True,
valid_until=None,
timeout=3600,
c2d_environment="ocean-compute",
):
web3 = get_web3()
if valid_until is None:
valid_until = get_future_valid_until(short=True)
algo_metadata = build_metadata_dict_type_algorithm()
if c2d_address is None:
c2d_address = consumer_wallet.address
Expand Down Expand Up @@ -95,7 +97,7 @@ def build_and_send_ddo_with_compute_service(
dataset_ddo_w_compute_service.did,
service,
consumer_wallet.address,
get_future_valid_until(short=short_valid_until),
valid_until,
c2d_environment,
),
consumer_wallet,
Expand All @@ -112,7 +114,7 @@ def build_and_send_ddo_with_compute_service(
alg_ddo.did,
alg_service,
consumer_wallet.address,
get_future_valid_until(short=short_valid_until),
valid_until,
c2d_environment,
force_zero=True,
),
Expand Down
42 changes: 27 additions & 15 deletions tests/test_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_compute_raw_algo(
free_c2d_env,
):
custom_services = "vanilla_compute" if allow_raw_algos else "norawalgo"

valid_until = get_future_valid_until()
# publish a dataset asset
dataset_ddo_w_compute_service = get_registered_asset(
publisher_wallet, custom_services=custom_services, service_type="compute"
Expand All @@ -72,7 +72,7 @@ def test_compute_raw_algo(
dataset_ddo_w_compute_service.did,
sa,
consumer_wallet.address,
get_future_valid_until(),
valid_until,
free_c2d_env["id"],
),
consumer_wallet,
Expand Down Expand Up @@ -110,14 +110,16 @@ def test_compute_raw_algo(
def test_compute_specific_algo_dids(
client, publisher_wallet, consumer_wallet, consumer_address, free_c2d_env
):
valid_until = get_future_valid_until()
ddo, tx_id, alg_ddo, _ = build_and_send_ddo_with_compute_service(
client,
publisher_wallet,
consumer_wallet,
False,
None,
free_c2d_env["consumerAddress"],
free_c2d_env["id"],
c2d_address=free_c2d_env["consumerAddress"],
valid_until=valid_until,
c2d_environment=free_c2d_env["id"],
)
sa = get_first_service_by_type(ddo, ServiceType.COMPUTE)
nonce, signature = get_compute_signature(client, consumer_wallet, ddo.did)
Expand Down Expand Up @@ -154,14 +156,16 @@ def test_compute_specific_algo_dids(

@pytest.mark.integration
def test_compute(client, publisher_wallet, consumer_wallet, free_c2d_env):
valid_until = get_future_valid_until()
ddo, tx_id, alg_ddo, alg_tx_id = build_and_send_ddo_with_compute_service(
client,
publisher_wallet,
consumer_wallet,
False,
None,
free_c2d_env["consumerAddress"],
free_c2d_env["id"],
c2d_address=free_c2d_env["consumerAddress"],
valid_until=valid_until,
c2d_environment=free_c2d_env["id"],
)
sa_compute = get_first_service_by_type(alg_ddo, ServiceType.ACCESS)
sa = get_first_service_by_type(ddo, ServiceType.COMPUTE)
Expand Down Expand Up @@ -281,14 +285,16 @@ def test_compute(client, publisher_wallet, consumer_wallet, free_c2d_env):

@pytest.mark.integration
def test_compute_diff_provider(client, publisher_wallet, consumer_wallet, free_c2d_env):
valid_until = get_future_valid_until()
ddo, tx_id, alg_ddo, alg_tx_id = build_and_send_ddo_with_compute_service(
client,
publisher_wallet,
consumer_wallet,
True,
None,
free_c2d_env["consumerAddress"],
free_c2d_env["id"],
c2d_address=free_c2d_env["consumerAddress"],
valid_until=valid_until,
c2d_environment=free_c2d_env["id"],
)
sa_compute = get_first_service_by_type(alg_ddo, ServiceType.ACCESS)
sa = get_first_service_by_type(ddo, ServiceType.COMPUTE)
Expand Down Expand Up @@ -316,14 +322,16 @@ def test_compute_diff_provider(client, publisher_wallet, consumer_wallet, free_c
def test_compute_allow_all_published(
client, publisher_wallet, consumer_wallet, free_c2d_env
):
valid_until = get_future_valid_until()
ddo, tx_id, alg_ddo, alg_tx_id = build_and_send_ddo_with_compute_service(
client,
publisher_wallet,
consumer_wallet,
False,
"allow_all_published",
free_c2d_env["consumerAddress"],
free_c2d_env["id"],
c2d_address=free_c2d_env["consumerAddress"],
valid_until=valid_until,
c2d_environment=free_c2d_env["id"],
)
sa_compute = get_first_service_by_type(alg_ddo, ServiceType.ACCESS)
sa = get_first_service_by_type(ddo, ServiceType.COMPUTE)
Expand Down Expand Up @@ -364,14 +372,16 @@ def test_compute_allow_all_published(
def test_compute_additional_input(
client, publisher_wallet, consumer_wallet, monkeypatch, free_c2d_env
):
valid_until = get_future_valid_until()
ddo, tx_id, alg_ddo, alg_tx_id = build_and_send_ddo_with_compute_service(
client,
publisher_wallet,
consumer_wallet,
False,
None,
free_c2d_env["consumerAddress"],
free_c2d_env["id"],
c2d_address=free_c2d_env["consumerAddress"],
valid_until=valid_until,
c2d_environment=free_c2d_env["id"],
)
sa_compute = get_first_service_by_type(alg_ddo, ServiceType.ACCESS)
sa = get_first_service_by_type(ddo, ServiceType.COMPUTE)
Expand All @@ -398,7 +408,7 @@ def test_compute_additional_input(
ddo2.did,
sa2,
consumer_wallet.address,
get_future_valid_until(),
valid_until,
free_c2d_env["id"],
force_zero=True,
),
Expand Down Expand Up @@ -448,14 +458,16 @@ def test_compute_additional_input(
def test_compute_delete_job(
client, publisher_wallet, consumer_wallet, consumer_address, free_c2d_env
):
valid_until = get_future_valid_until()
ddo, tx_id, alg_ddo, alg_tx_id = build_and_send_ddo_with_compute_service(
client,
publisher_wallet,
consumer_wallet,
False,
None,
free_c2d_env["consumerAddress"],
free_c2d_env["id"],
c2d_address=free_c2d_env["consumerAddress"],
valid_until=valid_until,
c2d_environment=free_c2d_env["id"],
)
sa_compute = get_first_service_by_type(alg_ddo, ServiceType.ACCESS)
sa = get_first_service_by_type(ddo, ServiceType.COMPUTE)
Expand Down
13 changes: 7 additions & 6 deletions tests/test_initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,16 @@ def test_initialize_compute_order_reused(
Case 4:
wrong tx id for dataset order
"""
# Order asset, valid for 60 seconds
# Order asset, valid for 30 seconds
valid_until = get_future_valid_until(short=True)
ddo, tx_id, alg_ddo, alg_tx_id = build_and_send_ddo_with_compute_service(
client,
publisher_wallet,
consumer_wallet,
True,
None,
free_c2d_env["consumerAddress"],
short_valid_until=True,
valid_until,
timeout=60,
c2d_environment=free_c2d_env["id"],
)
Expand All @@ -280,7 +281,7 @@ def test_initialize_compute_order_reused(
"consumerAddress": consumer_wallet.address,
"compute": {
"env": free_c2d_env["id"],
"validUntil": get_future_valid_until(short=True),
"validUntil": valid_until,
},
}

Expand All @@ -297,12 +298,10 @@ def test_initialize_compute_order_reused(
assert "providerFee" not in response.json["datasets"][0]
assert "providerFee" not in response.json["algorithm"]

# Update payload "validUntil" to 1 hour from now
payload["compute"]["validUntil"] = get_future_valid_until()

# Sleep long enough for provider fees to expire
timeout = time.time() + (30 * 4)
while True:
payload["compute"]["validUntil"] = get_future_valid_until(short=True) + 30
response = client.post(
BaseURLs.SERVICES_URL + "/initializeCompute",
data=json.dumps(payload),
Expand All @@ -320,7 +319,9 @@ def test_initialize_compute_order_reused(
assert "providerFee" in response.json["algorithm"]

# Sleep long enough for orders to expire
timeout = time.time() + (30 * 4)
while True:
payload["compute"]["validUntil"] = get_future_valid_until(short=True) + 30
response = client.post(
BaseURLs.SERVICES_URL + "/initializeCompute",
data=json.dumps(payload),
Expand Down