Skip to content

Commit

Permalink
test: ip validation in create_farm()
Browse files Browse the repository at this point in the history
  • Loading branch information
renauter committed Sep 26, 2023
1 parent b370a20 commit 4c29c6f
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion substrate-node/pallets/pallet-tfgrid/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ fn test_update_farm_name_existing_name_fails() {
}

#[test]
fn test_create_farm_with_double_ip_fails() {
fn test_create_farm_duplicate_ip_fails() {
ExternalityBuilder::build().execute_with(|| {
create_entity();
create_twin();
Expand All @@ -438,6 +438,26 @@ fn test_create_farm_with_double_ip_fails() {
});
}

#[test]
fn test_create_farm_not_valid_ip_fails() {
ExternalityBuilder::build().execute_with(|| {
create_entity();
create_twin();

let farm_name = get_farm_name_input(b"test_farm");

let mut pub_ips: PublicIpListInput<TestRuntime> = bounded_vec![];
let ip = get_public_ip_ip_input(b"185.206.122.33/24");
let gw = get_public_ip_gw_input(b"185.206.122.33");
pub_ips.try_push(IP4 { ip, gw }).unwrap();

assert_noop!(
TfgridModule::create_farm(RuntimeOrigin::signed(alice()), farm_name, pub_ips),
Error::<TestRuntime>::InvalidPublicIP
);
});
}

#[test]
fn test_adding_ip_to_farm_works() {
ExternalityBuilder::build().execute_with(|| {
Expand Down

0 comments on commit 4c29c6f

Please sign in to comment.