@@ -763,6 +763,67 @@ fn test_add_stake_insufficient_liquidity() {
763763 } ) ;
764764}
765765
766+ /// cargo test --package pallet-subtensor --lib -- tests::staking::test_add_stake_insufficient_liquidity_one_side_ok --exact --show-output
767+ #[ test]
768+ fn test_add_stake_insufficient_liquidity_one_side_ok ( ) {
769+ new_test_ext ( 1 ) . execute_with ( || {
770+ let subnet_owner_coldkey = U256 :: from ( 1001 ) ;
771+ let subnet_owner_hotkey = U256 :: from ( 1002 ) ;
772+ let hotkey = U256 :: from ( 2 ) ;
773+ let coldkey = U256 :: from ( 3 ) ;
774+ let amount_staked = DefaultMinStake :: < Test > :: get ( ) * 10 ;
775+
776+ let netuid = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
777+ SubtensorModule :: create_account_if_non_existent ( & coldkey, & hotkey) ;
778+ SubtensorModule :: add_balance_to_coldkey_account ( & coldkey, amount_staked) ;
779+
780+ // Set the liquidity at lowest possible value so that all staking requests fail
781+ let reserve_alpha = u64:: from ( mock:: SwapMinimumReserve :: get ( ) ) ;
782+ let reserve_tao = u64:: from ( mock:: SwapMinimumReserve :: get ( ) ) - 1 ;
783+ mock:: setup_reserves ( netuid, reserve_tao, reserve_alpha. into ( ) ) ;
784+
785+ // Check the error
786+ assert_ok ! ( SubtensorModule :: add_stake(
787+ RuntimeOrigin :: signed( coldkey) ,
788+ hotkey,
789+ netuid,
790+ amount_staked
791+ ) ) ;
792+ } ) ;
793+ }
794+
795+ /// cargo test --package pallet-subtensor --lib -- tests::staking::test_add_stake_insufficient_liquidity_one_side_fail --exact --show-output
796+ #[ test]
797+ fn test_add_stake_insufficient_liquidity_one_side_fail ( ) {
798+ new_test_ext ( 1 ) . execute_with ( || {
799+ let subnet_owner_coldkey = U256 :: from ( 1001 ) ;
800+ let subnet_owner_hotkey = U256 :: from ( 1002 ) ;
801+ let hotkey = U256 :: from ( 2 ) ;
802+ let coldkey = U256 :: from ( 3 ) ;
803+ let amount_staked = DefaultMinStake :: < Test > :: get ( ) * 10 ;
804+
805+ let netuid = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
806+ SubtensorModule :: create_account_if_non_existent ( & coldkey, & hotkey) ;
807+ SubtensorModule :: add_balance_to_coldkey_account ( & coldkey, amount_staked) ;
808+
809+ // Set the liquidity at lowest possible value so that all staking requests fail
810+ let reserve_alpha = u64:: from ( mock:: SwapMinimumReserve :: get ( ) ) - 1 ;
811+ let reserve_tao = u64:: from ( mock:: SwapMinimumReserve :: get ( ) ) ;
812+ mock:: setup_reserves ( netuid, reserve_tao, reserve_alpha. into ( ) ) ;
813+
814+ // Check the error
815+ assert_noop ! (
816+ SubtensorModule :: add_stake(
817+ RuntimeOrigin :: signed( coldkey) ,
818+ hotkey,
819+ netuid,
820+ amount_staked
821+ ) ,
822+ Error :: <Test >:: InsufficientLiquidity
823+ ) ;
824+ } ) ;
825+ }
826+
766827#[ test]
767828fn test_remove_stake_insufficient_liquidity ( ) {
768829 new_test_ext ( 1 ) . execute_with ( || {
0 commit comments