From 4871beb80df7ea2a259e0d7ea1c7bc5d3a34470b Mon Sep 17 00:00:00 2001 From: Matias Bzurovski Date: Wed, 4 Sep 2024 15:40:40 +0200 Subject: [PATCH 1/3] Move ResourcePreferences under ProfileNetwork --- Cargo.lock | 2 +- crates/sargon/Cargo.toml | 2 +- .../profile_network_get_entities.rs | 2 + .../v100/app_preferences/app_preferences.rs | 38 +---------- .../src/profile/v100/app_preferences/mod.rs | 2 - .../src/profile/v100/networks/network/mod.rs | 2 + .../v100/networks/network/profile_network.rs | 67 ++++++++++++++++++- .../resource_preferences/hidden_resources.rs | 0 .../network}/resource_preferences/mod.rs | 0 .../resource_app_preference.rs | 44 ++++++++++-- .../resource_identifier.rs | 63 ++++++++++++++--- .../resource_preferences.rs | 18 +++-- .../resource_preferences_uniffi_fn.rs | 0 .../resource_visibility.rs | 0 .../profile/v100/networks/profile_networks.rs | 28 ++++++++ crates/sargon/src/profile/v100/profile.rs | 47 +++++++------ .../system/sargon_os/sargon_os_accounts.rs | 1 + .../src/system/sargon_os/sargon_os_profile.rs | 1 + 18 files changed, 235 insertions(+), 82 deletions(-) rename crates/sargon/src/profile/v100/{app_preferences => networks/network}/resource_preferences/hidden_resources.rs (100%) rename crates/sargon/src/profile/v100/{app_preferences => networks/network}/resource_preferences/mod.rs (100%) rename crates/sargon/src/profile/v100/{app_preferences => networks/network}/resource_preferences/resource_app_preference.rs (67%) rename crates/sargon/src/profile/v100/{app_preferences => networks/network}/resource_preferences/resource_identifier.rs (55%) rename crates/sargon/src/profile/v100/{app_preferences => networks/network}/resource_preferences/resource_preferences.rs (91%) rename crates/sargon/src/profile/v100/{app_preferences => networks/network}/resource_preferences/resource_preferences_uniffi_fn.rs (100%) rename crates/sargon/src/profile/v100/{app_preferences => networks/network}/resource_preferences/resource_visibility.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index b19bdd180..f37457b3e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2602,7 +2602,7 @@ dependencies = [ [[package]] name = "sargon" -version = "1.1.9" +version = "1.1.10" dependencies = [ "actix-rt", "aes-gcm", diff --git a/crates/sargon/Cargo.toml b/crates/sargon/Cargo.toml index e6a83c619..5aa24183a 100644 --- a/crates/sargon/Cargo.toml +++ b/crates/sargon/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sargon" -version = "1.1.9" +version = "1.1.10" edition = "2021" build = "build.rs" diff --git a/crates/sargon/src/profile/logic/profile_network/profile_network_get_entities.rs b/crates/sargon/src/profile/logic/profile_network/profile_network_get_entities.rs index 71b82a4a0..e3a4a5d9a 100644 --- a/crates/sargon/src/profile/logic/profile_network/profile_network_get_entities.rs +++ b/crates/sargon/src/profile/logic/profile_network/profile_network_get_entities.rs @@ -35,6 +35,7 @@ mod tests { accounts.clone().to_owned(), Personas::new(), AuthorizedDapps::new(), + ResourcePreferences::new(), ); assert_eq!( &profile_network.accounts_non_hidden().items(), @@ -60,6 +61,7 @@ mod tests { Accounts::new(), personas, AuthorizedDapps::new(), + ResourcePreferences::new(), ); assert_eq!( &sut.personas_non_hidden().items(), diff --git a/crates/sargon/src/profile/v100/app_preferences/app_preferences.rs b/crates/sargon/src/profile/v100/app_preferences/app_preferences.rs index d159aa645..72028af7c 100644 --- a/crates/sargon/src/profile/v100/app_preferences/app_preferences.rs +++ b/crates/sargon/src/profile/v100/app_preferences/app_preferences.rs @@ -31,10 +31,6 @@ pub struct AppPreferences { /// Default config related to making of transactions pub transaction: TransactionPreferences, - - /// Configuration related to resources - #[serde(default)] - pub resources: ResourcePreferences, } impl AppPreferences { @@ -45,13 +41,8 @@ impl AppPreferences { gateways: {} security: {} transaction: {} - resources: {:?} "#, - self.display, - self.gateways, - self.security, - self.transaction, - self.resources + self.display, self.gateways, self.security, self.transaction ) } } @@ -62,14 +53,12 @@ impl AppPreferences { gateways: SavedGateways, security: Security, transaction: TransactionPreferences, - resources: ResourcePreferences, ) -> Self { Self { display, gateways, security, transaction, - resources, } } } @@ -82,7 +71,6 @@ impl HasSampleValues for AppPreferences { SavedGateways::sample(), Security::sample(), TransactionPreferences::sample(), - ResourcePreferences::sample(), ) } @@ -93,7 +81,6 @@ impl HasSampleValues for AppPreferences { SavedGateways::sample_other(), Security::sample_other(), TransactionPreferences::sample_other(), - ResourcePreferences::sample_other(), ) } } @@ -142,11 +129,6 @@ mod tests { assert_eq!(SUT::sample().transaction, TransactionPreferences::sample()) } - #[test] - fn get_resources() { - assert_eq!(SUT::sample().resources, ResourcePreferences::sample()) - } - #[test] fn test_has_gateway_with_url() { let sut = SUT::sample(); @@ -203,23 +185,7 @@ mod tests { }, "transaction": { "defaultDepositGuarantee": "0.975" - }, - "resources": [ - { - "resource": { - "kind": "fungible", - "value": "resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd" - }, - "visibility": "hidden" - }, - { - "resource": { - "kind": "nonFungible", - "value": "resource_rdx1t4dy69k6s0gv040xa64cyadyefwtett62ng6xfdnljyydnml7t6g3j" - }, - "visibility": "visible" - } - ] + } } "#, ) diff --git a/crates/sargon/src/profile/v100/app_preferences/mod.rs b/crates/sargon/src/profile/v100/app_preferences/mod.rs index f2a3762f4..57b154baf 100644 --- a/crates/sargon/src/profile/v100/app_preferences/mod.rs +++ b/crates/sargon/src/profile/v100/app_preferences/mod.rs @@ -2,7 +2,6 @@ mod app_display_settings; mod app_preferences; mod app_preferences_uniffi_fn; mod gateways; -mod resource_preferences; mod security; mod transaction_preferences; @@ -10,6 +9,5 @@ pub use app_display_settings::*; pub use app_preferences::*; pub use app_preferences_uniffi_fn::*; pub use gateways::*; -pub use resource_preferences::*; pub use security::*; pub use transaction_preferences::*; diff --git a/crates/sargon/src/profile/v100/networks/network/mod.rs b/crates/sargon/src/profile/v100/networks/network/mod.rs index 3d6514a32..6a6a8f48e 100644 --- a/crates/sargon/src/profile/v100/networks/network/mod.rs +++ b/crates/sargon/src/profile/v100/networks/network/mod.rs @@ -6,6 +6,7 @@ mod network_id_uniffi_fn; mod personas; mod profile_network; mod profile_network_uniffi_fn; +mod resource_preferences; pub use accounts::*; pub use authorized_dapp::*; @@ -15,3 +16,4 @@ pub use network_id_uniffi_fn::*; pub use personas::*; pub use profile_network::*; pub use profile_network_uniffi_fn::*; +pub use resource_preferences::*; diff --git a/crates/sargon/src/profile/v100/networks/network/profile_network.rs b/crates/sargon/src/profile/v100/networks/network/profile_network.rs index ab917c15f..75e33fdec 100644 --- a/crates/sargon/src/profile/v100/networks/network/profile_network.rs +++ b/crates/sargon/src/profile/v100/networks/network/profile_network.rs @@ -33,6 +33,10 @@ pub struct ProfileNetwork { /// [`AuthorizedDapp`]s that the user has interacted with. #[serde(rename = "authorizedDapps")] pub authorized_dapps: AuthorizedDapps, + + /// Configuration related to resources + #[serde(default)] + pub resource_preferences: ResourcePreferences, } impl IsNetworkAware for ProfileNetwork { @@ -49,8 +53,13 @@ impl ProfileNetwork { accounts: {} personas: {} authorized_dapps: {} + resource_preferences: {:?} "#, - self.id, self.accounts, self.personas, self.authorized_dapps, + self.id, + self.accounts, + self.personas, + self.authorized_dapps, + self.resource_preferences ) } } @@ -76,11 +85,13 @@ impl ProfileNetwork { accounts: impl Into, personas: impl Into, authorized_dapps: impl Into, + resource_preferences: impl Into, ) -> Self { let network_id = network_id.into(); let accounts = accounts.into(); let personas = personas.into(); let authorized_dapps = authorized_dapps.into(); + let resource_preferences = resource_preferences.into(); assert!( accounts .get_all() @@ -102,11 +113,21 @@ impl ProfileNetwork { .all(|d| d.network_id == network_id), "Discrepancy, found an AuthorizedDapp on other network than {network_id}" ); + + assert!( + resource_preferences + .get_all() + .into_iter() + .all(|d| d.network_id() == network_id), + "Discrepancy, found a ResourceAppPreference on other network than {network_id}" + ); + Self { id: network_id, accounts, personas, authorized_dapps, + resource_preferences, } } @@ -118,6 +139,7 @@ impl ProfileNetwork { Accounts::new(), Personas::new(), AuthorizedDapps::new(), + ResourcePreferences::new(), ) } } @@ -160,6 +182,7 @@ impl ProfileNetwork { Accounts::sample_mainnet(), Personas::sample_mainnet(), AuthorizedDapps::sample_mainnet(), + ResourcePreferences::sample_mainnet(), ) } @@ -170,6 +193,7 @@ impl ProfileNetwork { Accounts::sample_stokenet(), Personas::sample_stokenet(), AuthorizedDapps::sample_stokenet(), + ResourcePreferences::sample_stokenet(), ) } } @@ -202,6 +226,14 @@ mod tests { assert_eq!(sut.accounts, Accounts::sample()); } + #[test] + fn get_resources() { + assert_eq!( + SUT::sample().resource_preferences, + ResourcePreferences::sample() + ) + } + #[test] fn duplicate_accounts_are_filtered_out() { assert_eq!( @@ -212,6 +244,7 @@ mod tests { ), Personas::default(), AuthorizedDapps::default(), + ResourcePreferences::default(), ) .accounts .len(), @@ -229,6 +262,7 @@ mod tests { Accounts::just(Account::sample_stokenet()), Personas::default(), AuthorizedDapps::default(), + ResourcePreferences::default(), ); } @@ -242,6 +276,7 @@ mod tests { Accounts::sample_mainnet(), Personas::just(Persona::sample_stokenet()), AuthorizedDapps::default(), + ResourcePreferences::default(), ); } @@ -255,6 +290,7 @@ mod tests { Accounts::sample_mainnet(), Personas::sample_mainnet(), AuthorizedDapps::just(AuthorizedDapp::sample_stokenet()), + ResourcePreferences::default(), ); } @@ -604,7 +640,23 @@ mod tests { } ] } - ] + ], + "resource_preferences": [ + { + "resource": { + "kind": "fungible", + "value": "resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd" + }, + "visibility": "hidden" + }, + { + "resource": { + "kind": "nonFungible", + "value": "resource_rdx1t4dy69k6s0gv040xa64cyadyefwtett62ng6xfdnljyydnml7t6g3j" + }, + "visibility": "visible" + } + ] } "#, ); @@ -950,7 +1002,16 @@ mod tests { } ] } - ] + ], + "resource_preferences": [ + { + "resource": { + "kind": "nonFungible", + "value": "resource_tdx_2_1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxtfd2jc" + }, + "visibility": "visible" + } + ] } "#, ) diff --git a/crates/sargon/src/profile/v100/app_preferences/resource_preferences/hidden_resources.rs b/crates/sargon/src/profile/v100/networks/network/resource_preferences/hidden_resources.rs similarity index 100% rename from crates/sargon/src/profile/v100/app_preferences/resource_preferences/hidden_resources.rs rename to crates/sargon/src/profile/v100/networks/network/resource_preferences/hidden_resources.rs diff --git a/crates/sargon/src/profile/v100/app_preferences/resource_preferences/mod.rs b/crates/sargon/src/profile/v100/networks/network/resource_preferences/mod.rs similarity index 100% rename from crates/sargon/src/profile/v100/app_preferences/resource_preferences/mod.rs rename to crates/sargon/src/profile/v100/networks/network/resource_preferences/mod.rs diff --git a/crates/sargon/src/profile/v100/app_preferences/resource_preferences/resource_app_preference.rs b/crates/sargon/src/profile/v100/networks/network/resource_preferences/resource_app_preference.rs similarity index 67% rename from crates/sargon/src/profile/v100/app_preferences/resource_preferences/resource_app_preference.rs rename to crates/sargon/src/profile/v100/networks/network/resource_preferences/resource_app_preference.rs index fca9df34f..021870b1a 100644 --- a/crates/sargon/src/profile/v100/app_preferences/resource_preferences/resource_app_preference.rs +++ b/crates/sargon/src/profile/v100/networks/network/resource_preferences/resource_app_preference.rs @@ -8,10 +8,19 @@ use crate::prelude::*; Deserialize, Serialize, Clone, PartialEq, Eq, Debug, Hash, uniffi::Record, )] pub struct ResourceAppPreference { + /// The resource for which the preference is set up. pub resource: ResourceIdentifier, + + /// The visibility of the resource (hidden or visible). pub visibility: ResourceVisibility, } +impl IsNetworkAware for ResourceAppPreference { + fn network_id(&self) -> NetworkID { + self.resource.network_id() + } +} + impl ResourceAppPreference { pub fn new( resource: impl Into, @@ -31,19 +40,39 @@ impl Identifiable for ResourceAppPreference { } } -impl HasSampleValues for ResourceAppPreference { - fn sample() -> Self { - Self::new(ResourceIdentifier::sample(), ResourceVisibility::sample()) +impl ResourceAppPreference { + pub(crate) fn sample_fungible_mainnet() -> Self { + Self::new( + ResourceIdentifier::sample_fungible_mainnet(), + ResourceVisibility::sample(), + ) } - fn sample_other() -> Self { + pub(crate) fn sample_non_fungible_mainnet() -> Self { + Self::new( + ResourceIdentifier::sample_non_fungible_mainnet(), + ResourceVisibility::sample_other(), + ) + } + + pub(crate) fn sample_non_fungible_stokenet() -> Self { Self::new( - ResourceIdentifier::sample_other(), + ResourceIdentifier::sample_non_fungible_stokenet(), ResourceVisibility::sample_other(), ) } } +impl HasSampleValues for ResourceAppPreference { + fn sample() -> Self { + Self::sample_fungible_mainnet() + } + + fn sample_other() -> Self { + Self::sample_non_fungible_stokenet() + } +} + #[cfg(test)] mod tests { use super::*; @@ -71,6 +100,11 @@ mod tests { assert_eq!(ResourceVisibility::Visible, sut.visibility); } + #[test] + fn test_is_network_aware() { + assert_eq!(SUT::sample().network_id(), NetworkID::Mainnet); + } + #[test] fn json_roundtrip() { let sut = SUT::sample(); diff --git a/crates/sargon/src/profile/v100/app_preferences/resource_preferences/resource_identifier.rs b/crates/sargon/src/profile/v100/networks/network/resource_preferences/resource_identifier.rs similarity index 55% rename from crates/sargon/src/profile/v100/app_preferences/resource_preferences/resource_identifier.rs rename to crates/sargon/src/profile/v100/networks/network/resource_preferences/resource_identifier.rs index 846049564..4c4446ffd 100644 --- a/crates/sargon/src/profile/v100/app_preferences/resource_preferences/resource_identifier.rs +++ b/crates/sargon/src/profile/v100/networks/network/resource_preferences/resource_identifier.rs @@ -22,6 +22,18 @@ pub enum ResourceIdentifier { PoolUnit(PoolAddress), } +impl IsNetworkAware for ResourceIdentifier { + fn network_id(&self) -> NetworkID { + match self { + Self::NonFungible(resource_address) => { + resource_address.network_id() + } + Self::Fungible(resource_address) => resource_address.network_id(), + Self::PoolUnit(pool_address) => pool_address.network_id(), + } + } +} + impl Identifiable for ResourceIdentifier { type ID = Self; fn id(&self) -> Self::ID { @@ -37,25 +49,29 @@ impl From for ResourceIdentifier { impl HasSampleValues for ResourceIdentifier { fn sample() -> Self { - Self::sample_fungible() + Self::sample_fungible_mainnet() } fn sample_other() -> Self { - Self::sample_non_fungible() + Self::sample_non_fungible_stokenet() } } #[allow(unused)] impl ResourceIdentifier { - pub(crate) fn sample_fungible() -> Self { - Self::Fungible(ResourceAddress::sample()) + pub(crate) fn sample_fungible_mainnet() -> Self { + Self::Fungible(ResourceAddress::sample_mainnet()) + } + + pub(crate) fn sample_non_fungible_mainnet() -> Self { + Self::NonFungible(ResourceAddress::sample_mainnet_other()) } - pub(crate) fn sample_non_fungible() -> Self { - Self::NonFungible(ResourceAddress::sample_other()) + pub(crate) fn sample_non_fungible_stokenet() -> Self { + Self::NonFungible(ResourceAddress::sample_stokenet()) } - pub(crate) fn sample_pool_unit() -> Self { + pub(crate) fn sample_pool_unit_mainnet() -> Self { Self::PoolUnit(PoolAddress::sample()) } } @@ -80,13 +96,28 @@ mod tests { #[test] fn from() { - assert_eq!(SUT::sample_pool_unit(), PoolAddress::sample().into()) + assert_eq!( + SUT::sample_pool_unit_mainnet(), + PoolAddress::sample().into() + ) + } + + #[test] + fn test_is_network_aware() { + assert_eq!( + SUT::sample_fungible_mainnet().network_id(), + NetworkID::Mainnet + ); + assert_eq!( + SUT::sample_non_fungible_stokenet().network_id(), + NetworkID::Stokenet + ); } #[test] fn json_roundtrip() { assert_eq_after_json_roundtrip( - &SUT::sample_fungible(), + &SUT::sample_fungible_mainnet(), r#" { "kind": "fungible", @@ -96,7 +127,7 @@ mod tests { ); assert_eq_after_json_roundtrip( - &SUT::sample_non_fungible(), + &SUT::sample_non_fungible_mainnet(), r#" { "kind": "nonFungible", @@ -106,7 +137,17 @@ mod tests { ); assert_eq_after_json_roundtrip( - &SUT::sample_pool_unit(), + &SUT::sample_non_fungible_stokenet(), + r#" + { + "kind": "nonFungible", + "value": "resource_tdx_2_1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxtfd2jc" + } + "#, + ); + + assert_eq_after_json_roundtrip( + &SUT::sample_pool_unit_mainnet(), r#" { "kind": "poolUnit", diff --git a/crates/sargon/src/profile/v100/app_preferences/resource_preferences/resource_preferences.rs b/crates/sargon/src/profile/v100/networks/network/resource_preferences/resource_preferences.rs similarity index 91% rename from crates/sargon/src/profile/v100/app_preferences/resource_preferences/resource_preferences.rs rename to crates/sargon/src/profile/v100/networks/network/resource_preferences/resource_preferences.rs index 2887005a7..07b4cae1b 100644 --- a/crates/sargon/src/profile/v100/app_preferences/resource_preferences/resource_preferences.rs +++ b/crates/sargon/src/profile/v100/networks/network/resource_preferences/resource_preferences.rs @@ -10,14 +10,24 @@ decl_identified_vec_of!( impl HasSampleValues for ResourcePreferences { fn sample() -> Self { + Self::sample_mainnet() + } + + fn sample_other() -> Self { + Self::sample_stokenet() + } +} + +impl ResourcePreferences { + pub(crate) fn sample_mainnet() -> Self { Self::from_iter([ - ResourceAppPreference::sample(), - ResourceAppPreference::sample_other(), + ResourceAppPreference::sample_fungible_mainnet(), + ResourceAppPreference::sample_non_fungible_mainnet(), ]) } - fn sample_other() -> Self { - Self::from_iter([ResourceAppPreference::sample_other()]) + pub(crate) fn sample_stokenet() -> Self { + Self::from_iter([ResourceAppPreference::sample_non_fungible_stokenet()]) } } diff --git a/crates/sargon/src/profile/v100/app_preferences/resource_preferences/resource_preferences_uniffi_fn.rs b/crates/sargon/src/profile/v100/networks/network/resource_preferences/resource_preferences_uniffi_fn.rs similarity index 100% rename from crates/sargon/src/profile/v100/app_preferences/resource_preferences/resource_preferences_uniffi_fn.rs rename to crates/sargon/src/profile/v100/networks/network/resource_preferences/resource_preferences_uniffi_fn.rs diff --git a/crates/sargon/src/profile/v100/app_preferences/resource_preferences/resource_visibility.rs b/crates/sargon/src/profile/v100/networks/network/resource_preferences/resource_visibility.rs similarity index 100% rename from crates/sargon/src/profile/v100/app_preferences/resource_preferences/resource_visibility.rs rename to crates/sargon/src/profile/v100/networks/network/resource_preferences/resource_visibility.rs diff --git a/crates/sargon/src/profile/v100/networks/profile_networks.rs b/crates/sargon/src/profile/v100/networks/profile_networks.rs index 2a4a1b896..0de952931 100644 --- a/crates/sargon/src/profile/v100/networks/profile_networks.rs +++ b/crates/sargon/src/profile/v100/networks/profile_networks.rs @@ -108,6 +108,7 @@ mod tests { ]), Personas::default(), AuthorizedDapps::default(), + ResourcePreferences::default(), )]); assert!( !sut.append(ProfileNetwork::new( @@ -115,6 +116,7 @@ mod tests { Accounts::from_iter([Account::sample_mainnet_carol()]), Personas::default(), AuthorizedDapps::default(), + ResourcePreferences::default(), )) .0 ); @@ -207,6 +209,7 @@ mod tests { Accounts::just(Account::sample_mainnet()), Personas::default(), AuthorizedDapps::default(), + ResourcePreferences::default(), ); assert_eq!(SUT::just(network).len(), 1); } @@ -566,6 +569,22 @@ mod tests { } ] } + ], + "resource_preferences": [ + { + "resource": { + "kind": "fungible", + "value": "resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd" + }, + "visibility": "hidden" + }, + { + "resource": { + "kind": "nonFungible", + "value": "resource_rdx1t4dy69k6s0gv040xa64cyadyefwtett62ng6xfdnljyydnml7t6g3j" + }, + "visibility": "visible" + } ] }, { @@ -902,6 +921,15 @@ mod tests { } ] } + ], + "resource_preferences": [ + { + "resource": { + "kind": "nonFungible", + "value": "resource_tdx_2_1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxtfd2jc" + }, + "visibility": "visible" + } ] } ] diff --git a/crates/sargon/src/profile/v100/profile.rs b/crates/sargon/src/profile/v100/profile.rs index 313960113..1d37537b2 100644 --- a/crates/sargon/src/profile/v100/profile.rs +++ b/crates/sargon/src/profile/v100/profile.rs @@ -810,8 +810,8 @@ mod tests { "model": "iPhone SE 2nd gen", "mnemonicWordCount": 24, "systemVersion": "iOS 17.4.1", - "hostAppVersion": "1.6.4", - "hostVendor": "Apple" + "hostAppVersion": "1.6.4", + "hostVendor": "Apple" } } }, @@ -875,23 +875,7 @@ mod tests { }, "transaction": { "defaultDepositGuarantee": "0.975" - }, - "resources": [ - { - "resource": { - "kind": "fungible", - "value": "resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd" - }, - "visibility": "hidden" - }, - { - "resource": { - "kind": "nonFungible", - "value": "resource_rdx1t4dy69k6s0gv040xa64cyadyefwtett62ng6xfdnljyydnml7t6g3j" - }, - "visibility": "visible" - } - ] + } }, "networks": [ { @@ -1234,6 +1218,22 @@ mod tests { } ] } + ], + "resource_preferences": [ + { + "resource": { + "kind": "fungible", + "value": "resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd" + }, + "visibility": "hidden" + }, + { + "resource": { + "kind": "nonFungible", + "value": "resource_rdx1t4dy69k6s0gv040xa64cyadyefwtett62ng6xfdnljyydnml7t6g3j" + }, + "visibility": "visible" + } ] }, { @@ -1570,6 +1570,15 @@ mod tests { } ] } + ], + "resource_preferences": [ + { + "resource": { + "kind": "nonFungible", + "value": "resource_tdx_2_1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxtfd2jc" + }, + "visibility": "visible" + } ] } ] diff --git a/crates/sargon/src/system/sargon_os/sargon_os_accounts.rs b/crates/sargon/src/system/sargon_os/sargon_os_accounts.rs index 786fc92ba..2c6d72224 100644 --- a/crates/sargon/src/system/sargon_os/sargon_os_accounts.rs +++ b/crates/sargon/src/system/sargon_os/sargon_os_accounts.rs @@ -351,6 +351,7 @@ impl SargonOS { accounts.clone(), Personas::default(), AuthorizedDapps::default(), + ResourcePreferences::default(), ); networks.append(network); Ok(()) diff --git a/crates/sargon/src/system/sargon_os/sargon_os_profile.rs b/crates/sargon/src/system/sargon_os/sargon_os_profile.rs index dfd0dae0f..3a782acbb 100644 --- a/crates/sargon/src/system/sargon_os/sargon_os_profile.rs +++ b/crates/sargon/src/system/sargon_os/sargon_os_profile.rs @@ -442,6 +442,7 @@ mod tests { Accounts::just(Account::sample_stokenet()), Personas::new(), AuthorizedDapps::new(), + ResourcePreferences::new(), ); profile.networks.append(new_network.clone()); From 5d186c67e9080a90760f7017ccd654b9fdcd9ff6 Mon Sep 17 00:00:00 2001 From: Matias Bzurovski Date: Wed, 4 Sep 2024 18:09:22 +0200 Subject: [PATCH 2/3] missing tests --- .../v100/networks/network/profile_network.rs | 16 ++++++++++++++++ .../resource_preferences/resource_identifier.rs | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/crates/sargon/src/profile/v100/networks/network/profile_network.rs b/crates/sargon/src/profile/v100/networks/network/profile_network.rs index 75e33fdec..745bbea87 100644 --- a/crates/sargon/src/profile/v100/networks/network/profile_network.rs +++ b/crates/sargon/src/profile/v100/networks/network/profile_network.rs @@ -294,6 +294,22 @@ mod tests { ); } + #[test] + #[should_panic( + expected = "Discrepancy, found a ResourceAppPreference on other network than mainnet" + )] + fn panic_when_network_id_mismatch_between_resource_preferences_and_value() { + SUT::new( + NetworkID::Mainnet, + Accounts::sample_mainnet(), + Personas::sample_mainnet(), + AuthorizedDapps::sample_mainnet(), + ResourcePreferences::from_iter([ + ResourceAppPreference::sample_non_fungible_stokenet(), + ]), + ); + } + #[test] fn json_roundtrip_sample_mainnet() { let sut = SUT::sample_mainnet(); diff --git a/crates/sargon/src/profile/v100/networks/network/resource_preferences/resource_identifier.rs b/crates/sargon/src/profile/v100/networks/network/resource_preferences/resource_identifier.rs index 4c4446ffd..ccdd5e5e0 100644 --- a/crates/sargon/src/profile/v100/networks/network/resource_preferences/resource_identifier.rs +++ b/crates/sargon/src/profile/v100/networks/network/resource_preferences/resource_identifier.rs @@ -112,6 +112,10 @@ mod tests { SUT::sample_non_fungible_stokenet().network_id(), NetworkID::Stokenet ); + assert_eq!( + SUT::sample_pool_unit_mainnet().network_id(), + NetworkID::Mainnet + ); } #[test] From cb976639ad96ef2d65b366cc1e62c01610015b5c Mon Sep 17 00:00:00 2001 From: Sergiu Puhalschi Date: Wed, 4 Sep 2024 20:27:55 +0300 Subject: [PATCH 3/3] Update kt extensions --- .../radixdlt/sargon/samples/ProfileNetworkSample.kt | 13 +++++++++---- .../java/com/radixdlt/sargon/AppPreferencesTest.kt | 4 +--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/jvm/sargon-android/src/main/java/com/radixdlt/sargon/samples/ProfileNetworkSample.kt b/jvm/sargon-android/src/main/java/com/radixdlt/sargon/samples/ProfileNetworkSample.kt index 9e44df781..a771c5f86 100644 --- a/jvm/sargon-android/src/main/java/com/radixdlt/sargon/samples/ProfileNetworkSample.kt +++ b/jvm/sargon-android/src/main/java/com/radixdlt/sargon/samples/ProfileNetworkSample.kt @@ -9,6 +9,7 @@ import com.radixdlt.sargon.annotation.UsesSampleValues import com.radixdlt.sargon.extensions.Accounts import com.radixdlt.sargon.extensions.AuthorizedDapps import com.radixdlt.sargon.extensions.Personas +import com.radixdlt.sargon.extensions.ResourceAppPreferences @UsesSampleValues val ProfileNetwork.Companion.sampleMainnet: Sample @@ -23,7 +24,8 @@ val ProfileNetwork.Companion.sampleMainnet: Sample ).asList(), authorizedDapps = AuthorizedDapps( AuthorizedDapp.sampleMainnet() - ).asList() + ).asList(), + resourcePreferences = ResourceAppPreferences.sample().asList() ) override fun other(): ProfileNetwork = ProfileNetwork( @@ -36,7 +38,8 @@ val ProfileNetwork.Companion.sampleMainnet: Sample ).asList(), authorizedDapps = AuthorizedDapps( AuthorizedDapp.sampleMainnet.other() - ).asList() + ).asList(), + resourcePreferences = ResourceAppPreferences.sample.other().asList() ) } @@ -53,7 +56,8 @@ val ProfileNetwork.Companion.sampleStokenet: Sample ).asList(), authorizedDapps = AuthorizedDapps( AuthorizedDapp.sampleStokenet() - ).asList() + ).asList(), + resourcePreferences = ResourceAppPreferences.sample().asList() ) override fun other(): ProfileNetwork = ProfileNetwork( @@ -66,6 +70,7 @@ val ProfileNetwork.Companion.sampleStokenet: Sample ).asList(), authorizedDapps = AuthorizedDapps( AuthorizedDapp.sampleStokenet.other() - ).asList() + ).asList(), + resourcePreferences = ResourceAppPreferences.sample.other().asList() ) } \ No newline at end of file diff --git a/jvm/sargon-android/src/test/java/com/radixdlt/sargon/AppPreferencesTest.kt b/jvm/sargon-android/src/test/java/com/radixdlt/sargon/AppPreferencesTest.kt index 42633bd33..03916ea2c 100644 --- a/jvm/sargon-android/src/test/java/com/radixdlt/sargon/AppPreferencesTest.kt +++ b/jvm/sargon-android/src/test/java/com/radixdlt/sargon/AppPreferencesTest.kt @@ -1,6 +1,5 @@ package com.radixdlt.sargon -import com.radixdlt.sargon.extensions.ResourceAppPreferences import com.radixdlt.sargon.extensions.default import com.radixdlt.sargon.extensions.toDecimal192 import com.radixdlt.sargon.samples.Sample @@ -28,8 +27,7 @@ class AppPreferencesTest : SampleTestable { isAdvancedLockEnabled = false, securityStructuresOfFactorSourceIds = emptyList() ), - transaction = TransactionPreferences(defaultDepositGuarantee = 0.99.toDecimal192()), - resources = ResourceAppPreferences().asList() + transaction = TransactionPreferences(defaultDepositGuarantee = 0.99.toDecimal192()) ), AppPreferences.default() )