11#![ allow( clippy:: arithmetic_side_effects, clippy:: unwrap_used) ]
2- use crate :: utils:: rate_limiting:: TransactionType ;
2+
3+ use core:: num:: NonZeroU64 ;
4+
35use frame_support:: PalletId ;
46use frame_support:: derive_impl;
57use frame_support:: dispatch:: DispatchResultWithPostInfo ;
@@ -20,8 +22,9 @@ use sp_runtime::{
2022} ;
2123use sp_std:: cmp:: Ordering ;
2224use substrate_fixed:: types:: U64F64 ;
23- use subtensor_swap_interface:: { LiquidityDataProvider , SwapHandler } ;
25+ use subtensor_swap_interface:: { LiquidityDataProvider , OrderType , SwapHandler } ;
2426
27+ use crate :: utils:: rate_limiting:: TransactionType ;
2528use crate :: * ;
2629
2730type Block = frame_system:: mocking:: MockBlock < Test > ;
@@ -423,6 +426,7 @@ parameter_types! {
423426 pub const SwapMaxFeeRate : u16 = 10000 ; // 15.26%
424427 pub const SwapMaxPositions : u32 = 100 ;
425428 pub const SwapMinimumLiquidity : u64 = 1_000 ;
429+ pub const SwapMinimumReserve : NonZeroU64 = NonZeroU64 :: new( 1 ) . unwrap( ) ;
426430}
427431
428432impl pallet_subtensor_swap:: Config for Test {
@@ -433,6 +437,7 @@ impl pallet_subtensor_swap::Config for Test {
433437 type MaxFeeRate = SwapMaxFeeRate ;
434438 type MaxPositions = SwapMaxPositions ;
435439 type MinimumLiquidity = SwapMinimumLiquidity ;
440+ type MinimumReserve = SwapMinimumReserve ;
436441 type WeightInfo = ( ) ;
437442}
438443
@@ -852,3 +857,27 @@ pub fn increase_stake_on_hotkey_account(hotkey: &U256, increment: u64, netuid: u
852857 netuid,
853858 ) ;
854859}
860+
861+ pub ( crate ) fn setup_reserves ( netuid : u16 , tao : u64 , alpha : u64 ) {
862+ SubnetTAO :: < Test > :: set ( netuid, tao) ;
863+ SubnetAlphaIn :: < Test > :: set ( netuid, alpha) ;
864+ }
865+
866+ pub ( crate ) fn swap_tao_to_alpha ( netuid : u16 , tao : u64 ) -> u64 {
867+ let result = <Test as pallet:: Config >:: SwapInterface :: swap (
868+ netuid,
869+ OrderType :: Buy ,
870+ tao,
871+ <Test as pallet:: Config >:: SwapInterface :: max_price ( ) ,
872+ true ,
873+ ) ;
874+
875+ assert_ok ! ( & result) ;
876+
877+ let result = result. unwrap ( ) . amount_paid_out ;
878+
879+ // we don't want to have silent 0 comparissons in tests
880+ assert ! ( result > 0 ) ;
881+
882+ result
883+ }
0 commit comments