From 1815cd40b2c8e0ebdc2872a75ae7736d1dd0acce Mon Sep 17 00:00:00 2001 From: shadeofblue Date: Wed, 7 Jun 2023 08:46:07 +0200 Subject: [PATCH 1/9] update the default payment network to `goerli` --- examples/utils/__init__.py | 2 +- yapapi/engine.py | 4 ++-- yapapi/golem.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/utils/__init__.py b/examples/utils/__init__.py index 2a6563527..a1bf0259e 100644 --- a/examples/utils/__init__.py +++ b/examples/utils/__init__.py @@ -33,7 +33,7 @@ def build_parser(description: str) -> argparse.ArgumentParser: "--payment-driver", "--driver", help="Payment driver name, for example `erc20`" ) parser.add_argument( - "--payment-network", "--network", help="Payment network name, for example `rinkeby`" + "--payment-network", "--network", help="Payment network name, for example `goerli`" ) parser.add_argument("--subnet-tag", help="Subnet name, for example `public`") parser.add_argument( diff --git a/yapapi/engine.py b/yapapi/engine.py index c286375dc..d4e42c896 100644 --- a/yapapi/engine.py +++ b/yapapi/engine.py @@ -52,7 +52,7 @@ ) DEFAULT_DRIVER: str = os.getenv("YAGNA_PAYMENT_DRIVER", "erc20").lower() -DEFAULT_NETWORK: str = os.getenv("YAGNA_PAYMENT_NETWORK", "rinkeby").lower() +DEFAULT_NETWORK: str = os.getenv("YAGNA_PAYMENT_NETWORK", "goerli").lower() DEFAULT_SUBNET: Optional[str] = os.getenv("YAGNA_SUBNET", "public") MAX_CONCURRENTLY_PROCESSED_DEBIT_NOTES: Final[int] = 10 @@ -119,7 +119,7 @@ def __init__( environment variable, defaults to `erc20`. Only payment platforms with the specified driver will be used :param payment_network: name of the payment network to use. Uses `YAGNA_PAYMENT_NETWORK` - environment variable, defaults to `rinkeby`. Only payment platforms with the specified + environment variable, defaults to `goerli`. Only payment platforms with the specified network will be used :param stream_output: stream computation output from providers :param app_key: optional Yagna application key. If not provided, the default is to diff --git a/yapapi/golem.py b/yapapi/golem.py index 272996b7d..2c70031e6 100644 --- a/yapapi/golem.py +++ b/yapapi/golem.py @@ -116,7 +116,7 @@ def __init__( environment variable, defaults to `erc20`. Only payment platforms with the specified driver will be used :param payment_network: name of the network to use. Uses `YAGNA_NETWORK` environment - variable, defaults to `rinkeby`. Only payment platforms with the specified + variable, defaults to `goerli`. Only payment platforms with the specified network will be used :param event_consumer: a callable that processes events related to the computation; by default it is a function that logs all events From 9c258364364accf80dfe52cddf779a7cd3af5d7d Mon Sep 17 00:00:00 2001 From: shadeofblue Date: Wed, 7 Jun 2023 08:53:25 +0200 Subject: [PATCH 2/9] fix the test suite runs --- .github/workflows/build_publish.yml | 24 ++++++++---------------- .github/workflows/goth-nightly.yml | 10 ++++------ .github/workflows/goth.yml | 10 ++++------ .github/workflows/tests.yml | 6 ++---- pyproject.toml | 4 +++- 5 files changed, 21 insertions(+), 33 deletions(-) diff --git a/.github/workflows/build_publish.yml b/.github/workflows/build_publish.yml index 34c217f9f..248d573d2 100644 --- a/.github/workflows/build_publish.yml +++ b/.github/workflows/build_publish.yml @@ -13,10 +13,8 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: - python-version: 3.8 - - uses: Gr1N/setup-poetry@v4 - with: - poetry-version: 1.1.4 + python-version: '3.9' + - uses: Gr1N/setup-poetry@v8 - run: poetry install - run: poetry run poe test - run: poetry run poe typecheck @@ -32,10 +30,8 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: - python-version: 3.8 - - uses: Gr1N/setup-poetry@v4 - with: - poetry-version: 1.1.4 + python-version: '3.9' + - uses: Gr1N/setup-poetry@v8 - name: Get git release tag run: echo "::set-output name=git-release-tag::yapapi $(git describe --tags)" id: git_describe @@ -65,10 +61,8 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: - python-version: 3.8 - - uses: Gr1N/setup-poetry@v4 - with: - poetry-version: 1.1.4 + python-version: '3.9' + - uses: Gr1N/setup-poetry@v8 - name: Retrieve the built package uses: actions/download-artifact@v2 with: @@ -89,10 +83,8 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: - python-version: 3.8 - - uses: Gr1N/setup-poetry@v4 - with: - poetry-version: 1.1.4 + python-version: '3.9' + - uses: Gr1N/setup-poetry@v8 - name: Retrieve the built package uses: actions/download-artifact@v2 with: diff --git a/.github/workflows/goth-nightly.yml b/.github/workflows/goth-nightly.yml index c9c31d175..c1d9ee7d6 100644 --- a/.github/workflows/goth-nightly.yml +++ b/.github/workflows/goth-nightly.yml @@ -46,16 +46,14 @@ jobs: - name: Configure python uses: actions/setup-python@v4 with: - python-version: '3.8.0' + python-version: '3.9' - name: Configure poetry - uses: Gr1N/setup-poetry@v4 - with: - poetry-version: 1.1.6 + uses: Gr1N/setup-poetry@v8 - name: Install dependencies run: | - poetry env use python3.8 + poetry env use python3.9 poetry install -E integration-tests - name: Install websocat @@ -107,7 +105,7 @@ jobs: # Python version below should agree with the version set up by this job. # In future we'll be able to use the `--all` flag here to remove envs for # all Python versions (https://github.com/python-poetry/poetry/issues/3208). - run: poetry env remove python3.8 + run: poetry env remove python3.9 - name: Send Discord notification on failure uses: Ilshidur/action-discord@0.3.2 diff --git a/.github/workflows/goth.yml b/.github/workflows/goth.yml index ca50a7936..242064e1e 100644 --- a/.github/workflows/goth.yml +++ b/.github/workflows/goth.yml @@ -22,16 +22,14 @@ jobs: - name: Configure python uses: actions/setup-python@v4 with: - python-version: '3.8.0' + python-version: '3.9' - name: Configure poetry - uses: Gr1N/setup-poetry@v4 - with: - poetry-version: 1.1.6 + uses: Gr1N/setup-poetry@v8 - name: Install dependencies run: | - poetry env use python3.8 + poetry env use python3.9 poetry install -E integration-tests - name: Disconnect Docker containers from default network @@ -78,4 +76,4 @@ jobs: # Python version below should agree with the version set up by this job. # In future we'll be able to use the `--all` flag here to remove envs for # all Python versions (https://github.com/python-poetry/poetry/issues/3208). - run: poetry env remove python3.8 + run: poetry env remove python3.9 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index aef4df8f2..acae1791e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -32,16 +32,14 @@ jobs: - uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - - uses: Gr1N/setup-poetry@v7 - with: - poetry-version: 1.1.13 + - uses: Gr1N/setup-poetry@v8 - run: echo "::set-output name=ENABLE::1" if: ${{ matrix.os == 'ubuntu-latest' }} name: Enable extended checks id: extended-checks - run: echo "::set-output name=ENABLE::1" - if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.8' }} + if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.9' }} name: Enable sphinx check id: extended-checks-sphinx diff --git a/pyproject.toml b/pyproject.toml index a93290d2c..c917de183 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ documentation = "https://yapapi.readthedocs.io/en/stable/api.html" readme = "README.md" [tool.poetry.dependencies] -python = "^3.6.2" +python = "^3.7" aiohttp = "^3.6" aiohttp-sse-client = "^0.1.7" dataclasses = { version = "^0.8", python = ">=3.6, <3.7"} @@ -56,6 +56,8 @@ pexpect = {version = "^4.8.0", optional = true} sphinx = { version = "^4.0.1", optional = true } sphinx-autodoc-typehints = { version = "^1.12.0", optional = true } sphinx-rtd-theme = { version = "^1.0.0", optional = true} +setuptools = "^67.8.0" +pip = "^23.1.2" [tool.poetry.extras] integration-tests = ['goth', 'pytest', 'pytest-asyncio', 'pexpect'] From fa842564ebe44d8dc64deefa9646a99b8fb7ad35 Mon Sep 17 00:00:00 2001 From: shadeofblue Date: Wed, 7 Jun 2023 10:26:24 +0200 Subject: [PATCH 3/9] fix goth runs after a switch of default to `goerli` --- tests/goth_tests/test_agreement_termination/requestor.py | 1 + tests/goth_tests/test_async_task_generation/requestor.py | 1 + tests/goth_tests/test_concurrent_executors/requestor.py | 2 +- tests/goth_tests/test_instance_restart/requestor.py | 2 +- .../goth_tests/test_mid_agreement_payments/requestor_agent.py | 1 + tests/goth_tests/test_multiactivity_agreement/requestor.py | 1 + tests/goth_tests/test_power_outage.py | 2 +- tests/goth_tests/test_recycle_ip/ssh_recycle_ip.py | 1 + tests/goth_tests/test_resubscription.py | 1 + tests/goth_tests/test_run_blender.py | 2 +- tests/goth_tests/test_run_custom_usage_counter.py | 3 ++- tests/goth_tests/test_run_scan.py | 2 +- tests/goth_tests/test_run_simple_service.py | 3 ++- tests/goth_tests/test_run_ssh.py | 2 +- tests/goth_tests/test_run_webapp.py | 2 +- tests/goth_tests/test_run_yacat.py | 2 +- 16 files changed, 18 insertions(+), 10 deletions(-) diff --git a/tests/goth_tests/test_agreement_termination/requestor.py b/tests/goth_tests/test_agreement_termination/requestor.py index 24f7e184b..67216ef01 100755 --- a/tests/goth_tests/test_agreement_termination/requestor.py +++ b/tests/goth_tests/test_agreement_termination/requestor.py @@ -53,6 +53,7 @@ async def worker(ctx: WorkContext, tasks): async with Golem( budget=10.0, subnet_tag="goth", + payment_network="rinkeby", ) as golem: tasks = [Task(data=n) for n in range(6)] diff --git a/tests/goth_tests/test_async_task_generation/requestor.py b/tests/goth_tests/test_async_task_generation/requestor.py index ac3f3e877..455123ef5 100755 --- a/tests/goth_tests/test_async_task_generation/requestor.py +++ b/tests/goth_tests/test_async_task_generation/requestor.py @@ -30,6 +30,7 @@ async def worker(work_ctx, tasks): budget=10.0, subnet_tag="goth", event_consumer=log_event_repr, + payment_network="rinkeby", ) as golem: # We use an async task generator that yields tasks removed from diff --git a/tests/goth_tests/test_concurrent_executors/requestor.py b/tests/goth_tests/test_concurrent_executors/requestor.py index e7c275145..219a81681 100755 --- a/tests/goth_tests/test_concurrent_executors/requestor.py +++ b/tests/goth_tests/test_concurrent_executors/requestor.py @@ -52,7 +52,7 @@ async def duplicator(work_ctx, tasks): output = result.stdout.strip() task.accept_result(output) - async with Golem(budget=1.0, subnet_tag="goth") as golem: + async with Golem(budget=1.0, subnet_tag="goth", payment_network="rinkeby") as golem: # Construct a pipeline: # diff --git a/tests/goth_tests/test_instance_restart/requestor.py b/tests/goth_tests/test_instance_restart/requestor.py index 3af138d52..cafa69400 100755 --- a/tests/goth_tests/test_instance_restart/requestor.py +++ b/tests/goth_tests/test_instance_restart/requestor.py @@ -90,7 +90,7 @@ async def shutdown(self): async def main(): - async with Golem(budget=1.0, subnet_tag="goth") as golem: + async with Golem(budget=1.0, subnet_tag="goth", payment_network="rinkeby") as golem: # Start a cluster with a single service. # The first instance will fail before reaching the `running` state diff --git a/tests/goth_tests/test_mid_agreement_payments/requestor_agent.py b/tests/goth_tests/test_mid_agreement_payments/requestor_agent.py index 86abe3e1c..52e35064c 100755 --- a/tests/goth_tests/test_mid_agreement_payments/requestor_agent.py +++ b/tests/goth_tests/test_mid_agreement_payments/requestor_agent.py @@ -41,6 +41,7 @@ async def main(): strategy=ShortDebitNoteIntervalAndPaymentTimeout(), subnet_tag="goth", event_consumer=log_event_repr, + payment_network="rinkeby", ) as golem: logger = logging.getLogger("yapapi") logger.handlers[0].setLevel(logging.DEBUG) diff --git a/tests/goth_tests/test_multiactivity_agreement/requestor.py b/tests/goth_tests/test_multiactivity_agreement/requestor.py index fa0ded930..10dba35c5 100755 --- a/tests/goth_tests/test_multiactivity_agreement/requestor.py +++ b/tests/goth_tests/test_multiactivity_agreement/requestor.py @@ -30,6 +30,7 @@ async def worker(work_ctx, tasks): budget=10.0, subnet_tag="goth", event_consumer=log_event_repr, + payment_network="rinkeby", ) as golem: tasks = [Task(data=n) for n in range(3)] async for task in golem.execute_tasks( diff --git a/tests/goth_tests/test_power_outage.py b/tests/goth_tests/test_power_outage.py index 4f069ac26..e27317187 100644 --- a/tests/goth_tests/test_power_outage.py +++ b/tests/goth_tests/test_power_outage.py @@ -63,7 +63,7 @@ async def test_power_outage( provider_1 = runner.get_probes(probe_type=ProviderProbe)[0] async with requestor.run_command_on_host( - f"{blender_path} --subnet-tag goth --min-cpu-threads 1", + f"{blender_path} --subnet-tag goth --min-cpu-threads 1 --payment-network rinkeby", env=os.environ, ) as (_cmd_task, cmd_monitor, _process_monitor): diff --git a/tests/goth_tests/test_recycle_ip/ssh_recycle_ip.py b/tests/goth_tests/test_recycle_ip/ssh_recycle_ip.py index 3e43a5517..1b6788080 100755 --- a/tests/goth_tests/test_recycle_ip/ssh_recycle_ip.py +++ b/tests/goth_tests/test_recycle_ip/ssh_recycle_ip.py @@ -59,6 +59,7 @@ async def main(): async with Golem( budget=1.0, subnet_tag="goth", + payment_network="rinkeby", ) as golem: network = await golem.create_network("192.168.0.1/24") proxy = SocketProxy(ports=[2222]) diff --git a/tests/goth_tests/test_resubscription.py b/tests/goth_tests/test_resubscription.py index 6cd4532b9..ae579b46b 100644 --- a/tests/goth_tests/test_resubscription.py +++ b/tests/goth_tests/test_resubscription.py @@ -169,6 +169,7 @@ async def worker(work_ctx, tasks): async with Golem( budget=10.0, event_consumer=monitor.add_event_sync, + payment_network="rinkeby", ) as golem: task: Task # mypy needs this for some reason diff --git a/tests/goth_tests/test_run_blender.py b/tests/goth_tests/test_run_blender.py index 6089356ab..520683e32 100644 --- a/tests/goth_tests/test_run_blender.py +++ b/tests/goth_tests/test_run_blender.py @@ -59,7 +59,7 @@ async def test_run_blender( requestor = runner.get_probes(probe_type=RequestorProbe)[0] async with requestor.run_command_on_host( - f"{blender_path} --subnet-tag goth --min-cpu-threads 1", + f"{blender_path} --subnet-tag goth --min-cpu-threads 1 --payment-network rinkeby", env=os.environ, ) as (_cmd_task, cmd_monitor, _process_monitor): diff --git a/tests/goth_tests/test_run_custom_usage_counter.py b/tests/goth_tests/test_run_custom_usage_counter.py index 55e09747f..d9a6300fc 100644 --- a/tests/goth_tests/test_run_custom_usage_counter.py +++ b/tests/goth_tests/test_run_custom_usage_counter.py @@ -86,7 +86,8 @@ async def test_run_custom_usage_counter( requestor = runner.get_probes(probe_type=RequestorProbe)[0] async with requestor.run_command_on_host( - f"{requestor_path} --running-time {RUNNING_TIME} --subnet-tag {SUBNET_TAG}", + f"{requestor_path} --running-time {RUNNING_TIME} " + f"--subnet-tag {SUBNET_TAG} --payment-network rinkeby", env=os.environ, ) as (_cmd_task, cmd_monitor, _process_monitor): diff --git a/tests/goth_tests/test_run_scan.py b/tests/goth_tests/test_run_scan.py index 24c6bb052..1c4777cc7 100644 --- a/tests/goth_tests/test_run_scan.py +++ b/tests/goth_tests/test_run_scan.py @@ -45,7 +45,7 @@ async def test_run_scan( requestor = runner.get_probes(probe_type=RequestorProbe)[0] async with requestor.run_command_on_host( - f"{requestor_path} --subnet-tag {SUBNET_TAG} --scan-size 3", + f"{requestor_path} --subnet-tag {SUBNET_TAG} --scan-size 3 --payment-network rinkeby", env=os.environ, ) as (_cmd_task, cmd_monitor, process_monitor): cmd_monitor.add_assertion(assert_no_errors) diff --git a/tests/goth_tests/test_run_simple_service.py b/tests/goth_tests/test_run_simple_service.py index ca9b6113f..85293291d 100644 --- a/tests/goth_tests/test_run_simple_service.py +++ b/tests/goth_tests/test_run_simple_service.py @@ -44,7 +44,8 @@ async def test_run_simple_service( requestor = runner.get_probes(probe_type=RequestorProbe)[0] async with requestor.run_command_on_host( - f"{requestor_path} --running-time {RUNNING_TIME} --subnet-tag {SUBNET_TAG}", + f"{requestor_path} --running-time {RUNNING_TIME} " + f"--subnet-tag {SUBNET_TAG} --payment-network rinkeby", env=os.environ, ) as (_cmd_task, cmd_monitor, _process_monitor): diff --git a/tests/goth_tests/test_run_ssh.py b/tests/goth_tests/test_run_ssh.py index 36775fca7..162561768 100644 --- a/tests/goth_tests/test_run_ssh.py +++ b/tests/goth_tests/test_run_ssh.py @@ -63,7 +63,7 @@ async def test_run_ssh( requestor = runner.get_probes(probe_type=RequestorProbe)[0] async with requestor.run_command_on_host( - f"{requestor_path} --subnet-tag {SUBNET_TAG}", + f"{requestor_path} --subnet-tag {SUBNET_TAG} --payment-network rinkeby", env=os.environ, ) as (_cmd_task, cmd_monitor, process_monitor): start_time = time.time() diff --git a/tests/goth_tests/test_run_webapp.py b/tests/goth_tests/test_run_webapp.py index 7f422d47d..376116827 100644 --- a/tests/goth_tests/test_run_webapp.py +++ b/tests/goth_tests/test_run_webapp.py @@ -58,7 +58,7 @@ async def test_run_webapp( requestor = runner.get_probes(probe_type=RequestorProbe)[0] async with requestor.run_command_on_host( - f"{requestor_path} --subnet-tag {SUBNET_TAG} --port {port}", + f"{requestor_path} --subnet-tag {SUBNET_TAG} --port {port} --payment-network rinkeby", env=os.environ, ) as (_cmd_task, cmd_monitor, process_monitor): start_time = time.time() diff --git a/tests/goth_tests/test_run_yacat.py b/tests/goth_tests/test_run_yacat.py index 0905a55a5..fdc047526 100644 --- a/tests/goth_tests/test_run_yacat.py +++ b/tests/goth_tests/test_run_yacat.py @@ -71,7 +71,7 @@ async def test_run_yacat( async with requestor.run_command_on_host( f"{yacat_path} --mask ?a?a --hash $P$5ZDzPE45CigTC6EY4cXbyJSLj/pGee0 " f"--subnet-tag goth --chunk-size {CHUNK_SIZE} --max-workers {PROVIDER_COUNT} " - f"--log-file {(log_dir / logfile).resolve()}", + f"--log-file {(log_dir / logfile).resolve()} --payment-network rinkeby", env=os.environ, ) as (_cmd_task, cmd_monitor, _process_monitor): From 876d6154a281e210c00d87d0034c9c64ea6c18d9 Mon Sep 17 00:00:00 2001 From: shadeofblue Date: Wed, 7 Jun 2023 11:40:36 +0200 Subject: [PATCH 4/9] re-enable VPN tests --- tests/goth_tests/test_recycle_ip/test_recycle_ip.py | 1 - tests/goth_tests/test_run_ssh.py | 1 - tests/goth_tests/test_run_webapp.py | 1 - 3 files changed, 3 deletions(-) diff --git a/tests/goth_tests/test_recycle_ip/test_recycle_ip.py b/tests/goth_tests/test_recycle_ip/test_recycle_ip.py index ddb8b7415..115d7fe88 100644 --- a/tests/goth_tests/test_recycle_ip/test_recycle_ip.py +++ b/tests/goth_tests/test_recycle_ip/test_recycle_ip.py @@ -23,7 +23,6 @@ SUBNET_TAG = "goth" -@pytest.mark.skip # TODO: https://github.com/golemfactory/yagna/issues/2387 @pytest.mark.asyncio async def test_recycle_ip( log_dir: Path, diff --git a/tests/goth_tests/test_run_ssh.py b/tests/goth_tests/test_run_ssh.py index 162561768..d7f5e8dc5 100644 --- a/tests/goth_tests/test_run_ssh.py +++ b/tests/goth_tests/test_run_ssh.py @@ -22,7 +22,6 @@ SUBNET_TAG = "goth" -@pytest.mark.skip # TODO: https://github.com/golemfactory/yagna/issues/2387 @pytest.mark.asyncio async def test_run_ssh( log_dir: Path, diff --git a/tests/goth_tests/test_run_webapp.py b/tests/goth_tests/test_run_webapp.py index 376116827..bb8c75708 100644 --- a/tests/goth_tests/test_run_webapp.py +++ b/tests/goth_tests/test_run_webapp.py @@ -28,7 +28,6 @@ ONELINER_URL = f"http://localhost:{port}/" -@pytest.mark.skip # TODO: https://github.com/golemfactory/yagna/issues/2387 @pytest.mark.asyncio async def test_run_webapp( log_dir: Path, From 37a99671395a0536a68569403b569d0024a5fad2 Mon Sep 17 00:00:00 2001 From: shadeofblue Date: Wed, 7 Jun 2023 12:54:08 +0200 Subject: [PATCH 5/9] bump the version to 0.10.1-alpha.0 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c917de183..f2f929d16 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "yapapi" -version = "0.10.0" +version = "0.10.1a0" description = "High-level Python API for the New Golem" authors = ["Przemysław K. Rekucki ", "GolemFactory "] license = "LGPL-3.0-or-later" From a63cce3a30c9076d38e3f115020f46889208bb20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Rekucki?= <56750+prekucki@users.noreply.github.com> Date: Wed, 7 Jun 2023 17:22:40 +0200 Subject: [PATCH 6/9] fixed allocation creation (#1134) * fixed allocation creation * identity * unit test fixes --------- Co-authored-by: shadeofblue Co-authored-by: shadeofblue --- tests/test_payment_platforms.py | 164 +++++++++----------------------- yapapi/engine.py | 61 ++++++------ 2 files changed, 73 insertions(+), 152 deletions(-) diff --git a/tests/test_payment_platforms.py b/tests/test_payment_platforms.py index a9454c7e9..7d0f1df3c 100644 --- a/tests/test_payment_platforms.py +++ b/tests/test_payment_platforms.py @@ -4,10 +4,13 @@ from ya_payment import RequestorApi -from yapapi import NoPaymentAccountError -from yapapi.engine import DEFAULT_DRIVER, DEFAULT_NETWORK -from yapapi.golem import Golem -from yapapi.rest.payment import Account, Payment +from yapapi.engine import ( + DEFAULT_DRIVER, + DEFAULT_NETWORK, + MAINNET_TOKEN_NAME, + TESTNET_TOKEN_NAME, +) +from yapapi.golem import Golem, _Engine @pytest.fixture(autouse=True) @@ -15,156 +18,75 @@ def _set_app_key(monkeypatch): monkeypatch.setenv("YAGNA_APPKEY", "mock-appkey") -def _mock_accounts_iterator(*account_specs): - """Create an iterator over mock `Account` objects. - - `account_specs` should contain pairs `(driver, network)`, where `driver` and `network` - are strings, or triples `(driver, network, params)` with `driver` and `network` as before - and `params` a dictionary containing additional keyword arguments for `Account()`. - """ - - async def _mock(*_args): - for spec in account_specs: - params = { - "platform": "mock-platform", - "address": "mock-address", - "driver": spec[0], - "network": spec[1], - "token": "mock-token", - "send": True, - "receive": True, - } - if len(spec) == 3: - params.update(**spec[2]) - yield Account(**params) - - return _mock - - class _StopExecutor(Exception): """An exception raised to stop the test when reaching an expected checkpoint in executor.""" @pytest.fixture() -def _mock_decorate_demand(monkeypatch): - """Make `Payment.decorate_demand()` stop the test.""" +def _mock_engine_id(monkeypatch): + """Mock Engine `id`.""" + + async def _id(_): + return + monkeypatch.setattr( - Payment, - "decorate_demand", - mock.Mock(side_effect=_StopExecutor("decorate_demand() called")), + _Engine, + "_id", + _id, ) @pytest.fixture() def _mock_create_allocation(monkeypatch): """Make `RequestorApi.create_allocation()` stop the test.""" - monkeypatch.setattr( - RequestorApi, - "create_allocation", - mock.Mock(side_effect=_StopExecutor("create_allocation() called")), - ) + create_allocation_mock = mock.Mock(side_effect=_StopExecutor("create_allocation() called")) -@pytest.mark.asyncio -async def test_no_accounts_raises(monkeypatch): - """Test that exception is raised if `Payment.accounts()` returns empty list.""" + monkeypatch.setattr(RequestorApi, "create_allocation", create_allocation_mock) - monkeypatch.setattr(Payment, "accounts", _mock_accounts_iterator()) - - with pytest.raises(NoPaymentAccountError): - async with Golem(budget=10.0): - pass + return create_allocation_mock @pytest.mark.asyncio -async def test_no_matching_account_raises(monkeypatch): - """Test that exception is raised if `Payment.accounts()` returns no matching accounts.""" +async def test_default(_mock_engine_id, _mock_create_allocation): + """Test the allocation defaults.""" - monkeypatch.setattr( - Payment, - "accounts", - _mock_accounts_iterator( - ("other-driver", "other-network"), - ("matching-driver", "other-network"), - ("other-driver", "matching-network"), - ), - ) - - with pytest.raises(NoPaymentAccountError) as exc_info: - async with Golem( - budget=10.0, payment_driver="matching-driver", payment_network="matching-network" - ): + with pytest.raises(_StopExecutor): + async with Golem(budget=10.0): pass - exc = exc_info.value - assert exc.required_driver == "matching-driver" - assert exc.required_network == "matching-network" - - -@pytest.mark.asyncio -async def test_matching_account_creates_allocation(monkeypatch, _mock_decorate_demand): - """Test that matching accounts are correctly selected and allocations are created for them.""" - - monkeypatch.setattr( - Payment, - "accounts", - _mock_accounts_iterator( - ("other-driver", "other-network"), - ("matching-driver", "matching-network", {"platform": "platform-1"}), - ("matching-driver", "other-network"), - ("other-driver", "matching-network"), - ("matching-driver", "matching-network", {"platform": "platform-2"}), - ), + assert _mock_create_allocation.called + assert ( + _mock_create_allocation.mock_calls[0][1][0].payment_platform + == f"{DEFAULT_DRIVER}-{DEFAULT_NETWORK}-{TESTNET_TOKEN_NAME}" ) - create_allocation_args = [] - async def mock_create_allocation(_self, model): - create_allocation_args.append(model) - return mock.Mock() - - async def mock_release_allocation(*args, **kwargs): - pass - - monkeypatch.setattr(RequestorApi, "create_allocation", mock_create_allocation) - monkeypatch.setattr(RequestorApi, "release_allocation", mock_release_allocation) +@pytest.mark.asyncio +async def test_mainnet(_mock_engine_id, _mock_create_allocation): + """Test the allocation for a mainnet account.""" with pytest.raises(_StopExecutor): - async with Golem( - budget=10.0, - payment_driver="matching-driver", - payment_network="matching-network", - ): + async with Golem(budget=10.0, payment_driver="somedriver", payment_network="mainnet"): pass - assert len(create_allocation_args) == 2 - assert create_allocation_args[0].payment_platform == "platform-1" - assert create_allocation_args[1].payment_platform == "platform-2" + assert _mock_create_allocation.called + assert ( + _mock_create_allocation.mock_calls[0][1][0].payment_platform + == f"somedriver-mainnet-{MAINNET_TOKEN_NAME}" + ) @pytest.mark.asyncio -async def test_driver_network_case_insensitive(monkeypatch, _mock_create_allocation): - """Test that matching driver and network names is not case sensitive.""" - - monkeypatch.setattr(Payment, "accounts", _mock_accounts_iterator(("dRIVER", "NetWORK"))) +async def test_testnet(_mock_engine_id, _mock_create_allocation): + """Test the allocation for a mainnet account.""" with pytest.raises(_StopExecutor): - async with Golem( - budget=10.0, - payment_driver="dRiVeR", - payment_network="NeTwOrK", - ): + async with Golem(budget=10.0, payment_driver="somedriver", payment_network="othernet"): pass - -@pytest.mark.asyncio -async def test_default_driver_network(monkeypatch, _mock_create_allocation): - """Test that defaults are used if driver and network are not specified.""" - - monkeypatch.setattr( - Payment, "accounts", _mock_accounts_iterator((DEFAULT_DRIVER, DEFAULT_NETWORK)) + assert _mock_create_allocation.called + assert ( + _mock_create_allocation.mock_calls[0][1][0].payment_platform + == f"somedriver-othernet-{TESTNET_TOKEN_NAME}" ) - - with pytest.raises(_StopExecutor): - async with Golem(budget=10.0): - pass diff --git a/yapapi/engine.py b/yapapi/engine.py index d4e42c896..99585ac42 100644 --- a/yapapi/engine.py +++ b/yapapi/engine.py @@ -8,6 +8,7 @@ from datetime import datetime, timezone from decimal import Decimal import itertools +import json import logging import os import sys @@ -57,6 +58,10 @@ MAX_CONCURRENTLY_PROCESSED_DEBIT_NOTES: Final[int] = 10 +MAINNET_NETWORKS: Set[str] = {"mainnet", "polygon"} +MAINNET_TOKEN_NAME: str = "glm" +TESTNET_TOKEN_NAME: str = "tglm" + logger = logging.getLogger("yapapi.executor") @@ -103,6 +108,7 @@ def __init__( subnet_tag: Optional[str] = None, payment_driver: Optional[str] = None, payment_network: Optional[str] = None, + payment_token: Optional[str] = None, stream_output: bool = False, app_key: Optional[str] = None, ): @@ -135,6 +141,13 @@ def __init__( self._subnet: Optional[str] = subnet_tag or DEFAULT_SUBNET self._payment_driver: str = payment_driver.lower() if payment_driver else DEFAULT_DRIVER self._payment_network: str = payment_network.lower() if payment_network else DEFAULT_NETWORK + self._payment_token: str = ( + payment_token.lower() + if payment_token + else MAINNET_TOKEN_NAME + if self._payment_network in MAINNET_NETWORKS + else TESTNET_TOKEN_NAME + ) self._stream_output = stream_output # a set of `Job` instances used to track jobs - computations or services - started @@ -332,40 +345,26 @@ async def _shutdown(self, *exc_info): except Exception: logger.debug("Got error when waiting for services to finish", exc_info=True) - async def _create_allocations(self) -> rest.payment.MarketDecoration: + async def _id(self) -> str: + async with self._root_api_session.get(f"{self._api_config.root_url}/me") as resp: + return json.loads(await resp.text()).get("identity") + async def _create_allocations(self) -> rest.payment.MarketDecoration: if not self._budget_allocations: - async for account in self._payment_api.accounts(): - driver = account.driver.lower() - network = account.network.lower() - if (driver, network) != (self._payment_driver, self._payment_network): - logger.debug( - "Not using payment platform `%s`, platform's driver/network " - "`%s`/`%s` is different than requested driver/network `%s`/`%s`", - account.platform, - driver, - network, - self._payment_driver, - self._payment_network, + platform = f"{self._payment_driver}-{self._payment_network}-{self._payment_token}" + address = await self._id() + allocation = cast( + rest.payment.Allocation, + await self._stack.enter_async_context( + self._payment_api.new_allocation( + self._budget_amount, + payment_platform=platform, + payment_address=address, ) - continue - logger.debug("Creating allocation using payment platform `%s`", account.platform) - allocation = cast( - rest.payment.Allocation, - await self._stack.enter_async_context( - self._payment_api.new_allocation( - self._budget_amount, - payment_platform=account.platform, - payment_address=account.address, - # TODO what do to with this? - # expires=self._expires + CFG_INVOICE_TIMEOUT, - ) - ), - ) - self._budget_allocations.append(allocation) - - if not self._budget_allocations: - raise NoPaymentAccountError(self._payment_driver, self._payment_network) + ), + ) + logger.debug("Creating allocation using payment platform `%s`", platform) + self._budget_allocations.append(allocation) allocation_ids = [allocation.id for allocation in self._budget_allocations] return await self._payment_api.decorate_demand(allocation_ids) From 6d15c69004c270567239838ea995e60c3875f6a4 Mon Sep 17 00:00:00 2001 From: shadeofblue Date: Wed, 7 Jun 2023 17:23:29 +0200 Subject: [PATCH 7/9] bump version to 0.10.1-alpha.1 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index f2f929d16..76e652b57 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "yapapi" -version = "0.10.1a0" +version = "0.10.1-alpha.1" description = "High-level Python API for the New Golem" authors = ["Przemysław K. Rekucki ", "GolemFactory "] license = "LGPL-3.0-or-later" From 727bd2225abc1bc1cdc00afbcc0684acb0ba7ebb Mon Sep 17 00:00:00 2001 From: shadeofblue Date: Mon, 12 Jun 2023 10:49:42 +0200 Subject: [PATCH 8/9] bump version to release --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 76e652b57..8099539e7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "yapapi" -version = "0.10.1-alpha.1" +version = "0.10.1" description = "High-level Python API for the New Golem" authors = ["Przemysław K. Rekucki ", "GolemFactory "] license = "LGPL-3.0-or-later" From 7f66a2122373e85a011f059acc9fc7fcf2caeebf Mon Sep 17 00:00:00 2001 From: shadeofblue Date: Mon, 12 Jun 2023 18:32:19 +0200 Subject: [PATCH 9/9] unfreeze the pip/setuptools version --- pyproject.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1720eacfc..4807fa8fa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,12 +41,13 @@ attrs = ">=19.3" Deprecated = "^1.2.12" python-statemachine = "^0.8.0" +setuptools = "*" +pip = "*" + # Docs sphinx = { version = "^4.0.1", optional = true } sphinx-autodoc-typehints = { version = "^1.12.0", optional = true } sphinx-rtd-theme = { version = "^1.0.0", optional = true} -setuptools = "^67.8.0" -pip = "^23.1.2" [tool.poetry.extras] docs = ['sphinx', 'sphinx-autodoc-typehints', 'sphinx-rtd-theme']