@@ -397,4 +397,184 @@ fn test_pending_swapped() {
397
397
assert_eq ! ( PendingEmission :: <Test >:: get( netuid) , 1_000_000_000 - 125000000 ) ; // 1 - swapped.
398
398
assert_eq ! ( PendingRootDivs :: <Test >:: get( netuid) , 125000000 ) ; // swapped * (price = 1)
399
399
} ) ;
400
+ }
401
+
402
+
403
+ // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::coinbase::test_drain_base --exact --show-output --nocapture
404
+ #[ test]
405
+ fn test_drain_base ( ) {
406
+ new_test_ext ( 1 ) . execute_with ( || {
407
+ SubtensorModule :: drain_pending_emission (
408
+ 0 ,
409
+ 0 ,
410
+ 0 ,
411
+ 0 ,
412
+ 0 ,
413
+ )
414
+ } ) ;
415
+ }
416
+
417
+ // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::coinbase::test_drain_base_with_subnet --exact --show-output --nocapture
418
+ #[ test]
419
+ fn test_drain_base_with_subnet ( ) {
420
+ new_test_ext ( 1 ) . execute_with ( || {
421
+ let netuid: u16 = 1 ;
422
+ add_network ( netuid, 1 , 0 ) ;
423
+ SubtensorModule :: drain_pending_emission (
424
+ netuid,
425
+ 0 ,
426
+ 0 ,
427
+ 0 ,
428
+ 0 ,
429
+ )
430
+ } ) ;
431
+ }
432
+
433
+ // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::coinbase::test_drain_base_with_subnet_with_single_staker_not_registered --exact --show-output --nocapture
434
+ #[ test]
435
+ fn test_drain_base_with_subnet_with_single_staker_not_registered ( ) {
436
+ new_test_ext ( 1 ) . execute_with ( || {
437
+ let netuid: u16 = 1 ;
438
+ add_network ( netuid, 1 , 0 ) ;
439
+ let hotkey = U256 :: from ( 1 ) ;
440
+ let coldkey = U256 :: from ( 2 ) ;
441
+ let stake_before: u64 = 1_000_000_000 ;
442
+ SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
443
+ & hotkey,
444
+ & coldkey,
445
+ netuid,
446
+ stake_before,
447
+ ) ;
448
+ let pending_alpha: u64 = 1_000_000_000 ;
449
+ SubtensorModule :: drain_pending_emission (
450
+ netuid,
451
+ pending_alpha,
452
+ 0 ,
453
+ 0 ,
454
+ 0 ,
455
+ ) ;
456
+ let stake_after = SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet (
457
+ & hotkey, & coldkey, netuid,
458
+ ) ;
459
+ assert_eq ! ( stake_before, stake_after ) ; // Not registered.
460
+ } ) ;
461
+ }
462
+
463
+ // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::coinbase::test_drain_base_with_subnet_with_single_staker_registered --exact --show-output --nocapture
464
+ #[ test]
465
+ fn test_drain_base_with_subnet_with_single_staker_registered ( ) {
466
+ new_test_ext ( 1 ) . execute_with ( || {
467
+ let netuid: u16 = 1 ;
468
+ add_network ( netuid, 1 , 0 ) ;
469
+ let hotkey = U256 :: from ( 1 ) ;
470
+ let coldkey = U256 :: from ( 2 ) ;
471
+ let stake_before: u64 = 1_000_000_000 ;
472
+ register_ok_neuron ( netuid, hotkey, coldkey, 0 ) ;
473
+ SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
474
+ & hotkey,
475
+ & coldkey,
476
+ netuid,
477
+ stake_before,
478
+ ) ;
479
+ let pending_alpha: u64 = 1_000_000_000 ;
480
+ SubtensorModule :: drain_pending_emission (
481
+ netuid,
482
+ pending_alpha,
483
+ 0 ,
484
+ 0 ,
485
+ 0 ,
486
+ ) ;
487
+ let stake_after = SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet (
488
+ & hotkey, & coldkey, netuid,
489
+ ) ;
490
+ close ( stake_before + pending_alpha, stake_after, 10 ) ; // Registered gets all emission.
491
+ } ) ;
492
+ }
493
+
494
+ // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::coinbase::test_drain_base_with_subnet_with_single_staker_registered_root_weight --exact --show-output --nocapture
495
+ #[ test]
496
+ fn test_drain_base_with_subnet_with_single_staker_registered_root_weight ( ) {
497
+ new_test_ext ( 1 ) . execute_with ( || {
498
+ let root: u16 = 0 ;
499
+ let netuid: u16 = 1 ;
500
+ add_network ( netuid, 1 , 0 ) ;
501
+ let hotkey = U256 :: from ( 1 ) ;
502
+ let coldkey = U256 :: from ( 2 ) ;
503
+ let stake_before: u64 = 1_000_000_000 ;
504
+ // register_ok_neuron(root, hotkey, coldkey, 0);
505
+ register_ok_neuron ( netuid, hotkey, coldkey, 0 ) ;
506
+ SubtensorModule :: set_tao_weight ( u64:: MAX ) ; // Set TAO weight to 1.0
507
+ SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
508
+ & hotkey,
509
+ & coldkey,
510
+ root,
511
+ stake_before,
512
+ ) ;
513
+ SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
514
+ & hotkey,
515
+ & coldkey,
516
+ netuid,
517
+ stake_before,
518
+ ) ;
519
+ let pending_tao: u64 = 1_000_000_000 ;
520
+ let pending_alpha: u64 = 1_000_000_000 ;
521
+ SubtensorModule :: drain_pending_emission (
522
+ netuid,
523
+ pending_alpha,
524
+ pending_tao,
525
+ 0 ,
526
+ 0 ,
527
+ ) ;
528
+ let stake_after = SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet (
529
+ & hotkey, & coldkey, netuid,
530
+ ) ;
531
+ let root_after = SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet (
532
+ & hotkey, & coldkey, root,
533
+ ) ;
534
+ close ( stake_before + pending_alpha, stake_after, 10 ) ; // Registered gets all alpha emission.
535
+ close ( stake_before + pending_tao, root_after, 10 ) ; // Registered gets all tao emission
536
+ } ) ;
537
+ }
538
+
539
+ // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::coinbase::test_drain_base_with_subnet_with_two_stakers_registered --exact --show-output --nocapture
540
+ #[ test]
541
+ fn test_drain_base_with_subnet_with_two_stakers_registered ( ) {
542
+ new_test_ext ( 1 ) . execute_with ( || {
543
+ let netuid: u16 = 1 ;
544
+ add_network ( netuid, 1 , 0 ) ;
545
+ let hotkey1 = U256 :: from ( 1 ) ;
546
+ let hotkey2 = U256 :: from ( 2 ) ;
547
+ let coldkey = U256 :: from ( 3 ) ;
548
+ let stake_before: u64 = 1_000_000_000 ;
549
+ register_ok_neuron ( netuid, hotkey1, coldkey, 0 ) ;
550
+ register_ok_neuron ( netuid, hotkey2, coldkey, 0 ) ;
551
+ SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
552
+ & hotkey1,
553
+ & coldkey,
554
+ netuid,
555
+ stake_before,
556
+ ) ;
557
+ SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
558
+ & hotkey2,
559
+ & coldkey,
560
+ netuid,
561
+ stake_before,
562
+ ) ;
563
+ let pending_alpha: u64 = 1_000_000_000 ;
564
+ SubtensorModule :: drain_pending_emission (
565
+ netuid,
566
+ pending_alpha,
567
+ 0 ,
568
+ 0 ,
569
+ 0 ,
570
+ ) ;
571
+ let stake_after1 = SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet (
572
+ & hotkey1, & coldkey, netuid,
573
+ ) ;
574
+ let stake_after2 = SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet (
575
+ & hotkey2, & coldkey, netuid,
576
+ ) ;
577
+ close ( stake_before + pending_alpha/2 , stake_after1, 10 ) ; // Registered gets 1/2 emission
578
+ close ( stake_before + pending_alpha/2 , stake_after2, 10 ) ; // Registered gets 1/2 emission.
579
+ } ) ;
400
580
}
0 commit comments