Skip to content

Fix: Hold Restrictions #356

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions src/aleph_client/commands/instance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,16 @@
selector=True,
),
)
if (tier.compute_units > 4 or confidential) and payment_type == PaymentType.hold:
console.print("VM with more than 4 Compute unit and/or confidential can't run using HOLD.", style="red")
if payment_chain in super_token_chains:
payment_type = PaymentType.superfluid
console.print("Switching payment type to PAY-As-You-Go (superfluid).", style="green")

Check warning on line 342 in src/aleph_client/commands/instance/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/aleph_client/commands/instance/__init__.py#L341-L342

Added lines #L341 - L342 were not covered by tests
else:
console.print("The current chain is not compatible with PAYG. Aborting instance creation.", style="red")
console.print(f"Compatible Chain : {super_token_chains}")
raise typer.Exit(code=1)

name = name or validated_prompt("Instance name", lambda x: x and len(x) < 65)
vcpus = tier.vcpus
memory = tier.memory
Expand Down
10 changes: 7 additions & 3 deletions src/aleph_client/commands/pricing.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,13 @@ def display_table_for(
if "vram" in tier:
row.append(f"{tier['vram'] / 1024:.0f}")
if "holding" in price_unit:
row.append(
f"{displayable_amount(Decimal(price_unit['holding']) * current_units, decimals=3)} tokens"
)
# If the pricing entity is confidential, display "Not Available"
if pricing_entity == PricingEntity.INSTANCE_CONFIDENTIAL:
row.append("Not Available")
else:
row.append(
f"{displayable_amount(Decimal(price_unit['holding']) * current_units, decimals=3)} tokens"
)
if "payg" in price_unit and pricing_entity in PAYG_GROUP:
payg_hourly = Decimal(price_unit["payg"]) * current_units
row.append(
Expand Down
1 change: 1 addition & 0 deletions src/aleph_client/commands/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ async def upload(
verbose=verbose,
),
)

name = name or validated_prompt("Program name", lambda x: x and len(x) < 65)
vcpus = tier.vcpus
memory = tier.memory
Expand Down
68 changes: 42 additions & 26 deletions tests/unit/test_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from unittest.mock import AsyncMock, MagicMock, patch

import pytest
import typer
from aiohttp import InvalidURL
from aleph_message.models import Chain, ItemHash
from aleph_message.models.execution.base import Payment, PaymentType
Expand Down Expand Up @@ -380,7 +381,7 @@ def create_mock_vm_coco_client():
"coco_superfluid_evm",
"gpu_superfluid_evm",
],
argnames="args, expected",
argnames="args, expected, should_raise",
argvalues=[
( # regular_hold_evm
{
Expand All @@ -392,6 +393,7 @@ def create_mock_vm_coco_client():
"immutable_volume": [f"mount=/opt/packages,ref={FAKE_STORE_HASH}"],
},
(FAKE_VM_HASH, None, "ETH"),
False,
),
( # regular_superfluid_evm
{
Expand All @@ -401,6 +403,7 @@ def create_mock_vm_coco_client():
"crn_url": FAKE_CRN_URL,
},
(FAKE_VM_HASH, FAKE_CRN_URL, "AVAX"),
False,
),
( # regular_hold_sol
{
Expand All @@ -409,6 +412,7 @@ def create_mock_vm_coco_client():
"rootfs": "debian12",
},
(FAKE_VM_HASH, None, "SOL"),
False,
),
( # coco_hold_sol
{
Expand All @@ -418,7 +422,8 @@ def create_mock_vm_coco_client():
"crn_url": FAKE_CRN_URL,
"confidential": True,
},
(FAKE_VM_HASH, FAKE_CRN_URL, "SOL"),
None,
True,
),
( # coco_hold_evm
{
Expand All @@ -428,7 +433,8 @@ def create_mock_vm_coco_client():
"crn_url": FAKE_CRN_URL,
"confidential": True,
},
(FAKE_VM_HASH, FAKE_CRN_URL, "ETH"),
None,
True,
),
( # coco_superfluid_evm
{
Expand All @@ -439,6 +445,7 @@ def create_mock_vm_coco_client():
"confidential": True,
},
(FAKE_VM_HASH, FAKE_CRN_URL, "BASE"),
False,
),
( # gpu_superfluid_evm
{
Expand All @@ -449,11 +456,12 @@ def create_mock_vm_coco_client():
"gpu": True,
},
(FAKE_VM_HASH, FAKE_CRN_URL, "BASE"),
False,
),
],
)
@pytest.mark.asyncio
async def test_create_instance(args, expected):
async def test_create_instance(args, expected, should_raise):
mock_validate_ssh_pubkey_file = create_mock_validate_ssh_pubkey_file()
mock_load_account = create_mock_load_account()
mock_account = mock_load_account.return_value
Expand Down Expand Up @@ -496,28 +504,36 @@ async def create_instance(instance_spec):
all_args.update(instance_spec)
return await create(**all_args)

returned = await create_instance(args)
# Basic assertions for all cases
mock_load_account.assert_called_once()
mock_validate_ssh_pubkey_file.return_value.read_text.assert_called_once()
mock_client.get_estimated_price.assert_called_once()
mock_auth_client.create_instance.assert_called_once()
# Payment type specific assertions
if args["payment_type"] == "hold":
mock_get_balance.assert_called_once()
elif args["payment_type"] == "superfluid":
assert mock_account.manage_flow.call_count == 2
assert mock_wait_for_confirmed_flow.call_count == 2
# CRN related assertions
if args["payment_type"] == "superfluid" or args.get("confidential") or args.get("gpu"):
mock_fetch_latest_crn_version.assert_called()
if not args.get("gpu"):
mock_fetch_crn_info.assert_called_once()
else:
mock_crn_table.return_value.run_async.assert_called_once()
mock_wait_for_processed_instance.assert_called_once()
mock_vm_client.start_instance.assert_called_once()
assert returned == expected
if should_raise:
with pytest.raises(typer.Exit) as exc_info:
returned = await create_instance(args)
mock_load_account.assert_called_once()
mock_validate_ssh_pubkey_file.return_value.read_text.assert_called_once()

assert exc_info.value.exit_code == 1
else:
returned = await create_instance(args)
# Basic assertions for all cases
mock_load_account.assert_called_once()
mock_validate_ssh_pubkey_file.return_value.read_text.assert_called_once()
mock_client.get_estimated_price.assert_called_once()
mock_auth_client.create_instance.assert_called_once()
# Payment type specific assertions
if args["payment_type"] == "hold":
mock_get_balance.assert_called_once()
elif args["payment_type"] == "superfluid":
assert mock_account.manage_flow.call_count == 2
assert mock_wait_for_confirmed_flow.call_count == 2
# CRN related assertions
if args["payment_type"] == "superfluid" or args.get("confidential") or args.get("gpu"):
mock_fetch_latest_crn_version.assert_called()
if not args.get("gpu"):
mock_fetch_crn_info.assert_called_once()
else:
mock_crn_table.return_value.run_async.assert_called_once()
mock_wait_for_processed_instance.assert_called_once()
mock_vm_client.start_instance.assert_called_once()
assert returned == expected


@pytest.mark.asyncio
Expand Down
Loading