diff --git a/crates/sargon/src/signing/collector/extractor_of_instances_required_to_sign_transactions.rs b/crates/sargon/src/signing/collector/extractor_of_instances_required_to_sign_transactions.rs index d14f9a996..e2b65c9bc 100644 --- a/crates/sargon/src/signing/collector/extractor_of_instances_required_to_sign_transactions.rs +++ b/crates/sargon/src/signing/collector/extractor_of_instances_required_to_sign_transactions.rs @@ -47,13 +47,19 @@ mod tests { #[test] fn preprocessor_init_fail() { + let intent_with_invalid_persona = + TransactionIntent::sample_entity_addresses_requiring_auth( + vec![], + vec![Persona::sample_mainnet().address], + ); + let result = ExtractorOfInstancesRequiredToSignTransactions::extract( &Profile::sample_other(), - vec![TransactionIntent::sample()], + vec![intent_with_invalid_persona], RoleKind::Primary, ); - assert!(matches!(result, Err(CommonError::UnknownAccount))); + assert!(matches!(result, Err(CommonError::UnknownPersona))); } #[test] diff --git a/crates/sargon/src/signing/collector/signatures_collector.rs b/crates/sargon/src/signing/collector/signatures_collector.rs index 80810b950..0cff42feb 100644 --- a/crates/sargon/src/signing/collector/signatures_collector.rs +++ b/crates/sargon/src/signing/collector/signatures_collector.rs @@ -435,7 +435,7 @@ mod tests { } #[test] - fn invalid_profile_unknown_account() { + fn profile_with_unknown_account() { let res = SignaturesCollector::new( SigningFinishEarlyStrategy::default(), [TransactionIntent::sample_entities_requiring_auth( @@ -446,7 +446,7 @@ mod tests { &Profile::sample_from(IndexSet::new(), [], []), RoleKind::Primary, ); - assert!(matches!(res, Err(CommonError::UnknownAccount))); + assert!(res.is_ok()); } #[test] diff --git a/crates/sargon/src/signing/extractor_of_entities_requiring_auth.rs b/crates/sargon/src/signing/extractor_of_entities_requiring_auth.rs index 2ec48cf35..c439f2c9f 100644 --- a/crates/sargon/src/signing/extractor_of_entities_requiring_auth.rs +++ b/crates/sargon/src/signing/extractor_of_entities_requiring_auth.rs @@ -5,7 +5,7 @@ pub struct ExtractorOfEntitiesRequiringAuth; impl ExtractorOfEntitiesRequiringAuth { /// Matches entities requiring auth from a manifest summary with the entities in the given profile. /// Returns a set of `AccountOrPersona` or empty if the manifest summary does not require auth. - /// Returns an error if an account or persona is unknown. + /// Returns an error if persona is unknown. pub fn extract( profile: &Profile, summary: ManifestSummary, @@ -17,7 +17,8 @@ impl ExtractorOfEntitiesRequiringAuth { .addresses_of_accounts_requiring_auth .iter() .map(|a| profile.account_by_address(*a)) - .collect::>>()?; + .filter_map(|a| a.ok()) + .collect::>(); entities_requiring_auth.extend( accounts @@ -45,6 +46,7 @@ impl ExtractorOfEntitiesRequiringAuth { #[cfg(test)] mod tests { use super::*; + use indexmap::IndexSet; use radix_transactions::prelude::ManifestBuilder; #[test] @@ -67,7 +69,7 @@ mod tests { manifest_summary, ); - assert!(matches!(result, Err(CommonError::UnknownAccount))); + assert_eq!(result, Ok(IndexSet::new())); } #[test] diff --git a/crates/sargon/src/system/sargon_os/sargon_os_signing.rs b/crates/sargon/src/system/sargon_os/sargon_os_signing.rs index 0d24422c1..d0e1660e1 100644 --- a/crates/sargon/src/system/sargon_os/sargon_os_signing.rs +++ b/crates/sargon/src/system/sargon_os/sargon_os_signing.rs @@ -196,6 +196,45 @@ mod test { ); } + #[actix_rt::test] + async fn test_sign_transaction_intent_only_with_irrelevant_entity() { + let profile = Profile::sample(); + let sut = boot_with_profile(&profile, None).await; + + let irrelevant_account = Account::sample_mainnet_third(); + let transaction = TransactionIntent::sample_entities_requiring_auth( + vec![&irrelevant_account], + vec![], + ); + + let outcome = sut + .sign_transaction(transaction, RoleKind::Primary) + .await + .unwrap(); + + assert_eq!(outcome.intent_signatures.signatures.len(), 0); + } + + #[actix_rt::test] + async fn test_sign_transaction_intent_containing_irrelevant_entity() { + let profile = Profile::sample(); + let sut = boot_with_profile(&profile, None).await; + + let irrelevant_account = Account::sample_mainnet_third(); + let relevant_account = Account::sample_mainnet(); + let transaction = TransactionIntent::sample_entities_requiring_auth( + vec![&irrelevant_account, &relevant_account], + vec![], + ); + + let outcome = sut + .sign_transaction(transaction, RoleKind::Primary) + .await + .unwrap(); + + assert_eq!(outcome.intent_signatures.signatures.len(), 1); + } + #[actix_rt::test] async fn test_sign_transaction_intent_rejected_due_to_all_factors_neglected( ) { @@ -283,29 +322,6 @@ mod test { assert_eq!(outcome, Err(CommonError::SigningRejected)); } - #[actix_rt::test] - async fn test_sign_fail_due_to_irrelevant_entity() { - let profile = Profile::sample(); - let sut = boot_with_profile( - &profile, - Some(SigningFailure::NeglectedFactorSources(vec![ - profile.device_factor_sources().first().unwrap().id, - ])), - ) - .await; - - let irrelevant_account = Account::sample_mainnet_third(); - let transaction = TransactionIntent::sample_entities_requiring_auth( - vec![&irrelevant_account], - vec![], - ); - - let outcome = - sut.sign_transaction(transaction, RoleKind::Primary).await; - - assert_eq!(outcome, Err(CommonError::UnknownAccount)); - } - async fn boot_with_profile( profile: &Profile, maybe_signing_failure: Option, diff --git a/crates/sargon/src/system/sargon_os/transactions/sargon_os_transaction_analysis.rs b/crates/sargon/src/system/sargon_os/transactions/sargon_os_transaction_analysis.rs index d11bc52d4..14f8bbe4c 100644 --- a/crates/sargon/src/system/sargon_os/transactions/sargon_os_transaction_analysis.rs +++ b/crates/sargon/src/system/sargon_os/transactions/sargon_os_transaction_analysis.rs @@ -582,7 +582,11 @@ mod transaction_preview_analysis_tests { ) .await; - assert_eq!(result, Err(CommonError::UnknownAccount)) + // Just asserts that the execution path reached GW preview call + assert!(matches!( + result, + Err(CommonError::ExecutionSummaryFail { .. }) + )) } #[actix_rt::test]