From 42b04881c28b652f50d351eb7eb7fb4f92c06988 Mon Sep 17 00:00:00 2001 From: Luke Schoen Date: Fri, 7 May 2021 11:49:31 +0200 Subject: [PATCH 1/3] wip --- .../tests/cli_integration_tests_roaming.rs | 142 ++++++++++++++++++ 1 file changed, 142 insertions(+) diff --git a/runtime/tests/cli_integration_tests_roaming.rs b/runtime/tests/cli_integration_tests_roaming.rs index 23e6d3718..061108e76 100644 --- a/runtime/tests/cli_integration_tests_roaming.rs +++ b/runtime/tests/cli_integration_tests_roaming.rs @@ -622,6 +622,148 @@ mod tests { device_profile_vendorid: b"1000".to_vec(), }) ); + + + assert_ok!(RoamingOperatorTestModule::create(Origin::signed(0))); // MXC + assert_ok!(RoamingNetworkTestModule::create(Origin::signed(0))); + assert_ok!(RoamingNetworkTestModule::is_roaming_network_owner(0, 0)); + // Assign each network to the MXC network operator, by the owner/creator of the MXC network operator + assert_ok!(RoamingNetworkTestModule::assign_network_to_operator(Origin::signed(0), 0, 0)); + assert_eq!(RoamingNetworkTestModule::roaming_network_owner(0), Some(0)); + assert_ok!(RoamingOrganizationTestModule::create(Origin::signed(0))); + assert_ok!(RoamingNetworkServerTestModule::create(Origin::signed(0))); // Supernode + + + // Call Functions + assert_ok!(RoamingNetworkProfileTestModule::create(Origin::signed(0))); + assert_eq!(RoamingNetworkProfileTestModule::roaming_network_profile_owner(0), Some(0)); + assert_ok!(RoamingNetworkProfileTestModule::assign_network_profile_to_network(Origin::signed(0), 0, 0)); + assert_ok!(RoamingNetworkProfileTestModule::assign_network_profile_to_operator(Origin::signed(0), 0, 0)); + assert_ok!(RoamingNetworkProfileTestModule::set_device_access_allowed(Origin::signed(0), 0, true)); + // Network Profile 0 - Whitelist MXC + assert_ok!(RoamingNetworkProfileTestModule::add_whitelisted_network( + Origin::signed(0), + 0, // network_profile_id + 0, // network_id + )); + // Create Gateway + assert_ok!(RoamingGatewayTestModule::create(Origin::signed(0))); + assert_ok!(RoamingGatewayTestModule::assign_gateway_to_organization(Origin::signed(0), 0, 0)); + assert_ok!(RoamingGatewayTestModule::assign_gateway_to_network_server(Origin::signed(0), 0, 0)); + assert_ok!(RoamingGatewayProfileTestModule::create(Origin::signed(0))); + assert_ok!(RoamingGatewayProfileTestModule::assign_gateway_profile_to_gateway(Origin::signed(0), 0, 0)); + assert_ok!(RoamingGatewayProfileTestModule::set_config( + Origin::signed(0), + 0, + Some(b"1234".to_vec()), // gateway_profile_mac + Some(b"1000".to_vec()), // gateway_profile_vendorid + )); + + // Create End Device + assert_ok!(RoamingDeviceTestModule::create(Origin::signed(0))); + assert_eq!(RoamingDeviceTestModule::roaming_device_owner(0), Some(0)); + assert_ok!(RoamingDeviceTestModule::assign_device_to_organization(Origin::signed(0), 0, 0)); + assert_ok!(RoamingDeviceTestModule::assign_device_to_network_server(Origin::signed(0), 0, 0)); + assert_ok!(RoamingDeviceProfileTestModule::create(Origin::signed(0))); + assert_ok!(RoamingDeviceProfileTestModule::assign_device_profile_to_device(Origin::signed(0), 0, 0)); + assert_ok!(RoamingDeviceProfileTestModule::set_config( + Origin::signed(0), + 0, + Some(b"1234".to_vec()), // device_profile_devaddr + Some(b"5678".to_vec()), // device_profile_deveui + Some(b"6789".to_vec()), // device_profile_joineui + Some(b"1000".to_vec()), // device_profile_vendorid + )); + + // Identity for accounts and their hardware devices + + let sudo = Origin::root(); + + let user_owner_account_1 = Origin::signed(1); + // Identity info of account_id 1 + let user_owner_account_1_info = Some(IdentityInfo { + email: b"luke@mxc.org".to_vec() + }); + + // Identity info of hardware device (end device 1) + let fetched_gateway_profile_setting = >::get(0); + let hardware_device_1 = Origin::signed(3); // M2 Pro + let hardware_device_1_roaming_data = ( + roaming_device_index: fetched_gateway_profile_setting.roaming_device_index, + roaming_device_profile_index: fetched_gateway_profile_setting.roaming_device_profile_index, + roaming_device_profile_devaddr: fetched_gateway_profile_setting.device_profile_devaddr, + roaming_device_profile_vendorid: fetched_gateway_profile_setting.device_profile_vendorid, + ); // Tuple + // TODO - how do we store this using Identity pallet, as it says that values greater than u32 + // such as account_id's that are u64 will be truncated but we want to associate the account_id + // https://github.com/paritytech/substrate/blob/master/frame/identity/src/lib.rs + let hardware_device_1_additional: Vec> = Vec::new(); + hardware_device_1_additional.push(hardware_device_1, hardware_device_1_roaming_data); + // Reference: https://github.com/paritytech/substrate/blob/master/frame/identity/src/lib.rs#L255 + let hardware_device_1_info = Some(IdentityInfo { + additional: hardware_device_1_additional + }); + + // Identity info of hardware gateway (gateway 1) + let fetched_gateway_profile_setting = >::get(0); + let hardware_gateway_1 = Origin::signed(4); // Gateway + // https://dev.datahighway.com/docs/en/whitepaper#gateway-setup--staking + let hardware_gateway_1_roaming_data = ( + supernode_home_account_id: >::get(0), + gateway_id_mac: fetched_gateway_profile_setting.gateway_profile_mac.unwrap(), + gateway_profile_vendorid: fetched_gateway_profile_setting.gateway_profile_vendorid.unwrap(), + ); // Tuple + // TODO - how do we store this using Identity pallet, as it says that values greater than u32 + // such as account_id's that are u64 will be truncated but we want to associate the account_id + // https://github.com/paritytech/substrate/blob/master/frame/identity/src/lib.rs + let hardware_gateway_1_additional: Vec> = Vec::new(); + hardware_gateway_1_additional.push(hardware_gateway_1, hardware_gateway_1_roaming_data); + // Reference: https://github.com/paritytech/substrate/blob/master/frame/identity/src/lib.rs#L255 + let hardware_gateway_1_info = Some(IdentityInfo { + additional: hardware_gateway_1_additional + }); + + let registrar_1 = Origin::signed(2); + let reg_index_1 = 0u64; // Registrar Index + + let user_owner_account_2 = Origin::signed(5); + // Identity info of account_id 2 + let user_owner_account_2_info = Some(IdentityInfo { + email: b"test@mxc.org".to_vec() + }); + // Set an account balance to each account for transaction fees + assert_ok!(Balances::set_balance(Origin::root(), 1, 1_000, 0)); + assert_ok!(Balances::set_balance(Origin::root(), 2, 1_000, 0)); + assert_ok!(Balances::set_balance(Origin::root(), 3, 1_000, 0)); + assert_ok!(Balances::set_balance(Origin::root(), 4, 1_000, 0)); + assert_ok!(Balances::set_balance(Origin::root(), 5, 1_000, 0)); + + assert_eq!(Identity::add_registrar(sudo.clone(), registrar_1.clone()), reg_index_1); // Sudo required + let registrar_judgement_fee = 100u32; + assert_ok!(Identity::set_fee(sudo.clone(), reg_index_1, registrar_judgement_fee.clone())); // Sudo required + assert_ok!(Identity::set_fields(sudo.clone(), reg_index_1, registrar_1.clone(), IdentityFields::Email)); // Sudo required + assert_ok!(Identity::set_identity(registrar_1, user_owner_account_1_info)); // Set by registrar + assert_ok!(Identity::set_identity(registrar_1, hardware_device_1_info)); // Set by registrar + assert_ok!(Identity::set_identity(registrar_1, hardware_gateway_1_info)); // Set by registrar + let sub_accounts_1 = Vec::new(); + sub_accounts_1.push( + (hardware_device_1, hardware_device_1_info), + (hardware_gateway_1, hardware_gateway_1_info), + ); + // Identity is assigned to user wallet upon gw registration + assert_ok!(Identity::set_subs(user_owner_account_1, sub_accounts_1); + assert_ok!(Identity::add_subs(user_owner_account_1, user_owner_account_2, user_owner_account_2_info); + let max_fee = 1u32; + // Request judgement of user wallet identity by the registrar + // to confirm that their sub-identities (end device and gateway) do infact belong to the user + assert_ok!(Identity::request_judgement(user_owner_account_1, reg_index_1, max_fee)); + assert_ok!(Identity::provide_judgement(registrar_1, reg_index_1, user_owner_account_1, registrar_judgement_fee.clone())); + + // TODO - transfer ownership of M2 Pro and Gateway to a different user + + // TODO - use Proxy to allow another user to make calls on behalf of an identity + + // assert_ok!(Proxy::add_proxy(sudo.clone(), 3, ProxyType::Any, 1)); }); } } From 5bf52c28f46670ebdbae994c468e6d041fc5cfea Mon Sep 17 00:00:00 2001 From: Luke Schoen Date: Mon, 10 May 2021 23:15:19 +0200 Subject: [PATCH 2/3] wip: update spec --- .../tests/cli_integration_tests_roaming.rs | 302 +++++++++++------- 1 file changed, 181 insertions(+), 121 deletions(-) diff --git a/runtime/tests/cli_integration_tests_roaming.rs b/runtime/tests/cli_integration_tests_roaming.rs index 061108e76..b7a8b531f 100644 --- a/runtime/tests/cli_integration_tests_roaming.rs +++ b/runtime/tests/cli_integration_tests_roaming.rs @@ -623,146 +623,206 @@ mod tests { }) ); + // MMD-1022 - Spec for how M2 Pro will interact on blockchain - assert_ok!(RoamingOperatorTestModule::create(Origin::signed(0))); // MXC - assert_ok!(RoamingNetworkTestModule::create(Origin::signed(0))); - assert_ok!(RoamingNetworkTestModule::is_roaming_network_owner(0, 0)); - // Assign each network to the MXC network operator, by the owner/creator of the MXC network operator - assert_ok!(RoamingNetworkTestModule::assign_network_to_operator(Origin::signed(0), 0, 0)); - assert_eq!(RoamingNetworkTestModule::roaming_network_owner(0), Some(0)); - assert_ok!(RoamingOrganizationTestModule::create(Origin::signed(0))); - assert_ok!(RoamingNetworkServerTestModule::create(Origin::signed(0))); // Supernode - - - // Call Functions - assert_ok!(RoamingNetworkProfileTestModule::create(Origin::signed(0))); - assert_eq!(RoamingNetworkProfileTestModule::roaming_network_profile_owner(0), Some(0)); - assert_ok!(RoamingNetworkProfileTestModule::assign_network_profile_to_network(Origin::signed(0), 0, 0)); - assert_ok!(RoamingNetworkProfileTestModule::assign_network_profile_to_operator(Origin::signed(0), 0, 0)); - assert_ok!(RoamingNetworkProfileTestModule::set_device_access_allowed(Origin::signed(0), 0, true)); - // Network Profile 0 - Whitelist MXC - assert_ok!(RoamingNetworkProfileTestModule::add_whitelisted_network( - Origin::signed(0), - 0, // network_profile_id - 0, // network_id - )); - // Create Gateway - assert_ok!(RoamingGatewayTestModule::create(Origin::signed(0))); - assert_ok!(RoamingGatewayTestModule::assign_gateway_to_organization(Origin::signed(0), 0, 0)); - assert_ok!(RoamingGatewayTestModule::assign_gateway_to_network_server(Origin::signed(0), 0, 0)); - assert_ok!(RoamingGatewayProfileTestModule::create(Origin::signed(0))); - assert_ok!(RoamingGatewayProfileTestModule::assign_gateway_profile_to_gateway(Origin::signed(0), 0, 0)); - assert_ok!(RoamingGatewayProfileTestModule::set_config( - Origin::signed(0), - 0, - Some(b"1234".to_vec()), // gateway_profile_mac - Some(b"1000".to_vec()), // gateway_profile_vendorid - )); - - // Create End Device - assert_ok!(RoamingDeviceTestModule::create(Origin::signed(0))); - assert_eq!(RoamingDeviceTestModule::roaming_device_owner(0), Some(0)); - assert_ok!(RoamingDeviceTestModule::assign_device_to_organization(Origin::signed(0), 0, 0)); - assert_ok!(RoamingDeviceTestModule::assign_device_to_network_server(Origin::signed(0), 0, 0)); - assert_ok!(RoamingDeviceProfileTestModule::create(Origin::signed(0))); - assert_ok!(RoamingDeviceProfileTestModule::assign_device_profile_to_device(Origin::signed(0), 0, 0)); - assert_ok!(RoamingDeviceProfileTestModule::set_config( - Origin::signed(0), - 0, - Some(b"1234".to_vec()), // device_profile_devaddr - Some(b"5678".to_vec()), // device_profile_deveui - Some(b"6789".to_vec()), // device_profile_joineui - Some(b"1000".to_vec()), // device_profile_vendorid - )); + // Set an account balance to each account for transaction fees + assert_ok!(Balances::set_balance(Origin::root(), 1, 1_000, 0)); + assert_ok!(Balances::set_balance(Origin::root(), 2, 1_000, 0)); + assert_ok!(Balances::set_balance(Origin::root(), 3, 1_000, 0)); + assert_ok!(Balances::set_balance(Origin::root(), 4, 1_000, 0)); + assert_ok!(Balances::set_balance(Origin::root(), 5, 1_000, 0)); + assert_ok!(Balances::set_balance(Origin::root(), 6, 1_000, 0)); + assert_ok!(Balances::set_balance(Origin::root(), 7, 1_000, 0)); + assert_ok!(Balances::set_balance(Origin::root(), 8, 1_000, 0)); + assert_ok!(Balances::set_balance(Origin::root(), 9, 1_000, 0)); + assert_ok!(Balances::set_balance(Origin::root(), 10, 1_000, 0)); + assert_ok!(Balances::set_balance(Origin::root(), 11, 1_000, 0)); + assert_ok!(Balances::set_balance(Origin::root(), 12, 1_000, 0)); // Identity for accounts and their hardware devices let sudo = Origin::root(); + let mxc_account_0_id = 0; + let mxc_account_signed = Origin::signed(mxc_account_0_id); - let user_owner_account_1 = Origin::signed(1); + let user_account_1_id = 1; + let user_account_1_signed = Origin::signed(user_account_1_id); // Identity info of account_id 1 - let user_owner_account_1_info = Some(IdentityInfo { + let user_account_1_info = Some(IdentityInfo { email: b"luke@mxc.org".to_vec() }); + assert_ok!(Identity::set_identity(registrar, user_account_1_info)); // Set by registrar - // Identity info of hardware device (end device 1) - let fetched_gateway_profile_setting = >::get(0); - let hardware_device_1 = Origin::signed(3); // M2 Pro - let hardware_device_1_roaming_data = ( - roaming_device_index: fetched_gateway_profile_setting.roaming_device_index, - roaming_device_profile_index: fetched_gateway_profile_setting.roaming_device_profile_index, - roaming_device_profile_devaddr: fetched_gateway_profile_setting.device_profile_devaddr, - roaming_device_profile_vendorid: fetched_gateway_profile_setting.device_profile_vendorid, - ); // Tuple - // TODO - how do we store this using Identity pallet, as it says that values greater than u32 - // such as account_id's that are u64 will be truncated but we want to associate the account_id - // https://github.com/paritytech/substrate/blob/master/frame/identity/src/lib.rs - let hardware_device_1_additional: Vec> = Vec::new(); - hardware_device_1_additional.push(hardware_device_1, hardware_device_1_roaming_data); - // Reference: https://github.com/paritytech/substrate/blob/master/frame/identity/src/lib.rs#L255 - let hardware_device_1_info = Some(IdentityInfo { - additional: hardware_device_1_additional - }); - - // Identity info of hardware gateway (gateway 1) - let fetched_gateway_profile_setting = >::get(0); - let hardware_gateway_1 = Origin::signed(4); // Gateway - // https://dev.datahighway.com/docs/en/whitepaper#gateway-setup--staking - let hardware_gateway_1_roaming_data = ( - supernode_home_account_id: >::get(0), - gateway_id_mac: fetched_gateway_profile_setting.gateway_profile_mac.unwrap(), - gateway_profile_vendorid: fetched_gateway_profile_setting.gateway_profile_vendorid.unwrap(), - ); // Tuple - // TODO - how do we store this using Identity pallet, as it says that values greater than u32 - // such as account_id's that are u64 will be truncated but we want to associate the account_id - // https://github.com/paritytech/substrate/blob/master/frame/identity/src/lib.rs - let hardware_gateway_1_additional: Vec> = Vec::new(); - hardware_gateway_1_additional.push(hardware_gateway_1, hardware_gateway_1_roaming_data); - // Reference: https://github.com/paritytech/substrate/blob/master/frame/identity/src/lib.rs#L255 - let hardware_gateway_1_info = Some(IdentityInfo { - additional: hardware_gateway_1_additional - }); - - let registrar_1 = Origin::signed(2); - let reg_index_1 = 0u64; // Registrar Index - - let user_owner_account_2 = Origin::signed(5); + let user_account_2_id = 12; + let user_account_2_signed = Origin::signed(user_account_2_id); // Identity info of account_id 2 - let user_owner_account_2_info = Some(IdentityInfo { + let user_account_2_info = Some(IdentityInfo { email: b"test@mxc.org".to_vec() }); - // Set an account balance to each account for transaction fees - assert_ok!(Balances::set_balance(Origin::root(), 1, 1_000, 0)); - assert_ok!(Balances::set_balance(Origin::root(), 2, 1_000, 0)); - assert_ok!(Balances::set_balance(Origin::root(), 3, 1_000, 0)); - assert_ok!(Balances::set_balance(Origin::root(), 4, 1_000, 0)); - assert_ok!(Balances::set_balance(Origin::root(), 5, 1_000, 0)); + assert_ok!(Identity::set_identity(registrar, user_account_2_info)); // Set by registrar + // assert_ok!(Identity::add_subs(user_account_1_signed, user_account_2_signed, user_account_2_info); - assert_eq!(Identity::add_registrar(sudo.clone(), registrar_1.clone()), reg_index_1); // Sudo required + // Registrar needs to already exist before `register_gateway` or `register_device` is called + let registrar_account_id = 11; + let registrar = Origin::signed(registrar_account_id); + let registrar_index = 0u64; // Registrar Index + + assert_eq!(Identity::add_registrar(sudo.clone(), registrar.clone()), registrar_index); // Sudo required let registrar_judgement_fee = 100u32; - assert_ok!(Identity::set_fee(sudo.clone(), reg_index_1, registrar_judgement_fee.clone())); // Sudo required - assert_ok!(Identity::set_fields(sudo.clone(), reg_index_1, registrar_1.clone(), IdentityFields::Email)); // Sudo required - assert_ok!(Identity::set_identity(registrar_1, user_owner_account_1_info)); // Set by registrar - assert_ok!(Identity::set_identity(registrar_1, hardware_device_1_info)); // Set by registrar - assert_ok!(Identity::set_identity(registrar_1, hardware_gateway_1_info)); // Set by registrar - let sub_accounts_1 = Vec::new(); - sub_accounts_1.push( - (hardware_device_1, hardware_device_1_info), - (hardware_gateway_1, hardware_gateway_1_info), - ); - // Identity is assigned to user wallet upon gw registration - assert_ok!(Identity::set_subs(user_owner_account_1, sub_accounts_1); - assert_ok!(Identity::add_subs(user_owner_account_1, user_owner_account_2, user_owner_account_2_info); + assert_ok!(Identity::set_fee(sudo.clone(), registrar_index, registrar_judgement_fee.clone())); // Sudo required + assert_ok!(Identity::set_fields(sudo.clone(), registrar_index, registrar.clone(), IdentityFields::Email)); // Sudo required let max_fee = 1u32; - // Request judgement of user wallet identity by the registrar - // to confirm that their sub-identities (end device and gateway) do infact belong to the user - assert_ok!(Identity::request_judgement(user_owner_account_1, reg_index_1, max_fee)); - assert_ok!(Identity::provide_judgement(registrar_1, reg_index_1, user_owner_account_1, registrar_judgement_fee.clone())); - // TODO - transfer ownership of M2 Pro and Gateway to a different user + // TODO - the below `create` needs to create an account id for the object (i.e. operator_account_id) + assert_ok!(RoamingOperatorTestModule::create(mxc_account_signed)); + let mxc_roaming_operator_id = 2; // Hard-coded. Generated by above line + // TODO - the below `create` needs to create an account id for the object (i.e. network_account_id) + assert_ok!(RoamingNetworkTestModule::create(mxc_account_signed)); + let mxc_roaming_network_id = 3; // Hard-coded. Generated by above line + assert_ok!(RoamingNetworkTestModule::is_roaming_network_owner(mxc_roaming_network_id, mxc_account_0_id)); + // Assign each network to the MXC network operator, by the owner/creator of the MXC network operator + assert_ok!(RoamingNetworkTestModule::assign_network_to_operator(mxc_account_signed, mxc_roaming_network_id, mxc_roaming_operator_id)); + assert_eq!(RoamingNetworkTestModule::roaming_network_owner(mxc_account_0_id), Some(mxc_roaming_network_id)); + // TODO - the below `create` needs to create an account id for the object (i.e. network_server_account_id) + assert_ok!(RoamingNetworkServerTestModule::create(mxc_account_signed)); // Supernode + let mxc_network_server_id = 4; // Hard-coded. Generated by above line - // TODO - use Proxy to allow another user to make calls on behalf of an identity + // Call Functions + assert_ok!(RoamingNetworkProfileTestModule::create(mxc_account_signed)); + let mxc_roaming_network_profile_id = 5; // Hard-coded. Generated by above line + assert_eq!(RoamingNetworkProfileTestModule::roaming_network_profile_owner(mxc_roaming_network_profile_id), Some(mxc_roaming_network_id)); + assert_ok!(RoamingNetworkProfileTestModule::assign_network_profile_to_network(mxc_account_signed, mxc_roaming_network_profile_id, mxc_roaming_network_id)); + assert_ok!(RoamingNetworkProfileTestModule::assign_network_profile_to_operator(mxc_account_signed, mxc_roaming_network_profile_id, mxc_roaming_operator_id)); + assert_ok!(RoamingNetworkProfileTestModule::set_device_access_allowed(mxc_account_signed, mxc_roaming_network_profile_id, true)); + // Network Profile 0 - Whitelist MXC + assert_ok!(RoamingNetworkProfileTestModule::add_whitelisted_network( + mxc_account_signed, + mxc_roaming_network_profile_id, // network_profile_id + mxc_roaming_network_id, // network_id + )); + // Identity is assigned to user wallet upon gateway registration + // ** Gateway calls this extrinsic function ** + assert_ok!(RoamingGatewayTestModule::register_gateway(user_account_1_signed)); + // ** Important note: Behind the scenes, the above function should do all the following internally + // so we need to provide `register_gateway` with sufficient arguments + // TODO - the below `create` needs to create an account id for the object (i.e. user_organization_account_id) + assert_ok!(RoamingOrganizationTestModule::create(user_account_1_signed)); + let user_organization_id = 6; // Hard-coded. Generated by above line + // TODO - add this extrinsic function `assign_user_to_organization` + assert_ok!(RoamingGatewayTestModule::assign_user_to_organization(user_account_1_signed, user_account_1_id, user_organization_id)); + // TODO - add this roaming gateway pallet + // Create Gateway + // TODO - the below `create` needs to create an account id for the object (i.e. gateway_account_id) + assert_ok!(RoamingGatewayTestModule::create(user_account_1_signed)); + // M2 Pro + let gateway_account_id = 7; // Hard-coded. Generated by above line + let gateway_account_signed = Origin::signed(gateway_account_id); + assert_eq!(RoamingGatewayTestModule::roaming_gateway_owner(gateway_account_id), Some(7)); + assert_ok!(RoamingGatewayTestModule::assign_gateway_to_organization(user_account_1_signed, gateway_account_id, user_organization_id)); + assert_ok!(RoamingGatewayTestModule::assign_gateway_to_network_server(mxc_account_signed, gateway_account_id, mxc_network_server_id)); + assert_ok!(RoamingGatewayProfileTestModule::create(user_account_1_signed)); + let gateway_profile_id = 8; // Hard-coded. Generated by above line + assert_ok!(RoamingGatewayProfileTestModule::assign_gateway_profile_to_gateway(user_account_1_signed, gateway_profile_id, gateway_account_id)); + assert_ok!(RoamingGatewayProfileTestModule::set_config( + user_account_1_signed, + gateway_profile_id, + Some(b"1234".to_vec()), // gateway_profile_mac + Some(b"1000".to_vec()), // gateway_profile_vendorid + )); + let gateway_profile_settings_0_id = 0; // Hard-coded. Generated by above line + + // Identity info of hardware gateway (gateway) + let fetched_gateway_profile_setting = >::get(gateway_profile_settings_0_id); + // https://dev.datahighway.com/docs/en/whitepaper#gateway-setup--staking + let gateway_account_roaming_data = ( + supernode_home_account_id: >::get(0), + gateway_id_mac: fetched_gateway_profile_setting.gateway_profile_mac.unwrap(), + gateway_profile_vendorid: fetched_gateway_profile_setting.gateway_profile_vendorid.unwrap(), + ); // Tuple + // TODO - how do we store this using Identity pallet, as it says that values greater than u32 + // such as account_id's that are u64 will be truncated but we want to associate the account_id + // https://github.com/paritytech/substrate/blob/master/frame/identity/src/lib.rs + let gateway_account_additional: Vec> = Vec::new(); + gateway_account_additional.push(gateway_account, gateway_account_roaming_data); + // Reference: https://github.com/paritytech/substrate/blob/master/frame/identity/src/lib.rs#L255 + let gateway_account_info = Some(IdentityInfo { + additional: gateway_account_additional + }); + assert_ok!(Identity::set_identity(registrar, gateway_account_info)); // Set by registrar + // Identity is assigned to user wallet upon device registration + assert_ok!(Identity::add_subs(user_account_1_signed, gateway_account, gateway_account_info); + // Request judgement of user wallet identity by the registrar + // to confirm that their sub-identities (end device and gateway) do infact belong to the user + assert_ok!(Identity::request_judgement(user_account_1_signed, registrar_index, max_fee)); + assert_ok!(Identity::provide_judgement(registrar, registrar_index, user_account_1_signed, registrar_judgement_fee.clone())); + + // Identity is assigned to user wallet upon device registration + // ** Device calls this extrinsic function ** + assert_ok!(RoamingDeviceTestModule::register_device(user_account_1_signed)); + // Create End Device + // TODO - the below `create` needs to create an account id for the object (i.e. device_account_id) + assert_ok!(RoamingDeviceTestModule::create(user_account_1_signed)); + let device_account_id = 9; // Hard-coded. Generated by above line + let device_account_signed = Origin::signed(device_account_id); + assert_eq!(RoamingDeviceTestModule::roaming_device_owner(device_account_id), Some(9)); + assert_ok!(RoamingDeviceTestModule::assign_device_to_organization(user_account_1_signed, device_account_id, user_organization_id)); + assert_ok!(RoamingDeviceTestModule::assign_device_to_network_server(mxc_account_signed, device_account_id, mxc_network_server_id)); + // Note: We could create the RoamingDeviceProfile using the signed RoamingDevice account instead of the user + // to simplify the associations, but for now we will leave it this way for now and call `assign_..` to make the assocations instead. + assert_ok!(RoamingDeviceProfileTestModule::create(user_account_1_signed)); + let device_profile_id = 10; // Hard-coded. Generated by above line + assert_ok!(RoamingDeviceProfileTestModule::assign_device_profile_to_device(user_account_1_signed, device_profile_id, device_account_id)); + assert_ok!(RoamingDeviceProfileTestModule::set_config( + user_account_1_signed, + device_profile_id, + Some(b"1234".to_vec()), // device_profile_devaddr + Some(b"5678".to_vec()), // device_profile_deveui + Some(b"6789".to_vec()), // device_profile_joineui + Some(b"1000".to_vec()), // device_profile_vendorid + )); + let device_profile_settings_0_id = 0; // Hard-coded. Generated by above line + + // Identity info of hardware device (end device) + let fetched_device_profile_setting = >::get(device_profile_settings_0_id); + let device_account_roaming_data = ( + roaming_device_index: fetched_device_profile_setting.roaming_device_index, + roaming_device_profile_index: fetched_device_profile_setting.roaming_device_profile_index, + roaming_device_profile_devaddr: fetched_device_profile_setting.device_profile_devaddr, + roaming_device_profile_vendorid: fetched_device_profile_setting.device_profile_vendorid, + ); // Tuple + // TODO - how do we store this using Identity pallet, as it says that values greater than u32 + // such as account_id's that are u64 will be truncated but we want to associate the account_id + // https://github.com/paritytech/substrate/blob/master/frame/identity/src/lib.rs + let device_account_additional: Vec> = Vec::new(); + device_account_additional.push(device_account_signed, device_account_roaming_data); + // Reference: https://github.com/paritytech/substrate/blob/master/frame/identity/src/lib.rs#L255 + let device_account_info = Some(IdentityInfo { + additional: device_account_additional + }); + assert_ok!(Identity::set_identity(registrar, device_account_info)); // Set by registrar + + // Identity is assigned to user wallet upon gateway registration + assert_ok!(Identity::add_subs(user_account_1_signed, device_account_signed, device_account_info); + // Request judgement of user wallet identity by the registrar + // to confirm that their sub-identities (end device and gateway) do infact belong to the user + assert_ok!(Identity::request_judgement(user_account_1_signed, registrar_index, max_fee)); + assert_ok!(Identity::provide_judgement(registrar, registrar_index, user_account_1_signed, registrar_judgement_fee.clone())); + + + // Transfer identity ownership of M2 Pro Gateway to a different user + // ** Gateway calls this extrinsic function ** + // TODO - the below `transfer_gateway_owner` extrinsic needs to be added + assert_ok!(RoamingGatewayTestModule::transfer_gateway_owner(user_account_1_signed, gateway_account_id, user_account_2_id)); + assert_eq!(RoamingGatewayTestModule::roaming_gateway_owner(gateway_account_id), Some(user_account_2_id)); + + // Transfer identity ownership of end device to a different user + // ** Device calls this extrinsic function ** + // TODO - the below `transfer_device_owner` extrinsic needs to be added + assert_ok!(RoamingDeviceTestModule::transfer_device_owner(user_account_1_signed, device_account_id, user_account_2_id)); + assert_eq!(RoamingDeviceTestModule::roaming_device_owner(device_account_id), Some(user_account_2_id)); + + // TODO - use Proxy to allow another user to make calls on behalf of an identity // assert_ok!(Proxy::add_proxy(sudo.clone(), 3, ProxyType::Any, 1)); }); } From 003a96a3a8e906da88f13a596d0fcc6d7e3c7131 Mon Sep 17 00:00:00 2001 From: Luke Schoen Date: Tue, 11 May 2021 12:52:36 +0200 Subject: [PATCH 3/3] tweaks and fix extrinsic function name --- runtime/tests/cli_integration_tests_roaming.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/runtime/tests/cli_integration_tests_roaming.rs b/runtime/tests/cli_integration_tests_roaming.rs index b7a8b531f..dd5123d50 100644 --- a/runtime/tests/cli_integration_tests_roaming.rs +++ b/runtime/tests/cli_integration_tests_roaming.rs @@ -660,7 +660,7 @@ mod tests { email: b"test@mxc.org".to_vec() }); assert_ok!(Identity::set_identity(registrar, user_account_2_info)); // Set by registrar - // assert_ok!(Identity::add_subs(user_account_1_signed, user_account_2_signed, user_account_2_info); + // assert_ok!(Identity::add_sub(user_account_1_signed, user_account_2_id, user_account_2_info); // Registrar needs to already exist before `register_gateway` or `register_device` is called let registrar_account_id = 11; @@ -744,14 +744,14 @@ mod tests { // such as account_id's that are u64 will be truncated but we want to associate the account_id // https://github.com/paritytech/substrate/blob/master/frame/identity/src/lib.rs let gateway_account_additional: Vec> = Vec::new(); - gateway_account_additional.push(gateway_account, gateway_account_roaming_data); + gateway_account_additional.push(gateway_account_id, gateway_account_roaming_data); // Reference: https://github.com/paritytech/substrate/blob/master/frame/identity/src/lib.rs#L255 let gateway_account_info = Some(IdentityInfo { additional: gateway_account_additional }); assert_ok!(Identity::set_identity(registrar, gateway_account_info)); // Set by registrar // Identity is assigned to user wallet upon device registration - assert_ok!(Identity::add_subs(user_account_1_signed, gateway_account, gateway_account_info); + assert_ok!(Identity::add_sub(user_account_1_signed, gateway_account_id, gateway_account_info); // Request judgement of user wallet identity by the registrar // to confirm that their sub-identities (end device and gateway) do infact belong to the user assert_ok!(Identity::request_judgement(user_account_1_signed, registrar_index, max_fee)); @@ -803,7 +803,7 @@ mod tests { assert_ok!(Identity::set_identity(registrar, device_account_info)); // Set by registrar // Identity is assigned to user wallet upon gateway registration - assert_ok!(Identity::add_subs(user_account_1_signed, device_account_signed, device_account_info); + assert_ok!(Identity::add_sub(user_account_1_signed, device_account_id, device_account_info); // Request judgement of user wallet identity by the registrar // to confirm that their sub-identities (end device and gateway) do infact belong to the user assert_ok!(Identity::request_judgement(user_account_1_signed, registrar_index, max_fee)); @@ -815,12 +815,18 @@ mod tests { // TODO - the below `transfer_gateway_owner` extrinsic needs to be added assert_ok!(RoamingGatewayTestModule::transfer_gateway_owner(user_account_1_signed, gateway_account_id, user_account_2_id)); assert_eq!(RoamingGatewayTestModule::roaming_gateway_owner(gateway_account_id), Some(user_account_2_id)); + // Note: If a user sells hardware, we need them to remove the hardware from being one of their sub-identities + assert_ok!(Identity::remove_sub(user_account_1_signed, gateway_account_id); + assert_ok!(Identity::add_sub(user_account_2_id, gateway_account_id, gateway_account_info); // Transfer identity ownership of end device to a different user // ** Device calls this extrinsic function ** // TODO - the below `transfer_device_owner` extrinsic needs to be added assert_ok!(RoamingDeviceTestModule::transfer_device_owner(user_account_1_signed, device_account_id, user_account_2_id)); assert_eq!(RoamingDeviceTestModule::roaming_device_owner(device_account_id), Some(user_account_2_id)); + // Note: If a user sells hardware, we need them to remove the hardware from being one of their sub-identities + assert_ok!(Identity::remove_sub(user_account_1_signed, device_account_id); + assert_ok!(Identity::add_sub(user_account_2_id, device_account_id, device_account_info); // TODO - use Proxy to allow another user to make calls on behalf of an identity // assert_ok!(Proxy::add_proxy(sudo.clone(), 3, ProxyType::Any, 1));