Skip to content

Commit 55b682f

Browse files
fix: update node (#443)
1 parent 6948075 commit 55b682f

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

substrate-node/pallets/pallet-tfgrid/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ pub mod pallet {
10481048
if old_node.farm_id != farm_id {
10491049
let mut old_nodes_by_farm = NodesByFarmID::<T>::get(old_node.farm_id);
10501050
old_nodes_by_farm.retain(|&id| id != node_id);
1051-
NodesByFarmID::<T>::insert(farm_id, old_nodes_by_farm);
1051+
NodesByFarmID::<T>::insert(old_node.farm_id, old_nodes_by_farm);
10521052

10531053
let mut nodes_by_farm = NodesByFarmID::<T>::get(farm_id);
10541054
nodes_by_farm.push(node_id);

substrate-node/pallets/pallet-tfgrid/src/tests.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,59 @@ fn create_node_added_to_farm_list_works() {
652652
});
653653
}
654654

655+
#[test]
656+
fn update_node_moved_from_farm_list_works() {
657+
ExternalityBuilder::build().execute_with(|| {
658+
create_entity();
659+
create_twin();
660+
create_farm();
661+
create_farm2();
662+
create_node();
663+
664+
let nodes = TfgridModule::nodes_by_farm_id(1);
665+
assert_eq!(nodes.len(), 1);
666+
assert_eq!(nodes[0], 1);
667+
668+
let country = "Belgium".as_bytes().to_vec();
669+
let city = "Ghent".as_bytes().to_vec();
670+
671+
// random location
672+
let location = Location {
673+
longitude: "12.233213231".as_bytes().to_vec(),
674+
latitude: "32.323112123".as_bytes().to_vec(),
675+
};
676+
677+
let resources = Resources {
678+
hru: 1024 * GIGABYTE,
679+
sru: 512 * GIGABYTE,
680+
cru: 8,
681+
mru: 16 * GIGABYTE,
682+
};
683+
assert_ok!(TfgridModule::update_node(
684+
Origin::signed(alice()),
685+
1,
686+
2,
687+
resources,
688+
location,
689+
country,
690+
city,
691+
Vec::new().try_into().unwrap(),
692+
true,
693+
true,
694+
"some_serial".as_bytes().to_vec(),
695+
));
696+
697+
// should be removed from farm 1 nodes
698+
let nodes = TfgridModule::nodes_by_farm_id(1);
699+
assert_eq!(nodes.len(), 0);
700+
701+
// Should be part of farm 2 nodes
702+
let nodes = TfgridModule::nodes_by_farm_id(2);
703+
assert_eq!(nodes.len(), 1);
704+
assert_eq!(nodes[0], 1);
705+
});
706+
}
707+
655708
#[test]
656709
fn create_node_with_interfaces_works() {
657710
ExternalityBuilder::build().execute_with(|| {
@@ -1889,6 +1942,25 @@ fn create_farm() {
18891942
create_farming_policies()
18901943
}
18911944

1945+
fn create_farm2() {
1946+
let farm_name = get_farm_name(b"test_farm2");
1947+
1948+
let mut pub_ips: PublicIpListInput<TestRuntime> = bounded_vec![];
1949+
1950+
let ip = get_public_ip_ip(&"185.206.122.33/24".as_bytes().to_vec()).0;
1951+
let gw = get_public_ip_gateway(&"185.206.122.1".as_bytes().to_vec()).0;
1952+
1953+
pub_ips.try_push(PublicIpInput { ip, gw }).unwrap();
1954+
1955+
assert_ok!(TfgridModule::create_farm(
1956+
Origin::signed(alice()),
1957+
farm_name.0.clone(),
1958+
pub_ips.clone()
1959+
));
1960+
1961+
create_farming_policies()
1962+
}
1963+
18921964
fn create_node() {
18931965
let country = "Belgium".as_bytes().to_vec();
18941966
let city = "Ghent".as_bytes().to_vec();

0 commit comments

Comments
 (0)