diff --git a/Cargo.lock b/Cargo.lock index 8f274ead5..6353e8cdb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2761,7 +2761,7 @@ dependencies = [ [[package]] name = "sargon" -version = "1.1.88" +version = "1.1.89" dependencies = [ "actix-rt", "aes-gcm", @@ -2816,7 +2816,7 @@ dependencies = [ [[package]] name = "sargon-uniffi" -version = "1.1.88" +version = "1.1.89" dependencies = [ "actix-rt", "assert-json-diff", diff --git a/crates/sargon-uniffi/Cargo.toml b/crates/sargon-uniffi/Cargo.toml index 19d15232e..2d6add444 100644 --- a/crates/sargon-uniffi/Cargo.toml +++ b/crates/sargon-uniffi/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "sargon-uniffi" # Don't forget to update version in crates/sargon/Cargo.toml -version = "1.1.88" +version = "1.1.89" edition = "2021" build = "build.rs" diff --git a/crates/sargon/Cargo.toml b/crates/sargon/Cargo.toml index 3a2363e47..ec5abe96a 100644 --- a/crates/sargon/Cargo.toml +++ b/crates/sargon/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "sargon" # Don't forget to update version in crates/sargon-uniffi/Cargo.toml -version = "1.1.88" +version = "1.1.89" edition = "2021" build = "build.rs" 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 2e7108da5..80e53a3eb 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..d04c65ce9 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 @@ -544,47 +544,6 @@ mod transaction_preview_analysis_tests { ) } - #[actix_rt::test] - async fn signer_entities_not_found() { - let responses = prepare_responses( - LedgerState { - network: "".to_string(), - state_version: 0, - proposer_round_timestamp: "".to_string(), - epoch: 0, - round: 0, - }, - TransactionPreviewResponse { - encoded_receipt: "".to_string(), - radix_engine_toolkit_receipt: Some( - ScryptoSerializableToolkitTransactionReceipt::Reject { - reason: "Test".to_string(), - }, - ), - logs: vec![], - receipt: TransactionReceipt { - status: TransactionReceiptStatus::Succeeded, - error_message: None, - }, - }, - ); - let os = - prepare_os(MockNetworkingDriver::new_with_bodies(200, responses)) - .await; - - let result = os - .analyse_transaction_preview( - TransactionManifest::sample().instructions_string(), - Blobs::sample(), - true, - Nonce::sample(), - PublicKey::sample(), - ) - .await; - - assert_eq!(result, Err(CommonError::UnknownAccount)) - } - #[actix_rt::test] async fn execution_summary_parse_error() { let responses = prepare_responses( @@ -731,6 +690,51 @@ mod transaction_preview_analysis_tests { ) } + #[actix_rt::test] + async fn signer_entities_not_found() { + let responses = prepare_responses( + LedgerState { + network: "".to_string(), + state_version: 0, + proposer_round_timestamp: "".to_string(), + epoch: 0, + round: 0, + }, + TransactionPreviewResponse { + encoded_receipt: "".to_string(), + radix_engine_toolkit_receipt: Some( + ScryptoSerializableToolkitTransactionReceipt::Reject { + reason: "Test".to_string(), + }, + ), + logs: vec![], + receipt: TransactionReceipt { + status: TransactionReceiptStatus::Succeeded, + error_message: None, + }, + }, + ); + let os = + prepare_os(MockNetworkingDriver::new_with_bodies(200, responses)) + .await; + + let result = os + .analyse_transaction_preview( + TransactionManifest::sample().instructions_string(), + Blobs::sample(), + true, + Nonce::sample(), + PublicKey::sample(), + ) + .await; + + // Just asserts that the execution path reached GW preview call + assert!(matches!( + result, + Err(CommonError::ExecutionSummaryFail { .. }) + )) + } + #[actix_rt::test] async fn analyse_open_pre_auth_preview() { let os = prepare_os(MockNetworkingDriver::new_always_failing()).await;