diff --git a/cli-tool/cmds/farm_cmds/delete.js b/cli-tool/cmds/farm_cmds/delete.js deleted file mode 100644 index 4c2f8436d..000000000 --- a/cli-tool/cmds/farm_cmds/delete.js +++ /dev/null @@ -1,8 +0,0 @@ -const { - deleteFarm -} = require('../../src/farms') - -exports.command = 'delete ' -exports.desc = 'Delete a farm by id' -exports.builder = {} -exports.handler = deleteFarm diff --git a/cli-tool/cmds/twin_cmds/delete.js b/cli-tool/cmds/twin_cmds/delete.js deleted file mode 100644 index c2648f943..000000000 --- a/cli-tool/cmds/twin_cmds/delete.js +++ /dev/null @@ -1,8 +0,0 @@ -const { - deleteTwin -} = require('../../src/twins') - -exports.command = 'delete ' -exports.desc = 'Delete a twin' -exports.builder = {} -exports.handler = deleteTwin diff --git a/cli-tool/src/farms.js b/cli-tool/src/farms.js index 79dfa3e48..1c3662043 100644 --- a/cli-tool/src/farms.js +++ b/cli-tool/src/farms.js @@ -1,7 +1,7 @@ const { getClient } = require('./client') const { callback } = require('./util') -async function createFarm (args) { +async function createFarm(args) { const { name, c: countryID, g: cityID, certificationType, a: url, m: mnemonic } = args const client = await getClient(url, mnemonic) @@ -17,7 +17,7 @@ async function createFarm (args) { return client.createFarm(name, certificationTypeParsed, countryID, cityID, [publicIP], callback) } -async function addPublicIP (args) { +async function addPublicIP(args) { const { id, ip, gateway, a: url, m: mnemonic } = args const client = await getClient(url, mnemonic) @@ -25,7 +25,7 @@ async function addPublicIP (args) { return client.addFarmIp(id, ip, gateway, callback) } -async function deletePublicIP (args) { +async function deletePublicIP(args) { const { id, ip, a: url, m: mnemonic } = args const client = await getClient(url, mnemonic) @@ -33,7 +33,7 @@ async function deletePublicIP (args) { return client.deleteFarmIp(id, ip, callback) } -async function getFarm (args) { +async function getFarm(args) { const { id, a: url } = args const client = await getClient(url, '') @@ -43,7 +43,7 @@ async function getFarm (args) { process.exit(0) } -async function listFarms (args) { +async function listFarms(args) { const { a: url } = args const client = await getClient(url, '') @@ -53,21 +53,10 @@ async function listFarms (args) { process.exit(0) } -async function deleteFarm (args) { - const { id, a: url, m: mnemonic } = args - const client = await getClient(url, mnemonic) - - await client.deleteFarmByID(id, callback) - - console.log('farm deleted') - process.exit(0) -} - module.exports = { createFarm, getFarm, listFarms, - deleteFarm, addPublicIP, deletePublicIP } diff --git a/cli-tool/src/twins.js b/cli-tool/src/twins.js index f32d1c485..04b2163a8 100644 --- a/cli-tool/src/twins.js +++ b/cli-tool/src/twins.js @@ -1,14 +1,14 @@ const { getClient } = require('./client') const { callback } = require('./util') -async function createTwin (args) { +async function createTwin(args) { const { ip, a: url, m: mnemonic } = args const client = await getClient(url, mnemonic) return client.createTwin(ip, callback) } -async function getTwin (args) { +async function getTwin(args) { const { a: url, id } = args const client = await getClient(url, '') @@ -18,7 +18,7 @@ async function getTwin (args) { process.exit(0) } -async function listTwins (args) { +async function listTwins(args) { const { a: url } = args const client = await getClient(url, '') @@ -28,24 +28,14 @@ async function listTwins (args) { process.exit(0) } -async function deleteTwin (args) { - const { id, a: url, m: mnemonic } = args - const client = await getClient(url, mnemonic) - - await client.deleteTwin(id, callback) - - console.log('twin deleted') - process.exit(0) -} - -async function createTwinEntity (twinID, entityID, signature, mnemonic, url, callback) { +async function createTwinEntity(twinID, entityID, signature, mnemonic, url, callback) { const client = await getClient(url, mnemonic) const create = await client.addTwinEntity(twinID, entityID, signature, callback) return create } -async function deleteTwinEntity (twinID, entityID, mnemonic, url, callback) { +async function deleteTwinEntity(twinID, entityID, mnemonic, url, callback) { const client = await getClient(url, mnemonic) const create = await client.removeTwinEntity(twinID, entityID, callback) @@ -56,7 +46,6 @@ module.exports = { createTwin, getTwin, listTwins, - deleteTwin, createTwinEntity, deleteTwinEntity } diff --git a/substrate-node/pallets/pallet-smart-contract/src/lib.rs b/substrate-node/pallets/pallet-smart-contract/src/lib.rs index ed1b5365d..17df950d0 100644 --- a/substrate-node/pallets/pallet-smart-contract/src/lib.rs +++ b/substrate-node/pallets/pallet-smart-contract/src/lib.rs @@ -459,17 +459,6 @@ pub mod pallet { Self::_cancel_contract(account_id, contract_id, types::Cause::CanceledByUser) } - // DEPRECATED - #[pallet::call_index(3)] - #[pallet::weight(10_000 + T::DbWeight::get().writes(1).ref_time())] - pub fn add_reports( - _origin: OriginFor, - _reports: Vec, - ) -> DispatchResultWithPostInfo { - // return error - Err(DispatchErrorWithPostInfo::from(Error::::MethodIsDeprecated).into()) - } - #[pallet::call_index(4)] #[pallet::weight(10_000 + T::DbWeight::get().writes(1).ref_time())] pub fn create_name_contract( diff --git a/substrate-node/pallets/pallet-smart-contract/src/tests.rs b/substrate-node/pallets/pallet-smart-contract/src/tests.rs index cfba1b161..8fb61a98c 100644 --- a/substrate-node/pallets/pallet-smart-contract/src/tests.rs +++ b/substrate-node/pallets/pallet-smart-contract/src/tests.rs @@ -1236,47 +1236,6 @@ fn test_node_contract_billing_cycles_cancel_contract_during_cycle_works() { }); } -#[test] -fn test_node_contract_billing_fails() { - let (mut ext, mut pool_state) = new_test_ext_with_pool_state(0); - ext.execute_with(|| { - run_to_block(1, Some(&mut pool_state)); - // Creates a farm and node and sets the price of tft to 0 which raises an error later - prepare_farm_and_node(); - - assert_ok!(SmartContractModule::create_node_contract( - RuntimeOrigin::signed(bob()), - 1, - generate_deployment_hash(), - get_deployment_data(), - 1, - None - )); - - let contracts_to_bill_at_block = SmartContractModule::contract_to_bill_at_block(1); - assert_eq!(contracts_to_bill_at_block.len(), 1); - - let contract_id = contracts_to_bill_at_block[0]; - - // delete twin to make the billing fail - assert_ok!(TfgridModule::delete_twin( - RuntimeOrigin::signed(bob()), - SmartContractModule::contracts(contract_id).unwrap().twin_id, - )); - - // the offchain worker should save the failed ids in local storage and try again - // in subsequent blocks (which will also fail) - for i in 1..3 { - pool_state.write().should_call_bill_contract( - 1, - Err(Error::::TwinNotExists.into()), - 1 + i * 10, - ); - run_to_block(11 * i, Some(&mut pool_state)); - } - }); -} - #[test] fn test_node_contract_billing_cycles_cancel_contract_during_cycle_without_balance_works() { let (mut ext, mut pool_state) = new_test_ext_with_pool_state(0); diff --git a/substrate-node/pallets/pallet-tfgrid/spec.md b/substrate-node/pallets/pallet-tfgrid/spec.md index cf98fd6d1..81368d0eb 100644 --- a/substrate-node/pallets/pallet-tfgrid/spec.md +++ b/substrate-node/pallets/pallet-tfgrid/spec.md @@ -185,7 +185,6 @@ Twins: - create_twin(..) - update_twin(..) -- delete_twin(..) Entity-Twin Relation: @@ -202,7 +201,6 @@ Farms: - createFarm(..) - updateFarm(..) -- deleteFarm(..) - addFarmIp(..) - removeFarmIp(..) diff --git a/substrate-node/pallets/pallet-tfgrid/src/lib.rs b/substrate-node/pallets/pallet-tfgrid/src/lib.rs index 2306e008f..b082b4fae 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/lib.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/lib.rs @@ -962,12 +962,6 @@ pub mod pallet { } } - #[pallet::call_index(7)] - #[pallet::weight(100_000_000 + T::DbWeight::get().writes(2).ref_time() + T::DbWeight::get().reads(2).ref_time())] - pub fn delete_farm(_origin: OriginFor, _id: u32) -> DispatchResultWithPostInfo { - Err(DispatchErrorWithPostInfo::from(Error::::MethodIsDeprecated).into()) - } - #[pallet::call_index(8)] #[pallet::weight(::WeightInfo::create_node())] pub fn create_node( @@ -1559,28 +1553,6 @@ pub mod pallet { Ok(().into()) } - #[pallet::call_index(21)] - #[pallet::weight(100_000_000 + T::DbWeight::get().writes(2).ref_time() + T::DbWeight::get().reads(1).ref_time())] - pub fn delete_twin(origin: OriginFor, twin_id: u32) -> DispatchResultWithPostInfo { - let account_id = ensure_signed(origin)?; - - let twin = Twins::::get(&twin_id).ok_or(Error::::TwinNotExists)?; - // Make sure only the owner of this twin can call this method - ensure!( - twin.account_id == account_id, - Error::::UnauthorizedToUpdateTwin - ); - - Twins::::remove(&twin_id); - - // remove twin id from this users map of twin ids - TwinIdByAccountID::::remove(&account_id.clone()); - - Self::deposit_event(Event::TwinDeleted(twin_id)); - - Ok(().into()) - } - #[pallet::call_index(22)] #[pallet::weight(100_000_000 + T::DbWeight::get().writes(3).ref_time() + T::DbWeight::get().reads(2).ref_time())] pub fn create_pricing_policy( @@ -2352,4 +2324,4 @@ impl tfchain_support::traits::Tfgrid for P None => false, } } -} \ No newline at end of file +} diff --git a/substrate-node/pallets/pallet-tfgrid/src/tests.rs b/substrate-node/pallets/pallet-tfgrid/src/tests.rs index 9bcea3a09..819b63276 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/tests.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/tests.rs @@ -153,29 +153,6 @@ fn test_create_twin_works() { }); } -#[test] -fn test_delete_twin_works() { - ExternalityBuilder::build().execute_with(|| { - assert_ok!(TfgridModule::user_accept_tc( - RuntimeOrigin::signed(alice()), - get_document_link_input(b"some_link"), - get_document_hash_input(b"some_hash"), - )); - - let ip = get_twin_ip_input(b"::1"); - assert_ok!(TfgridModule::create_twin( - RuntimeOrigin::signed(alice()), - ip - )); - - let twin_id = 1; - assert_ok!(TfgridModule::delete_twin( - RuntimeOrigin::signed(alice()), - twin_id - )); - }); -} - #[test] fn test_delete_node_works() { ExternalityBuilder::build().execute_with(|| { @@ -461,19 +438,6 @@ fn test_adding_misformatted_ip_to_farm_fails() { }); } -#[test] -fn test_delete_farm_fails() { - ExternalityBuilder::build().execute_with(|| { - create_entity(); - create_twin(); - create_farm(); - assert_noop!( - TfgridModule::delete_farm(RuntimeOrigin::signed(alice()), 1), - Error::::MethodIsDeprecated - ); - }); -} - #[test] fn test_adding_ip_duplicate_to_farm_fails() { ExternalityBuilder::build().execute_with(|| { diff --git a/substrate-node/tests/TfChainClient.py b/substrate-node/tests/TfChainClient.py index f382c35bf..a82a20a37 100644 --- a/substrate-node/tests/TfChainClient.py +++ b/substrate-node/tests/TfChainClient.py @@ -130,18 +130,6 @@ def update_twin(self, ip: str = "::1", port: int = DEFAULT_PORT, who: str = DEFA self._sign_extrinsic_submit_check_response( substrate, call, who, expected_events=expected_events) - def delete_twin(self, twin_id: int = 1, port: int = DEFAULT_PORT, who: str = DEFAULT_SIGNER): - substrate = self._connect_to_server(f"ws://127.0.0.1:{port}") - - call = substrate.compose_call("TfgridModule", "delete_twin", { - "twin_id": twin_id}) - expected_events = [{ - "module_id": "TfgridModule", - "event_id": "TwinDeleted" - }] - self._sign_extrinsic_submit_check_response( - substrate, call, who, expected_events=expected_events) - def get_twin(self, id: int = 1, port: int = DEFAULT_PORT): substrate = self._connect_to_server(f"ws://127.0.0.1:{port}") diff --git a/substrate-node/tests/integration_tests.robot b/substrate-node/tests/integration_tests.robot index 583844566..714d7b414 100644 --- a/substrate-node/tests/integration_tests.robot +++ b/substrate-node/tests/integration_tests.robot @@ -61,9 +61,9 @@ Test Start And Stop Network Tear Down Multi Node Network -Test Create Update Delete Twin - [Documentation] Testing api calls (create, update, delete) for managing twins - Setup Multi Node Network log_name=test_create_update_delete_twin +Test Create Update Twin + [Documentation] Testing api calls (create, update) for managing twins + Setup Multi Node Network log_name=test_create_update_twin User Accept Tc @@ -77,11 +77,6 @@ Test Create Update Delete Twin Should Not Be Equal ${twin} ${None} Should Be Equal ${twin}[ip] 0000:0000:0000:0000:0000:0000:0000:0001 - Delete Twin ${1} - - ${twin} = Get Twin ${1} - Should Be Equal ${twin} ${None} - Tear Down Multi Node Network Test Create Update Farm