22
33import pytest
44
5- from bittensor import Balance
6-
75from tests .e2e_tests .utils .chain_interactions import (
86 sudo_set_hyperparameter_values ,
97 wait_epoch ,
10- sudo_set_admin_utils ,
118)
129
1310
1411@pytest .mark .asyncio
15- @pytest .mark .parametrize ("local_chain" , [False ], indirect = True )
1612async def test_incentive (local_chain , subtensor , templates , alice_wallet , bob_wallet ):
1713 """
1814 Test the incentive mechanism and interaction of miners/validators
@@ -35,21 +31,6 @@ async def test_incentive(local_chain, subtensor, templates, alice_wallet, bob_wa
3531 # Verify subnet <netuid> created successfully
3632 assert subtensor .subnet_exists (netuid ), "Subnet wasn't created successfully"
3733
38- # Change tempo to 10
39- tempo_set = 10
40- assert (
41- sudo_set_admin_utils (
42- local_chain ,
43- alice_wallet ,
44- call_function = "sudo_set_tempo" ,
45- call_params = {"netuid" : netuid , "tempo" : tempo_set },
46- return_error_message = True ,
47- )[0 ]
48- is True
49- )
50- tempo = subtensor .get_subnet_hyperparameters (netuid = netuid ).tempo
51- assert tempo_set == tempo
52-
5334 # Register Bob as a neuron on the subnet
5435 assert subtensor .burned_register (
5536 bob_wallet , netuid
@@ -60,27 +41,9 @@ async def test_incentive(local_chain, subtensor, templates, alice_wallet, bob_wa
6041 len (subtensor .neurons (netuid = netuid )) == 2
6142 ), "Alice & Bob not registered in the subnet"
6243
63- # Add stake for Alice
64- assert subtensor .add_stake (
65- alice_wallet ,
66- netuid = netuid ,
67- amount = Balance .from_tao (1_000 ),
68- wait_for_inclusion = True ,
69- wait_for_finalization = True ,
70- ), "Failed to add stake for Alice"
71-
7244 # Wait for the first epoch to pass
7345 await wait_epoch (subtensor , netuid )
7446
75- # Add further stake so validator permit is activated
76- assert subtensor .add_stake (
77- alice_wallet ,
78- netuid = netuid ,
79- amount = Balance .from_tao (1_000 ),
80- wait_for_inclusion = True ,
81- wait_for_finalization = True ,
82- ), "Failed to add stake for Alice"
83-
8447 # Get latest metagraph
8548 metagraph = subtensor .metagraph (netuid )
8649
@@ -91,6 +54,9 @@ async def test_incentive(local_chain, subtensor, templates, alice_wallet, bob_wa
9154 assert alice_neuron .dividends == 0
9255 assert alice_neuron .stake .tao > 0
9356 assert alice_neuron .validator_trust == 0
57+ assert alice_neuron .incentive == 0
58+ assert alice_neuron .consensus == 0
59+ assert alice_neuron .rank == 0
9460
9561 bob_neuron = metagraph .neurons [1 ]
9662
@@ -109,12 +75,13 @@ async def test_incentive(local_chain, subtensor, templates, alice_wallet, bob_wa
10975 )
11076
11177 async with templates .miner (bob_wallet , netuid ):
112- async with templates .validator (alice_wallet , netuid ):
113- # Wait for the Validator to process and set_weights
114- await asyncio .sleep (5 )
78+ async with templates .validator (alice_wallet , netuid ) as validator :
79+ # wait for the Validator to process and set_weights
80+ async with asyncio .timeout (15 ):
81+ await validator .set_weights .wait ()
11582
11683 # Wait few epochs
117- await wait_epoch (subtensor , netuid , times = 2 )
84+ await wait_epoch (subtensor , netuid , times = 4 )
11885
11986 # Refresh metagraph
12087 metagraph = subtensor .metagraph (netuid )
@@ -125,12 +92,15 @@ async def test_incentive(local_chain, subtensor, templates, alice_wallet, bob_wa
12592 assert alice_neuron .validator_permit is True
12693 assert alice_neuron .dividends == 1.0
12794 assert alice_neuron .stake .tao > 0
128- assert alice_neuron .validator_trust == 1
95+ assert alice_neuron .validator_trust > 0.99
96+ assert alice_neuron .incentive < 0.5
97+ assert alice_neuron .consensus < 0.5
98+ assert alice_neuron .rank < 0.5
12999
130100 bob_neuron = metagraph .neurons [1 ]
131- assert bob_neuron .incentive == 1
132- assert bob_neuron .consensus == 1
133- assert bob_neuron .rank == 1
101+ assert bob_neuron .incentive > 0.5
102+ assert bob_neuron .consensus > 0.5
103+ assert bob_neuron .rank > 0.5
134104 assert bob_neuron .trust == 1
135105
136106 print ("✅ Passed test_incentive" )
0 commit comments