Skip to content

Commit

Permalink
Merge pull request #423 from opentensor/test-dissolve-network
Browse files Browse the repository at this point in the history
test dissolve_network
  • Loading branch information
distributedstatemachine committed May 16, 2024
2 parents ed84d0d + 7148878 commit 397eb54
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions pallets/subtensor/tests/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,3 +882,81 @@ fn test_get_emission_across_entire_issuance_range() {
}
});
}

#[test]
fn test_dissolve_network_ok() {
new_test_ext(1).execute_with(|| {
let netuid: u16 = 30;
let hotkey = U256::from(1);

add_network(netuid, 0, 0);
let owner_coldkey = SubtensorModule::get_subnet_owner(netuid);
register_ok_neuron(netuid, hotkey, owner_coldkey, 3);

assert!(SubtensorModule::if_subnet_exist(netuid));
assert_ok!(SubtensorModule::dissolve_network(
RuntimeOrigin::signed(owner_coldkey),
netuid
));
assert!(!SubtensorModule::if_subnet_exist(netuid))
});
}

#[test]
fn test_dissolve_network_refund_coldkey_ok() {
new_test_ext(1).execute_with(|| {
let netuid: u16 = 30;
let hotkey = U256::from(1);
let subnet_locked_balance = 1000;

add_network(netuid, 0, 0);
let owner_coldkey = SubtensorModule::get_subnet_owner(netuid);
register_ok_neuron(netuid, hotkey, owner_coldkey, 3);

SubtensorModule::set_subnet_locked_balance(netuid, subnet_locked_balance);
let coldkey_balance = SubtensorModule::get_coldkey_balance(&owner_coldkey);

assert!(SubtensorModule::if_subnet_exist(netuid));
assert_ok!(SubtensorModule::dissolve_network(
RuntimeOrigin::signed(owner_coldkey),
netuid
));
assert!(!SubtensorModule::if_subnet_exist(netuid));

let coldkey_new_balance = SubtensorModule::get_coldkey_balance(&owner_coldkey);

assert!(coldkey_new_balance > coldkey_balance);
assert_eq!(coldkey_new_balance, coldkey_balance + subnet_locked_balance);
});
}

#[test]
fn test_dissolve_network_not_owner_err() {
new_test_ext(1).execute_with(|| {
let netuid: u16 = 30;
let hotkey = U256::from(1);
let owner_coldkey = U256::from(2);
let random_coldkey = U256::from(3);

add_network(netuid, 0, 0);
register_ok_neuron(netuid, hotkey, owner_coldkey, 3);

assert_err!(
SubtensorModule::dissolve_network(RuntimeOrigin::signed(random_coldkey), netuid),
Error::<Test>::NotSubnetOwner
);
});
}

#[test]
fn test_dissolve_network_does_not_exist_err() {
new_test_ext(1).execute_with(|| {
let netuid: u16 = 30;
let coldkey = U256::from(2);

assert_err!(
SubtensorModule::dissolve_network(RuntimeOrigin::signed(coldkey), netuid),
Error::<Test>::NetworkDoesNotExist
);
});
}

0 comments on commit 397eb54

Please sign in to comment.