1
1
import pytest
2
- from bittensor_wallet import Wallet
3
2
4
3
from bittensor .core import async_subtensor
5
4
from bittensor .core .extrinsics .asyncex import registration as async_registration
6
5
7
6
8
7
@pytest .mark .asyncio
9
- async def test_do_pow_register_success (subtensor , mocker ):
8
+ async def test_do_pow_register_success (subtensor , fake_wallet , mocker ):
10
9
"""Tests successful PoW registration."""
11
10
# Preps
12
- fake_wallet = mocker .Mock (autospec = Wallet )
13
11
fake_wallet .hotkey .ss58_address = "hotkey_ss58"
14
12
fake_wallet .coldkeypub .ss58_address = "coldkey_ss58"
15
13
fake_pow_result = mocker .Mock (
@@ -66,10 +64,9 @@ async def test_do_pow_register_success(subtensor, mocker):
66
64
67
65
68
66
@pytest .mark .asyncio
69
- async def test_do_pow_register_failure (subtensor , mocker ):
67
+ async def test_do_pow_register_failure (subtensor , fake_wallet , mocker ):
70
68
"""Tests failed PoW registration."""
71
69
# Preps
72
- fake_wallet = mocker .Mock (autospec = Wallet )
73
70
fake_wallet .hotkey .ss58_address = "hotkey_ss58"
74
71
fake_wallet .coldkeypub .ss58_address = "coldkey_ss58"
75
72
fake_pow_result = mocker .Mock (
@@ -121,10 +118,9 @@ async def test_do_pow_register_failure(subtensor, mocker):
121
118
122
119
123
120
@pytest .mark .asyncio
124
- async def test_do_pow_register_no_waiting (subtensor , mocker ):
121
+ async def test_do_pow_register_no_waiting (subtensor , fake_wallet , mocker ):
125
122
"""Tests PoW registration without waiting for inclusion or finalization."""
126
123
# Preps
127
- fake_wallet = mocker .Mock (autospec = Wallet )
128
124
fake_wallet .hotkey .ss58_address = "hotkey_ss58"
129
125
fake_wallet .coldkeypub .ss58_address = "coldkey_ss58"
130
126
fake_pow_result = mocker .Mock (
@@ -166,10 +162,9 @@ async def test_do_pow_register_no_waiting(subtensor, mocker):
166
162
167
163
168
164
@pytest .mark .asyncio
169
- async def test_register_extrinsic_success (subtensor , mocker ):
165
+ async def test_register_extrinsic_success (subtensor , fake_wallet , mocker ):
170
166
"""Tests successful registration."""
171
167
# Preps
172
- fake_wallet = mocker .Mock (autospec = Wallet )
173
168
fake_wallet .hotkey .ss58_address = "hotkey_ss58"
174
169
fake_wallet .coldkey .ss58_address = "coldkey_ss58"
175
170
@@ -221,10 +216,9 @@ async def test_register_extrinsic_success(subtensor, mocker):
221
216
222
217
223
218
@pytest .mark .asyncio
224
- async def test_register_extrinsic_success_with_cuda (subtensor , mocker ):
219
+ async def test_register_extrinsic_success_with_cuda (subtensor , fake_wallet , mocker ):
225
220
"""Tests successful registration with CUDA enabled."""
226
221
# Preps
227
- fake_wallet = mocker .Mock (autospec = Wallet )
228
222
fake_wallet .hotkey .ss58_address = "hotkey_ss58"
229
223
fake_wallet .coldkey .ss58_address = "coldkey_ss58"
230
224
@@ -278,10 +272,9 @@ async def test_register_extrinsic_success_with_cuda(subtensor, mocker):
278
272
279
273
280
274
@pytest .mark .asyncio
281
- async def test_register_extrinsic_failed_with_cuda (subtensor , mocker ):
275
+ async def test_register_extrinsic_failed_with_cuda (subtensor , fake_wallet , mocker ):
282
276
"""Tests failed registration with CUDA enabled."""
283
277
# Preps
284
- fake_wallet = mocker .Mock (autospec = Wallet )
285
278
fake_wallet .hotkey .ss58_address = "hotkey_ss58"
286
279
fake_wallet .coldkey .ss58_address = "coldkey_ss58"
287
280
@@ -319,11 +312,9 @@ async def test_register_extrinsic_failed_with_cuda(subtensor, mocker):
319
312
320
313
321
314
@pytest .mark .asyncio
322
- async def test_register_extrinsic_subnet_not_exists (subtensor , mocker ):
315
+ async def test_register_extrinsic_subnet_not_exists (subtensor , fake_wallet , mocker ):
323
316
"""Tests registration when subnet does not exist."""
324
317
# Preps
325
- fake_wallet = mocker .Mock (autospec = Wallet )
326
-
327
318
mocked_subnet_exists = mocker .patch .object (
328
319
subtensor , "subnet_exists" , return_value = False
329
320
)
@@ -344,10 +335,9 @@ async def test_register_extrinsic_subnet_not_exists(subtensor, mocker):
344
335
345
336
346
337
@pytest .mark .asyncio
347
- async def test_register_extrinsic_already_registered (subtensor , mocker ):
338
+ async def test_register_extrinsic_already_registered (subtensor , fake_wallet , mocker ):
348
339
"""Tests registration when the key is already registered."""
349
340
# Preps
350
- fake_wallet = mocker .Mock (autospec = Wallet )
351
341
mocked_get_neuron = mocker .patch .object (
352
342
subtensor ,
353
343
"get_neuron_for_pubkey_and_subnet" ,
@@ -371,9 +361,8 @@ async def test_register_extrinsic_already_registered(subtensor, mocker):
371
361
372
362
373
363
@pytest .mark .asyncio
374
- async def test_register_extrinsic_max_attempts_reached (subtensor , mocker ):
364
+ async def test_register_extrinsic_max_attempts_reached (subtensor , fake_wallet , mocker ):
375
365
# Preps
376
- fake_wallet = mocker .Mock (autospec = Wallet )
377
366
fake_wallet .hotkey .ss58_address = "hotkey_ss58"
378
367
fake_wallet .coldkey .ss58_address = "coldkey_ss58"
379
368
@@ -439,10 +428,9 @@ async def is_stale_side_effect(*_, **__):
439
428
440
429
441
430
@pytest .mark .asyncio
442
- async def test_set_subnet_identity_extrinsic_is_success (subtensor , mocker ):
431
+ async def test_set_subnet_identity_extrinsic_is_success (subtensor , fake_wallet , mocker ):
443
432
"""Verify that set_subnet_identity_extrinsic calls the correct functions and returns the correct result."""
444
433
# Preps
445
- wallet = mocker .MagicMock (autospec = Wallet )
446
434
netuid = 123
447
435
subnet_name = "mock_subnet_name"
448
436
github_repo = "mock_github_repo"
@@ -463,7 +451,7 @@ async def test_set_subnet_identity_extrinsic_is_success(subtensor, mocker):
463
451
# Call
464
452
result = await async_registration .set_subnet_identity_extrinsic (
465
453
subtensor = subtensor ,
466
- wallet = wallet ,
454
+ wallet = fake_wallet ,
467
455
netuid = netuid ,
468
456
subnet_name = subnet_name ,
469
457
github_repo = github_repo ,
@@ -479,7 +467,7 @@ async def test_set_subnet_identity_extrinsic_is_success(subtensor, mocker):
479
467
call_module = "SubtensorModule" ,
480
468
call_function = "set_subnet_identity" ,
481
469
call_params = {
482
- "hotkey" : wallet .hotkey .ss58_address ,
470
+ "hotkey" : fake_wallet .hotkey .ss58_address ,
483
471
"netuid" : netuid ,
484
472
"subnet_name" : subnet_name ,
485
473
"github_repo" : github_repo ,
@@ -492,7 +480,7 @@ async def test_set_subnet_identity_extrinsic_is_success(subtensor, mocker):
492
480
)
493
481
mocked_submit_extrinsic .assert_awaited_once_with (
494
482
call = mocked_compose_call .return_value ,
495
- wallet = wallet ,
483
+ wallet = fake_wallet ,
496
484
wait_for_inclusion = False ,
497
485
wait_for_finalization = True ,
498
486
)
@@ -501,10 +489,9 @@ async def test_set_subnet_identity_extrinsic_is_success(subtensor, mocker):
501
489
502
490
503
491
@pytest .mark .asyncio
504
- async def test_set_subnet_identity_extrinsic_is_failed (subtensor , mocker ):
492
+ async def test_set_subnet_identity_extrinsic_is_failed (subtensor , fake_wallet , mocker ):
505
493
"""Verify that set_subnet_identity_extrinsic calls the correct functions and returns False with bad result."""
506
494
# Preps
507
- wallet = mocker .MagicMock (autospec = Wallet )
508
495
netuid = 123
509
496
subnet_name = "mock_subnet_name"
510
497
github_repo = "mock_github_repo"
@@ -527,7 +514,7 @@ async def test_set_subnet_identity_extrinsic_is_failed(subtensor, mocker):
527
514
# Call
528
515
result = await async_registration .set_subnet_identity_extrinsic (
529
516
subtensor = subtensor ,
530
- wallet = wallet ,
517
+ wallet = fake_wallet ,
531
518
netuid = netuid ,
532
519
subnet_name = subnet_name ,
533
520
github_repo = github_repo ,
@@ -545,7 +532,7 @@ async def test_set_subnet_identity_extrinsic_is_failed(subtensor, mocker):
545
532
call_module = "SubtensorModule" ,
546
533
call_function = "set_subnet_identity" ,
547
534
call_params = {
548
- "hotkey" : wallet .hotkey .ss58_address ,
535
+ "hotkey" : fake_wallet .hotkey .ss58_address ,
549
536
"netuid" : netuid ,
550
537
"subnet_name" : subnet_name ,
551
538
"github_repo" : github_repo ,
@@ -558,7 +545,7 @@ async def test_set_subnet_identity_extrinsic_is_failed(subtensor, mocker):
558
545
)
559
546
mocked_submit_extrinsic .assert_awaited_once_with (
560
547
call = mocked_compose_call .return_value ,
561
- wallet = wallet ,
548
+ wallet = fake_wallet ,
562
549
wait_for_inclusion = True ,
563
550
wait_for_finalization = True ,
564
551
)
0 commit comments