47
47
)
48
48
from aleph_client .utils import FORBIDDEN_HOSTS , sanitize_url
49
49
50
+ from .conftest import MOCK_METADATA_ID , MOCK_VOUCHER_ID
50
51
from .mocks import (
51
52
FAKE_ADDRESS_EVM ,
52
53
FAKE_CRN_BASIC_HASH ,
@@ -254,7 +255,7 @@ def create_mock_shutil():
254
255
return MagicMock (which = MagicMock (return_value = "/root/.cargo/bin/sevctl" , move = MagicMock (return_value = "/fake/path" )))
255
256
256
257
257
- def create_mock_client (mock_crn_list , payment_type = "superfluid" ):
258
+ def create_mock_client (mock_crn_list , payment_type = "superfluid" , mock_voucher_service = None ):
258
259
# Create a proper mock for the crn service
259
260
mock_crn_service = MagicMock ()
260
261
mock_crn_service .get_crns_list = AsyncMock (return_value = {"crns" : mock_crn_list })
@@ -271,11 +272,13 @@ def create_mock_client(mock_crn_list, payment_type="superfluid"):
271
272
)
272
273
),
273
274
)
274
- # Set the crn attribute to the properly mocked service
275
+ # Set the service attributes
275
276
mock_client .crn = mock_crn_service
277
+ mock_client .voucher = mock_voucher_service
276
278
277
279
mock_client_class = MagicMock ()
278
280
mock_client_class .return_value .__aenter__ = AsyncMock (return_value = mock_client )
281
+
279
282
return mock_client_class , mock_client
280
283
281
284
@@ -291,6 +294,48 @@ def response_get_program_price(ptype):
291
294
mock_crn_service = MagicMock ()
292
295
mock_crn_service .get_crns_list = AsyncMock (return_value = {"crns" : mock_crn_list or []})
293
296
297
+ # Create voucher attributes using the proper types
298
+ from aleph .sdk .types import Voucher , VoucherAttribute
299
+
300
+ # Create EVM voucher
301
+ evm_voucher = Voucher (
302
+ id = MOCK_VOUCHER_ID ,
303
+ metadata_id = MOCK_METADATA_ID ,
304
+ name = "EVM Test Voucher" ,
305
+ description = "A test voucher for EVM chains" ,
306
+ external_url = "https://example.com" ,
307
+ image = "https://example.com/image.png" ,
308
+ icon = "https://example.com/icon.png" ,
309
+ attributes = [
310
+ VoucherAttribute (trait_type = "Duration" , value = "30 days" , display_type = "string" ),
311
+ VoucherAttribute (trait_type = "Compute Units" , value = "4" , display_type = "number" ),
312
+ VoucherAttribute (trait_type = "Type" , value = "instance" , display_type = "string" ),
313
+ ],
314
+ )
315
+
316
+ # Create Solana voucher
317
+ solana_voucher = Voucher (
318
+ id = "solticket123" ,
319
+ metadata_id = MOCK_METADATA_ID ,
320
+ name = "Solana Test Voucher" ,
321
+ description = "A test voucher for Solana" ,
322
+ external_url = "https://example.com" ,
323
+ image = "https://example.com/image.png" ,
324
+ icon = "https://example.com/icon.png" ,
325
+ attributes = [
326
+ VoucherAttribute (trait_type = "Duration" , value = "60 days" , display_type = "string" ),
327
+ VoucherAttribute (trait_type = "Compute Units" , value = "8" , display_type = "number" ),
328
+ VoucherAttribute (trait_type = "Type" , value = "instance" , display_type = "string" ),
329
+ ],
330
+ )
331
+
332
+ # Create a proper mock for voucher service
333
+ mock_voucher_service = MagicMock ()
334
+ mock_voucher_service .fetch_vouchers_by_chain = AsyncMock (return_value = [evm_voucher ])
335
+ mock_voucher_service .get_vouchers = AsyncMock (return_value = [evm_voucher , solana_voucher ])
336
+ mock_voucher_service .get_evm_vouchers = AsyncMock (return_value = [evm_voucher ])
337
+ mock_voucher_service .get_solana_vouchers = AsyncMock (return_value = [solana_voucher ])
338
+
294
339
mock_response_get_message = create_mock_instance_message (mock_account , payg = True )
295
340
mock_response_create_instance = MagicMock (item_hash = FAKE_VM_HASH )
296
341
@@ -312,6 +357,7 @@ def response_get_program_price(ptype):
312
357
# Set the service attributes
313
358
mock_auth_client .crn = mock_crn_service
314
359
mock_auth_client .port_forwarder = mock_port_forwarder
360
+ mock_auth_client .voucher = mock_voucher_service
315
361
316
362
if payment_types :
317
363
mock_auth_client .get_program_price = AsyncMock (
@@ -374,6 +420,9 @@ def create_mock_vm_coco_client():
374
420
"coco_hold_evm" ,
375
421
"coco_superfluid_evm" ,
376
422
"gpu_superfluid_evm" ,
423
+ "nft_payment_avax" ,
424
+ "nft_payment_base" ,
425
+ "nft_payment_sol" ,
377
426
],
378
427
argnames = "args, expected" ,
379
428
argvalues = [
@@ -445,6 +494,32 @@ def create_mock_vm_coco_client():
445
494
},
446
495
(FAKE_VM_HASH , FAKE_CRN_GPU_URL , "BASE" ),
447
496
),
497
+ ( # nft_payment_avax
498
+ {
499
+ "payment_type" : "nft" ,
500
+ "payment_chain" : "AVAX" ,
501
+ "rootfs" : "debian12" ,
502
+ },
503
+ (FAKE_VM_HASH , None , "AVAX" ),
504
+ ),
505
+ ( # nft_payment_base
506
+ {
507
+ "payment_type" : "nft" ,
508
+ "payment_chain" : "BASE" ,
509
+ "rootfs" : "debian12" ,
510
+ "crn_url" : FAKE_CRN_BASIC_URL ,
511
+ },
512
+ (FAKE_VM_HASH , None , "BASE" ),
513
+ ),
514
+ ( # nft_payment_sol
515
+ {
516
+ "payment_type" : "nft" ,
517
+ "payment_chain" : "SOL" ,
518
+ "rootfs" : "debian12" ,
519
+ "crn_url" : FAKE_CRN_BASIC_URL ,
520
+ },
521
+ (FAKE_VM_HASH , None , "SOL" ),
522
+ ),
448
523
],
449
524
)
450
525
@pytest .mark .asyncio
0 commit comments