@@ -49,15 +49,14 @@ fn test_dynamic_function_various_values() {
49
49
} ) ;
50
50
}
51
51
52
-
53
52
// Test the base case of running coinbase with zero emission.
54
53
// This test verifies that the coinbase mechanism can handle the edge case
55
54
// of zero emission without errors or unexpected behavior.
56
55
// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::coinbase::test_coinbase_basecase --exact --show-output --nocapture
57
56
#[ test]
58
57
fn test_coinbase_basecase ( ) {
59
58
new_test_ext ( 1 ) . execute_with ( || {
60
- SubtensorModule :: run_coinbase ( I96F32 :: from_num ( 0.0 ) ) ;
59
+ SubtensorModule :: run_coinbase ( I96F32 :: from_num ( 0.0 ) ) ;
61
60
} ) ;
62
61
}
63
62
@@ -73,11 +72,11 @@ fn test_coinbase_tao_issuance_base() {
73
72
let netuid: u16 = 1 ;
74
73
let emission: u64 = 1_234_567 ;
75
74
add_network ( netuid, 1 , 0 ) ;
76
- assert_eq ! ( SubnetTAO :: <Test >:: get( netuid ) , 0 ) ;
77
- SubtensorModule :: run_coinbase ( I96F32 :: from_num ( emission ) ) ;
78
- assert_eq ! ( SubnetTAO :: <Test >:: get( netuid ) , emission) ;
79
- assert_eq ! ( TotalIssuance :: <Test >:: get( ) , emission) ;
80
- assert_eq ! ( TotalStake :: <Test >:: get( ) , emission) ;
75
+ assert_eq ! ( SubnetTAO :: <Test >:: get( netuid) , 0 ) ;
76
+ SubtensorModule :: run_coinbase ( I96F32 :: from_num ( emission) ) ;
77
+ assert_eq ! ( SubnetTAO :: <Test >:: get( netuid) , emission) ;
78
+ assert_eq ! ( TotalIssuance :: <Test >:: get( ) , emission) ;
79
+ assert_eq ! ( TotalStake :: <Test >:: get( ) , emission) ;
81
80
} ) ;
82
81
}
83
82
@@ -98,15 +97,15 @@ fn test_coinbase_tao_issuance_multiple() {
98
97
add_network ( netuid1, 1 , 0 ) ;
99
98
add_network ( netuid2, 1 , 0 ) ;
100
99
add_network ( netuid3, 1 , 0 ) ;
101
- assert_eq ! ( SubnetTAO :: <Test >:: get( netuid1 ) , 0 ) ;
102
- assert_eq ! ( SubnetTAO :: <Test >:: get( netuid2 ) , 0 ) ;
103
- assert_eq ! ( SubnetTAO :: <Test >:: get( netuid3 ) , 0 ) ;
104
- SubtensorModule :: run_coinbase ( I96F32 :: from_num ( emission ) ) ;
105
- assert_eq ! ( SubnetTAO :: <Test >:: get( netuid1 ) , emission/ 3 ) ;
106
- assert_eq ! ( SubnetTAO :: <Test >:: get( netuid2 ) , emission/ 3 ) ;
107
- assert_eq ! ( SubnetTAO :: <Test >:: get( netuid3 ) , emission/ 3 ) ;
108
- assert_eq ! ( TotalIssuance :: <Test >:: get( ) , emission) ;
109
- assert_eq ! ( TotalStake :: <Test >:: get( ) , emission) ;
100
+ assert_eq ! ( SubnetTAO :: <Test >:: get( netuid1) , 0 ) ;
101
+ assert_eq ! ( SubnetTAO :: <Test >:: get( netuid2) , 0 ) ;
102
+ assert_eq ! ( SubnetTAO :: <Test >:: get( netuid3) , 0 ) ;
103
+ SubtensorModule :: run_coinbase ( I96F32 :: from_num ( emission) ) ;
104
+ assert_eq ! ( SubnetTAO :: <Test >:: get( netuid1) , emission / 3 ) ;
105
+ assert_eq ! ( SubnetTAO :: <Test >:: get( netuid2) , emission / 3 ) ;
106
+ assert_eq ! ( SubnetTAO :: <Test >:: get( netuid3) , emission / 3 ) ;
107
+ assert_eq ! ( TotalIssuance :: <Test >:: get( ) , emission) ;
108
+ assert_eq ! ( TotalStake :: <Test >:: get( ) , emission) ;
110
109
} ) ;
111
110
}
112
111
@@ -128,18 +127,18 @@ fn test_coinbase_tao_issuance_different_prices() {
128
127
SubnetMechanism :: < Test > :: insert ( netuid1, 1 ) ;
129
128
SubnetMechanism :: < Test > :: insert ( netuid2, 1 ) ;
130
129
// Set subnet prices.
131
- SubnetMovingPrice :: < Test > :: insert ( netuid1, I96F32 :: from_num ( 1 ) ) ;
132
- SubnetMovingPrice :: < Test > :: insert ( netuid2, I96F32 :: from_num ( 2 ) ) ;
130
+ SubnetMovingPrice :: < Test > :: insert ( netuid1, I96F32 :: from_num ( 1 ) ) ;
131
+ SubnetMovingPrice :: < Test > :: insert ( netuid2, I96F32 :: from_num ( 2 ) ) ;
133
132
// Assert initial TAO reserves.
134
- assert_eq ! ( SubnetTAO :: <Test >:: get( netuid1 ) , 0 ) ;
135
- assert_eq ! ( SubnetTAO :: <Test >:: get( netuid2 ) , 0 ) ;
133
+ assert_eq ! ( SubnetTAO :: <Test >:: get( netuid1) , 0 ) ;
134
+ assert_eq ! ( SubnetTAO :: <Test >:: get( netuid2) , 0 ) ;
136
135
// Run the coinbase with the emission amount.
137
- SubtensorModule :: run_coinbase ( I96F32 :: from_num ( emission ) ) ;
136
+ SubtensorModule :: run_coinbase ( I96F32 :: from_num ( emission) ) ;
138
137
// Assert tao emission is split evenly.
139
- assert_eq ! ( SubnetTAO :: <Test >:: get( netuid1 ) , emission/ 3 ) ;
140
- assert_eq ! ( SubnetTAO :: <Test >:: get( netuid2 ) , emission/ 3 + emission/ 3 ) ;
141
- close ( TotalIssuance :: < Test > :: get ( ) , emission, 2 ) ;
142
- close ( TotalStake :: < Test > :: get ( ) , emission, 2 ) ;
138
+ assert_eq ! ( SubnetTAO :: <Test >:: get( netuid1) , emission / 3 ) ;
139
+ assert_eq ! ( SubnetTAO :: <Test >:: get( netuid2) , emission / 3 + emission / 3 ) ;
140
+ close ( TotalIssuance :: < Test > :: get ( ) , emission, 2 ) ;
141
+ close ( TotalStake :: < Test > :: get ( ) , emission, 2 ) ;
143
142
} ) ;
144
143
}
145
144
@@ -158,31 +157,43 @@ fn test_coinbase_moving_prices() {
158
157
SubnetTAO :: < Test > :: insert ( netuid, 1_000_000 ) ;
159
158
SubnetAlphaIn :: < Test > :: insert ( netuid, 1_000_000 ) ;
160
159
SubnetMechanism :: < Test > :: insert ( netuid, 1 ) ;
161
- SubnetMovingPrice :: < Test > :: insert ( netuid, I96F32 :: from_num ( 1 ) ) ;
160
+ SubnetMovingPrice :: < Test > :: insert ( netuid, I96F32 :: from_num ( 1 ) ) ;
162
161
// Updating the moving price keeps it the same.
163
- assert_eq ! ( SubtensorModule :: get_moving_alpha_price( netuid) , I96F32 :: from_num( 1 ) ) ;
164
- SubtensorModule :: update_moving_price ( netuid ) ;
165
- assert_eq ! ( SubtensorModule :: get_moving_alpha_price( netuid) , I96F32 :: from_num( 1 ) ) ;
162
+ assert_eq ! (
163
+ SubtensorModule :: get_moving_alpha_price( netuid) ,
164
+ I96F32 :: from_num( 1 )
165
+ ) ;
166
+ SubtensorModule :: update_moving_price ( netuid) ;
167
+ assert_eq ! (
168
+ SubtensorModule :: get_moving_alpha_price( netuid) ,
169
+ I96F32 :: from_num( 1 )
170
+ ) ;
166
171
// Check alpha of 1.
167
172
// Set price to zero.
168
- SubnetMovingPrice :: < Test > :: insert ( netuid, I96F32 :: from_num ( 0 ) ) ;
169
- SubnetMovingAlpha :: < Test > :: set ( I96F32 :: from_num ( 1.0 ) ) ;
173
+ SubnetMovingPrice :: < Test > :: insert ( netuid, I96F32 :: from_num ( 0 ) ) ;
174
+ SubnetMovingAlpha :: < Test > :: set ( I96F32 :: from_num ( 1.0 ) ) ;
170
175
// Run moving 1 times.
171
- SubtensorModule :: update_moving_price ( netuid ) ;
176
+ SubtensorModule :: update_moving_price ( netuid) ;
172
177
// Assert price is == 100% of the real price.
173
- assert_eq ! ( SubtensorModule :: get_moving_alpha_price( netuid) , I96F32 :: from_num( 1.0 ) ) ;
178
+ assert_eq ! (
179
+ SubtensorModule :: get_moving_alpha_price( netuid) ,
180
+ I96F32 :: from_num( 1.0 )
181
+ ) ;
174
182
// Set price to zero.
175
- SubnetMovingPrice :: < Test > :: insert ( netuid, I96F32 :: from_num ( 0 ) ) ;
176
- SubnetMovingAlpha :: < Test > :: set ( I96F32 :: from_num ( 0.1 ) ) ;
183
+ SubnetMovingPrice :: < Test > :: insert ( netuid, I96F32 :: from_num ( 0 ) ) ;
184
+ SubnetMovingAlpha :: < Test > :: set ( I96F32 :: from_num ( 0.1 ) ) ;
177
185
// Run moving 6 times.
178
- SubtensorModule :: update_moving_price ( netuid ) ;
179
- SubtensorModule :: update_moving_price ( netuid ) ;
180
- SubtensorModule :: update_moving_price ( netuid ) ;
181
- SubtensorModule :: update_moving_price ( netuid ) ;
182
- SubtensorModule :: update_moving_price ( netuid ) ;
183
- SubtensorModule :: update_moving_price ( netuid ) ;
186
+ SubtensorModule :: update_moving_price ( netuid) ;
187
+ SubtensorModule :: update_moving_price ( netuid) ;
188
+ SubtensorModule :: update_moving_price ( netuid) ;
189
+ SubtensorModule :: update_moving_price ( netuid) ;
190
+ SubtensorModule :: update_moving_price ( netuid) ;
191
+ SubtensorModule :: update_moving_price ( netuid) ;
184
192
// Assert price is > 50% of the real price.
185
- assert_eq ! ( SubtensorModule :: get_moving_alpha_price( netuid) , I96F32 :: from_num( 0.468559 ) ) ;
193
+ assert_eq ! (
194
+ SubtensorModule :: get_moving_alpha_price( netuid) ,
195
+ I96F32 :: from_num( 0.468559 )
196
+ ) ;
186
197
} ) ;
187
198
}
188
199
@@ -206,13 +217,13 @@ fn test_coinbase_alpha_issuance_base() {
206
217
SubnetTAO :: < Test > :: insert ( netuid2, 1_000_000 ) ;
207
218
SubnetAlphaIn :: < Test > :: insert ( netuid2, 1_000_000 ) ;
208
219
// Check initial
209
- assert_eq ! ( SubnetAlphaIn :: <Test >:: get( netuid1 ) , 0 ) ;
210
- assert_eq ! ( SubnetAlphaIn :: <Test >:: get( netuid2 ) , 0 ) ;
211
- SubtensorModule :: run_coinbase ( I96F32 :: from_num ( emission ) ) ;
220
+ assert_eq ! ( SubnetAlphaIn :: <Test >:: get( netuid1) , 0 ) ;
221
+ assert_eq ! ( SubnetAlphaIn :: <Test >:: get( netuid2) , 0 ) ;
222
+ SubtensorModule :: run_coinbase ( I96F32 :: from_num ( emission) ) ;
212
223
// tao_in = 500_000
213
224
// alpha_in = 500_000/price = 500_000
214
- assert_eq ! ( SubnetAlphaIn :: <Test >:: get( netuid1 ) , emission/ 2 ) ;
215
- assert_eq ! ( SubnetAlphaIn :: <Test >:: get( netuid2 ) , emission/ 2 ) ;
225
+ assert_eq ! ( SubnetAlphaIn :: <Test >:: get( netuid1) , emission / 2 ) ;
226
+ assert_eq ! ( SubnetAlphaIn :: <Test >:: get( netuid2) , emission / 2 ) ;
216
227
} ) ;
217
228
}
218
229
@@ -235,17 +246,18 @@ fn test_coinbase_alpha_issuance_different() {
235
246
SubnetTAO :: < Test > :: insert ( netuid2, initial) ;
236
247
SubnetAlphaIn :: < Test > :: insert ( netuid2, initial) ;
237
248
// Set subnet prices.
238
- SubnetMovingPrice :: < Test > :: insert ( netuid1, I96F32 :: from_num ( 1 ) ) ;
239
- SubnetMovingPrice :: < Test > :: insert ( netuid2, I96F32 :: from_num ( 2 ) ) ;
249
+ SubnetMovingPrice :: < Test > :: insert ( netuid1, I96F32 :: from_num ( 1 ) ) ;
250
+ SubnetMovingPrice :: < Test > :: insert ( netuid2, I96F32 :: from_num ( 2 ) ) ;
240
251
// Run coinbase
241
- SubtensorModule :: run_coinbase ( I96F32 :: from_num ( emission ) ) ;
252
+ SubtensorModule :: run_coinbase ( I96F32 :: from_num ( emission) ) ;
242
253
// tao_in = 333_333
243
254
// alpha_in = 333_333/price = 333_333 + initial
244
- assert_eq ! ( SubnetAlphaIn :: <Test >:: get( netuid1 ) , initial + emission/ 3 ) ;
255
+ assert_eq ! ( SubnetAlphaIn :: <Test >:: get( netuid1) , initial + emission / 3 ) ;
245
256
// tao_in = 666_666
246
257
// alpha_in = 666_666/price = 666_666 + initial
247
- assert_eq ! ( SubnetAlphaIn :: <Test >:: get( netuid2 ) , initial + emission/3 + emission/3 ) ;
258
+ assert_eq ! (
259
+ SubnetAlphaIn :: <Test >:: get( netuid2) ,
260
+ initial + emission / 3 + emission / 3
261
+ ) ;
248
262
} ) ;
249
263
}
250
-
251
-
0 commit comments