@@ -195,6 +195,9 @@ fn test_coinbase_moving_prices() {
195
195
SubtensorModule :: get_moving_alpha_price( netuid) ,
196
196
I96F32 :: from_num( 1 )
197
197
) ;
198
+ // Skip some blocks so that EMA price is now slowed down
199
+ System :: set_block_number ( 7_200_000 ) ;
200
+
198
201
SubtensorModule :: update_moving_price ( netuid) ;
199
202
assert_eq ! (
200
203
SubtensorModule :: get_moving_alpha_price( netuid) ,
@@ -207,10 +210,7 @@ fn test_coinbase_moving_prices() {
207
210
// Run moving 1 times.
208
211
SubtensorModule :: update_moving_price ( netuid) ;
209
212
// Assert price is == 100% of the real price.
210
- assert_eq ! (
211
- SubtensorModule :: get_moving_alpha_price( netuid) ,
212
- I96F32 :: from_num( 1.0 )
213
- ) ;
213
+ assert ! ( I96F32 :: from_num( 1.0 ) - SubtensorModule :: get_moving_alpha_price( netuid) < 0.001 ) ;
214
214
// Set price to zero.
215
215
SubnetMovingPrice :: < Test > :: insert ( netuid, I96F32 :: from_num ( 0 ) ) ;
216
216
SubnetMovingAlpha :: < Test > :: set ( I96F32 :: from_num ( 0.1 ) ) ;
@@ -222,13 +222,63 @@ fn test_coinbase_moving_prices() {
222
222
SubtensorModule :: update_moving_price ( netuid) ;
223
223
SubtensorModule :: update_moving_price ( netuid) ;
224
224
// Assert price is > 50% of the real price.
225
- assert_eq ! (
226
- SubtensorModule :: get_moving_alpha_price( netuid) ,
227
- I96F32 :: from_num ( 0.468559 )
225
+ assert ! (
226
+ ( I96F32 :: from_num ( 0.468559 ) - SubtensorModule :: get_moving_alpha_price( netuid) ) . abs ( )
227
+ < 0.001
228
228
) ;
229
229
} ) ;
230
230
}
231
231
232
+ // Test moving price updates slow down at the beginning.
233
+ // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::coinbase::test_update_moving_price_initial --exact --show-output --nocapture
234
+ #[ test]
235
+ fn test_update_moving_price_initial ( ) {
236
+ new_test_ext ( 1 ) . execute_with ( || {
237
+ let netuid: u16 = 1 ;
238
+ add_network ( netuid, 1 , 0 ) ;
239
+ // Set current price to 1.0
240
+ SubnetTAO :: < Test > :: insert ( netuid, 1_000_000 ) ;
241
+ SubnetAlphaIn :: < Test > :: insert ( netuid, 1_000_000 ) ;
242
+ SubnetMechanism :: < Test > :: insert ( netuid, 1 ) ;
243
+ SubnetMovingAlpha :: < Test > :: set ( I96F32 :: from_num ( 0.5 ) ) ;
244
+ SubnetMovingPrice :: < Test > :: insert ( netuid, I96F32 :: from_num ( 0 ) ) ;
245
+
246
+ // Registered recently
247
+ System :: set_block_number ( 510 ) ;
248
+ NetworkRegisteredAt :: < Test > :: insert ( netuid, 500 ) ;
249
+
250
+ SubtensorModule :: update_moving_price ( netuid) ;
251
+
252
+ let new_price = SubnetMovingPrice :: < Test > :: get ( netuid) ;
253
+ assert ! ( new_price. to_num:: <f64 >( ) < 0.001 ) ;
254
+ } ) ;
255
+ }
256
+
257
+ // Test moving price updates slow down at the beginning.
258
+ // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::coinbase::test_update_moving_price_after_time --exact --show-output --nocapture
259
+ #[ test]
260
+ fn test_update_moving_price_after_time ( ) {
261
+ new_test_ext ( 1 ) . execute_with ( || {
262
+ let netuid: u16 = 1 ;
263
+ add_network ( netuid, 1 , 0 ) ;
264
+ // Set current price to 1.0
265
+ SubnetTAO :: < Test > :: insert ( netuid, 1_000_000 ) ;
266
+ SubnetAlphaIn :: < Test > :: insert ( netuid, 1_000_000 ) ;
267
+ SubnetMechanism :: < Test > :: insert ( netuid, 1 ) ;
268
+ SubnetMovingAlpha :: < Test > :: set ( I96F32 :: from_num ( 0.5 ) ) ;
269
+ SubnetMovingPrice :: < Test > :: insert ( netuid, I96F32 :: from_num ( 0 ) ) ;
270
+
271
+ // Registered long time ago
272
+ System :: set_block_number ( 7_200_500 ) ;
273
+ NetworkRegisteredAt :: < Test > :: insert ( netuid, 500 ) ;
274
+
275
+ SubtensorModule :: update_moving_price ( netuid) ;
276
+
277
+ let new_price = SubnetMovingPrice :: < Test > :: get ( netuid) ;
278
+ assert ! ( ( new_price. to_num:: <f64 >( ) - 0.5 ) . abs( ) < 0.001 ) ;
279
+ } ) ;
280
+ }
281
+
232
282
// Test basic alpha issuance in coinbase mechanism.
233
283
// This test verifies that:
234
284
// - Alpha issuance is initialized to 0 for new subnets
0 commit comments