2
2
3
3
import pytest
4
4
5
- from bittensor import Balance
6
-
7
5
from tests .e2e_tests .utils .chain_interactions import (
8
6
sudo_set_hyperparameter_values ,
9
7
wait_epoch ,
10
- sudo_set_admin_utils ,
11
8
)
12
9
13
10
14
11
@pytest .mark .asyncio
15
- @pytest .mark .parametrize ("local_chain" , [False ], indirect = True )
16
12
async def test_incentive (local_chain , subtensor , templates , alice_wallet , bob_wallet ):
17
13
"""
18
14
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
35
31
# Verify subnet <netuid> created successfully
36
32
assert subtensor .subnet_exists (netuid ), "Subnet wasn't created successfully"
37
33
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
-
53
34
# Register Bob as a neuron on the subnet
54
35
assert subtensor .burned_register (
55
36
bob_wallet , netuid
@@ -60,27 +41,9 @@ async def test_incentive(local_chain, subtensor, templates, alice_wallet, bob_wa
60
41
len (subtensor .neurons (netuid = netuid )) == 2
61
42
), "Alice & Bob not registered in the subnet"
62
43
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
-
72
44
# Wait for the first epoch to pass
73
45
await wait_epoch (subtensor , netuid )
74
46
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
-
84
47
# Get latest metagraph
85
48
metagraph = subtensor .metagraph (netuid )
86
49
@@ -91,6 +54,9 @@ async def test_incentive(local_chain, subtensor, templates, alice_wallet, bob_wa
91
54
assert alice_neuron .dividends == 0
92
55
assert alice_neuron .stake .tao > 0
93
56
assert alice_neuron .validator_trust == 0
57
+ assert alice_neuron .incentive == 0
58
+ assert alice_neuron .consensus == 0
59
+ assert alice_neuron .rank == 0
94
60
95
61
bob_neuron = metagraph .neurons [1 ]
96
62
@@ -109,12 +75,13 @@ async def test_incentive(local_chain, subtensor, templates, alice_wallet, bob_wa
109
75
)
110
76
111
77
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 ()
115
82
116
83
# Wait few epochs
117
- await wait_epoch (subtensor , netuid , times = 2 )
84
+ await wait_epoch (subtensor , netuid , times = 4 )
118
85
119
86
# Refresh metagraph
120
87
metagraph = subtensor .metagraph (netuid )
@@ -125,12 +92,15 @@ async def test_incentive(local_chain, subtensor, templates, alice_wallet, bob_wa
125
92
assert alice_neuron .validator_permit is True
126
93
assert alice_neuron .dividends == 1.0
127
94
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
129
99
130
100
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
134
104
assert bob_neuron .trust == 1
135
105
136
106
print ("✅ Passed test_incentive" )
0 commit comments