Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
GhenadieVP committed Dec 17, 2024
1 parent 7f13683 commit 3f77cd5
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions crates/sargon/src/signing/collector/signatures_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -446,7 +446,7 @@ mod tests {
&Profile::sample_from(IndexSet::new(), [], []),
RoleKind::Primary,
);
assert!(matches!(res, Err(CommonError::UnknownAccount)));
assert!(res.is_ok());
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -17,7 +17,8 @@ impl ExtractorOfEntitiesRequiringAuth {
.addresses_of_accounts_requiring_auth
.iter()
.map(|a| profile.account_by_address(*a))
.collect::<Result<Vec<_>>>()?;
.filter_map(|a| a.ok())
.collect::<Vec<_>>();

entities_requiring_auth.extend(
accounts
Expand Down Expand Up @@ -45,6 +46,7 @@ impl ExtractorOfEntitiesRequiringAuth {
#[cfg(test)]
mod tests {
use super::*;
use indexmap::IndexSet;
use radix_transactions::prelude::ManifestBuilder;

#[test]
Expand All @@ -67,7 +69,7 @@ mod tests {
manifest_summary,
);

assert!(matches!(result, Err(CommonError::UnknownAccount)));
assert_eq!(result, Ok(IndexSet::new()));
}

#[test]
Expand Down
62 changes: 39 additions & 23 deletions crates/sargon/src/system/sargon_os/sargon_os_signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
) {
Expand Down Expand Up @@ -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<SigningFailure>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 3f77cd5

Please sign in to comment.