Skip to content

Commit

Permalink
re-enable c2d tests (#661)
Browse files Browse the repository at this point in the history
* re-enable c2d tests

* fix ci

* optimize tests speed

* temp add ssh

* cleanup runner disk space

* fix cleanup

* remove ssh

* Delete find_format function.

* Delete import.

* Updated nonce for compute for tests purpose.

* Fixed disabled asset error.

* Fixed address for test for format timestamp.

* Compare Decimals.

---------

Co-authored-by: Maria Carmina <mariacarmina.cretu@gmail.com>
  • Loading branch information
alexcos20 and mariacarmina authored Sep 6, 2023
1 parent 484e211 commit bea73c5
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 86 deletions.
27 changes: 20 additions & 7 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,35 @@ jobs:
- name: Run Barge
working-directory: ${{ github.workspace }}/barge
run: |
bash -x start_ocean.sh --no-dashboard 2>&1 --with-rbac --with-provider2 --with-thegraph --skip-subgraph-deploy > start_ocean.log &
bash -x start_ocean.sh --no-dashboard 2>&1 --with-rbac --with-provider2 --with-thegraph --with-c2d --skip-subgraph-deploy > start_ocean.log &
- name: Install dependencies
working-directory: ${{ github.workspace }}
run: |
python -m pip install --upgrade pip
pip install -r requirements_dev.txt
- name: Delete default runner images
run: |
docker image rm node:14
docker image rm node:14-alpine
docker image rm node:16
docker image rm node:16-alpine
docker image rm node:18
docker image rm node:18-alpine
docker image rm buildpack-deps:buster
docker image rm buildpack-deps:bullseye
docker image rm debian:10
docker image rm debian:11
docker image rm moby/buildkit:latest
- name: Wait for contracts deployment and C2D cluster to be ready
working-directory: ${{ github.workspace }}/barge
run: |
for i in $(seq 1 250); do
sleep 10
[ -f "$HOME/.ocean/ocean-contracts/artifacts/ready" ] && break
[ -f "$HOME/.ocean/ocean-contracts/artifacts/ready" -a -f "$HOME/.ocean/ocean-c2d/ready" ] && break
done
- name: Verify deployments
run: |
cat $HOME/.ocean/ocean-contracts/artifacts/address.json
- name: Install dependencies
working-directory: ${{ github.workspace }}
run: |
python -m pip install --upgrade pip
pip install -r requirements_dev.txt
- name: Test with pytest
run: |
coverage run --source ocean_provider -m pytest
Expand Down
2 changes: 1 addition & 1 deletion ocean_provider/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_services_endpoints():
),
)
)
for (key, value) in services_endpoints.items():
for key, value in services_endpoints.items():
services_endpoints[key] = (
list(
map(
Expand Down
10 changes: 2 additions & 8 deletions ocean_provider/utils/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX-License-Identifier: Apache-2.0
#
import logging
from _decimal import Decimal

from eth_keys import KeyAPI
from eth_keys.backends import NativeECCBackend
Expand All @@ -16,7 +17,7 @@

def verify_nonce(signer_address, nonce):
db_nonce = get_nonce(signer_address)
if db_nonce and _find_nonce_format(str(nonce)) < _find_nonce_format(str(db_nonce)):
if db_nonce and Decimal(nonce) < Decimal(db_nonce):
msg = (
f"Invalid signature expected nonce ({db_nonce}) > current nonce ({nonce})."
)
Expand Down Expand Up @@ -112,10 +113,3 @@ def sign_message(message, wallet):
signature = "0x" + r[2:] + s[2:] + v[2:]

return signature


def _find_nonce_format(nonce: str):
if "." in nonce and nonce[-1] != ".":
return float(nonce)
else:
return int(nonce)
3 changes: 2 additions & 1 deletion ocean_provider/utils/data_nft.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def get_data_nft_contract(web3: Web3, address: Optional[str] = None) -> Contract

def get_metadata(web3: Web3, address: str) -> Tuple[str, str, MetadataState, bool]:
"""Queries the ERC721 Template smart contract getMetaData call.
Returns metaDataDecryptorUrl, metaDataDecryptorAddress, metaDataState, and hasMetaData"""
Returns metaDataDecryptorUrl, metaDataDecryptorAddress, metaDataState, and hasMetaData
"""
data_nft_contract = get_data_nft_contract(web3, address)

return data_nft_contract.caller.getMetaData()
Expand Down
9 changes: 0 additions & 9 deletions ocean_provider/utils/test/test_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
get_private_key,
sign_message,
verify_signature,
_find_nonce_format,
)
from tests.helpers.nonce import build_nonce

Expand All @@ -19,14 +18,6 @@ def test_get_private_key(publisher_wallet):
)


@pytest.mark.unit
def test_find_nonce_format():
nonce = "1"
assert isinstance(_find_nonce_format(nonce), int)
nonce = "1.1"
assert isinstance(_find_nonce_format(nonce), float)


@pytest.mark.unit
def test_verify_signature(consumer_wallet, publisher_wallet):
nonce = build_nonce(consumer_wallet.address)
Expand Down
1 change: 0 additions & 1 deletion ocean_provider/utils/test/test_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@


@pytest.mark.unit
@pytest.mark.skip("C2D connection needs fixing.")
def test_get_compute_endpoint(monkeypatch):
monkeypatch.setenv("OPERATOR_SERVICE_URL", "http://with-slash.com/")
assert get_compute_endpoint() == "http://with-slash.com/api/v1/operator/compute"
Expand Down
1 change: 0 additions & 1 deletion ocean_provider/utils/test/test_provider_fees.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@


@pytest.mark.unit
@pytest.mark.skip("C2D connection needs fixing.")
@freeze_time("Feb 11th, 2012 00:00")
def test_get_provider_fee_amount(web3, publisher_wallet):
valid_until = get_future_valid_until()
Expand Down
18 changes: 0 additions & 18 deletions ocean_provider/validation/test/test_algo_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
this_is_a_gist = "https://gist.githubusercontent.com/calina-c/5e8c965962bc0240eab516cb7a180670/raw/6e6cd245c039a9aac0a488857c6927d39eaafe4d/sprintf-py-conversions"


@pytest.mark.skip("C2D connection needs fixing.")
@pytest.mark.unit
@patch("ocean_provider.validation.algo.check_asset_consumable", return_value=(True, ""))
@patch(
Expand Down Expand Up @@ -64,7 +63,6 @@ def side_effect(*args, **kwargs):
assert validator.validate() is True


@pytest.mark.skip("C2D connection needs fixing.")
@pytest.mark.unit
@patch("ocean_provider.validation.algo.check_asset_consumable", return_value=(True, ""))
@patch(
Expand Down Expand Up @@ -105,7 +103,6 @@ def test_passes_raw(provider_wallet, consumer_address, web3):
assert validator.validate() is True


@pytest.mark.skip("C2D connection needs fixing.")
@pytest.mark.unit
@patch("ocean_provider.validation.algo.check_asset_consumable", return_value=(True, ""))
@patch(
Expand Down Expand Up @@ -152,7 +149,6 @@ def side_effect(*args, **kwargs):
assert validator.message == "not_algo"


@pytest.mark.skip("C2D connection needs fixing.")
@pytest.mark.unit
@patch("ocean_provider.validation.algo.check_asset_consumable", return_value=(True, ""))
@patch(
Expand Down Expand Up @@ -253,7 +249,6 @@ def test_fails_meta_issues(provider_wallet, consumer_address, web3):
assert validator.message == "checksum_prefix"


@pytest.mark.skip("C2D connection needs fixing.")
@pytest.mark.unit
@patch("ocean_provider.validation.algo.check_asset_consumable", return_value=(True, ""))
@patch(
Expand Down Expand Up @@ -386,7 +381,6 @@ def side_effect(*args, **kwargs):
assert validator.message == "not_found"


@pytest.mark.skip("C2D connection needs fixing.")
@pytest.mark.unit
@patch("ocean_provider.validation.algo.check_asset_consumable", return_value=(True, ""))
@patch(
Expand Down Expand Up @@ -444,7 +438,6 @@ def other_service(*args, **kwargs):
assert validator.message == "service_not_access_compute"


@pytest.mark.skip("C2D connection needs fixing.")
@pytest.mark.unit
@patch("ocean_provider.validation.algo.check_asset_consumable", return_value=(True, ""))
@patch(
Expand Down Expand Up @@ -543,7 +536,6 @@ def side_effect(*args, **kwargs):
assert validator.message == "not_trusted_algo_publisher"


@pytest.mark.skip("C2D connection needs fixing.")
@pytest.mark.unit
@patch("ocean_provider.validation.algo.check_asset_consumable", return_value=(True, ""))
@patch(
Expand All @@ -568,7 +560,6 @@ def test_fails_no_asset_url(provider_wallet, consumer_address, web3):
assert validator.message == "compute_services_not_in_same_provider"


@pytest.mark.skip("C2D connection needs fixing.")
@pytest.mark.unit
@patch("ocean_provider.validation.algo.check_asset_consumable", return_value=(True, ""))
@patch("ocean_provider.validation.algo.validate_order", side_effect=Exception("mock"))
Expand All @@ -593,7 +584,6 @@ def test_fails_validate_order(provider_wallet, consumer_address, web3):
assert validator.message == "order_invalid"


@pytest.mark.skip("C2D connection needs fixing.")
@pytest.mark.unit
@patch("ocean_provider.validation.algo.check_asset_consumable", return_value=(True, ""))
@patch(
Expand Down Expand Up @@ -621,7 +611,6 @@ def test_fails_no_service_id(provider_wallet, consumer_address, web3):
assert validator.message == "missing"


@pytest.mark.skip("C2D connection needs fixing.")
@pytest.mark.unit
@patch("ocean_provider.validation.algo.check_asset_consumable", return_value=(True, ""))
@patch(
Expand Down Expand Up @@ -668,7 +657,6 @@ def side_effect(*args, **kwargs):
assert validator.message == "did_not_found"


@pytest.mark.skip("C2D connection needs fixing.")
@pytest.mark.unit
@patch("ocean_provider.validation.algo.check_asset_consumable", return_value=(True, ""))
@patch(
Expand Down Expand Up @@ -722,7 +710,6 @@ def record_consume_request_side_effect(*args, **kwargs):
assert validator.message == "in_use_or_not_on_chain"


@pytest.mark.skip("C2D connection needs fixing.")
@pytest.mark.unit
@patch("ocean_provider.validation.algo.check_asset_consumable", return_value=(True, ""))
@patch(
Expand Down Expand Up @@ -780,7 +767,6 @@ def other_service(*args, **kwargs):
assert validator.message == "main_service_compute"


@pytest.mark.skip("C2D connection needs fixing.")
@pytest.mark.unit
@patch("ocean_provider.validation.algo.check_asset_consumable", return_value=(True, ""))
@patch(
Expand Down Expand Up @@ -832,7 +818,6 @@ def side_effect(*args, **kwargs):
assert validator.message == "no_raw_algo_allowed"


@pytest.mark.skip("C2D connection needs fixing.")
@pytest.mark.unit
@patch("ocean_provider.validation.algo.check_asset_consumable", return_value=(True, ""))
@patch(
Expand Down Expand Up @@ -892,7 +877,6 @@ def another_side_effect(*args, **kwargs):
assert validator.validate() is True


@pytest.mark.skip("C2D connection needs fixing.")
@pytest.mark.unit
@patch("ocean_provider.validation.algo.check_asset_consumable", return_value=(True, ""))
@patch(
Expand Down Expand Up @@ -939,7 +923,6 @@ def another_side_effect(*args, **kwargs):
assert validator.message == "missing_meta_documentId"


@pytest.mark.skip("C2D connection needs fixing.")
@pytest.mark.unit
@patch("ocean_provider.validation.algo.check_asset_consumable", return_value=(True, ""))
@patch(
Expand Down Expand Up @@ -985,7 +968,6 @@ def side_effect(*args, **kwargs):
assert validator.message == "fees_not_paid"


@pytest.mark.skip("C2D connection needs fixing.")
@pytest.mark.unit
@patch("ocean_provider.validation.algo.check_asset_consumable", return_value=(True, ""))
@patch(
Expand Down
4 changes: 2 additions & 2 deletions tests/helpers/compute_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ocean_provider.utils.util import msg_hash
from tests.helpers.constants import ARWEAVE_TRANSACTION_ID
from tests.helpers.ddo_dict_builders import build_metadata_dict_type_algorithm
from tests.helpers.nonce import build_nonce
from tests.helpers.nonce import build_nonce, build_nonce_for_compute
from tests.test_helpers import (
get_first_service_by_type,
get_registered_asset,
Expand Down Expand Up @@ -155,7 +155,7 @@ def build_and_send_ddo_with_compute_service(


def get_compute_signature(client, consumer_wallet, did, job_id=None):
nonce = build_nonce(consumer_wallet.address)
nonce = build_nonce_for_compute()

# prepare consumer signature on did
if job_id:
Expand Down
6 changes: 6 additions & 0 deletions tests/helpers/nonce.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import time

from ocean_provider.user_nonce import get_nonce, update_nonce


Expand All @@ -11,3 +13,7 @@ def build_nonce(address) -> int:

update_nonce(address, 1)
return 1


def build_nonce_for_compute() -> int:
return time.time_ns()
Loading

0 comments on commit bea73c5

Please sign in to comment.