Skip to content

Commit

Permalink
test_swap_idempotency
Browse files Browse the repository at this point in the history
  • Loading branch information
camfairchild committed Jan 8, 2025
1 parent 449043f commit cf1d1c1
Showing 1 changed file with 38 additions and 19 deletions.
57 changes: 38 additions & 19 deletions pallets/subtensor/src/tests/swap_coldkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,32 +274,51 @@ fn test_swap_with_zero_balance() {
});
}

// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test swap_coldkey -- test_swap_idempotency --exact --nocapture
// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::swap_coldkey::test_swap_idempotency --exact --show-output
#[test]
fn test_swap_idempotency() {
new_test_ext(1).execute_with(|| {
assert!(false);
let old_coldkey = U256::from(1);
let new_coldkey = U256::from(2);
let hotkey = U256::from(3);
let netuid = 1u16;
let stake = 100;

// let old_coldkey = U256::from(1);
// let new_coldkey = U256::from(2);
// let stake = 100;
// Add a network
add_network(netuid, 1, 0);
SubtensorModule::add_balance_to_coldkey_account(&old_coldkey, stake); // Give old coldkey some balance
// Stake to a hotkey
register_ok_neuron(netuid, hotkey, old_coldkey, 1001000);
assert_ok!(SubtensorModule::add_stake(
<<Test as Config>::RuntimeOrigin>::signed(old_coldkey),
hotkey,
netuid,
stake
));

// TotalColdkeyStake::<Test>::insert(old_coldkey, stake);
// Get stake before swap
let stake_before_swap = SubtensorModule::get_total_stake_for_coldkey(&old_coldkey);

// let mut weight = Weight::zero();
// assert_ok!(SubtensorModule::perform_swap_coldkey(
// &old_coldkey,
// &new_coldkey,
// &mut weight
// ));
// assert_ok!(SubtensorModule::perform_swap_coldkey(
// &old_coldkey,
// &new_coldkey,
// &mut weight
// ));
let mut weight = Weight::zero();
assert_ok!(SubtensorModule::perform_swap_coldkey(
&old_coldkey,
&new_coldkey,
&mut weight
));
assert_ok!(SubtensorModule::perform_swap_coldkey(
&old_coldkey,
&new_coldkey,
&mut weight
));

// assert_eq!(TotalColdkeyStake::<Test>::get(old_coldkey), 0);
// assert_eq!(TotalColdkeyStake::<Test>::get(new_coldkey), stake);
assert_eq!(
SubtensorModule::get_total_stake_for_coldkey(&old_coldkey),
0
);
assert_eq!(
SubtensorModule::get_total_stake_for_coldkey(&new_coldkey),
stake_before_swap
);
});
}

Expand Down

0 comments on commit cf1d1c1

Please sign in to comment.