Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test dissolve_network #423

Merged
merged 2 commits into from
May 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
);
});
}
Loading