Skip to content

Commit 76bfd18

Browse files
committed
Fix swap_coldkey tests
1 parent 704df27 commit 76bfd18

File tree

4 files changed

+154
-69
lines changed

4 files changed

+154
-69
lines changed

pallets/admin-utils/src/tests/mock.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![allow(clippy::arithmetic_side_effects, clippy::unwrap_used)]
22

3+
use core::num::NonZeroU64;
4+
35
use frame_support::{
46
PalletId, assert_ok, derive_impl, parameter_types,
57
traits::{Everything, Hooks, PrivilegeCmp},
@@ -267,6 +269,7 @@ parameter_types! {
267269
pub const SwapMaxFeeRate: u16 = 10000; // 15.26%
268270
pub const SwapMaxPositions: u32 = 100;
269271
pub const SwapMinimumLiquidity: u64 = 1_000;
272+
pub const SwapMinimumReserve: NonZeroU64 = NonZeroU64::new(1_000_000).unwrap();
270273
}
271274

272275
impl pallet_subtensor_swap::Config for Test {
@@ -277,6 +280,7 @@ impl pallet_subtensor_swap::Config for Test {
277280
type MaxFeeRate = SwapMaxFeeRate;
278281
type MaxPositions = SwapMaxPositions;
279282
type MinimumLiquidity = SwapMinimumLiquidity;
283+
type MinimumReserve = SwapMinimumReserve;
280284
type WeightInfo = ();
281285
}
282286

pallets/subtensor/src/tests/mock.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![allow(clippy::arithmetic_side_effects, clippy::unwrap_used)]
2-
use crate::utils::rate_limiting::TransactionType;
2+
3+
use core::num::NonZeroU64;
4+
35
use frame_support::PalletId;
46
use frame_support::derive_impl;
57
use frame_support::dispatch::DispatchResultWithPostInfo;
@@ -20,8 +22,9 @@ use sp_runtime::{
2022
};
2123
use sp_std::cmp::Ordering;
2224
use 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;
2528
use crate::*;
2629

2730
type 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

428432
impl 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

Comments
 (0)