Skip to content

Commit

Permalink
PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiupuhalschi-rdx committed Jan 16, 2025
1 parent 3ef0c5f commit bbcfd2f
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Foundation
import SargonUniFFI

extension TimePeriodUnit {
public var values: [Int] {
Array(1 ... Int(constantMaxRecoveryConfirmationFallbackPeriodUnits()))
}
}
4 changes: 4 additions & 0 deletions apple/Sources/Sargon/Util/SharedConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ extension Account {
extension Persona {
public static let nameMaxLength = Int(constantEntityNameMaxLength())
}

extension DisplayName {
public static let maxLength = Int(constantDisplayNameMaxLength())
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ struct ShieldTests {
builder = builder.addFactorSourceToRecoveryOverride(factorSourceId: .sampleArculus)
.addFactorSourceToConfirmationOverride(factorSourceId: .sampleArculusOther)

builder.setAuthenticationSigningFactor(new: .sampleDevice)
builder = builder.setAuthenticationSigningFactor(new: .sampleDevice)

let shield = try! builder.build()

Expand Down Expand Up @@ -206,7 +206,7 @@ struct ShieldTests {
.removeFactorFromPrimary(factorSourceId: .sampleArculusOther, factorListKind: FactorListKind.override)
.removeFactorFromRecovery(factorSourceId: .sampleLedgerOther)

builder.setAuthenticationSigningFactor(new: .sampleDevice)
builder = builder.setAuthenticationSigningFactor(new: .sampleDevice)

// Validate
#expect(builder.validate() == nil)
Expand Down
12 changes: 12 additions & 0 deletions apple/Tests/TestCases/Profile/MFA/TimePeriodUnitTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import CustomDump
import Foundation
import Sargon
import SargonUniFFI
import XCTest

final class TimePeriodUnitTests: TestCase {
func test() {
let sut = TimePeriodUnit.days
XCTAssertEqual(sut.values, Array(1 ... 9999))
}
}
3 changes: 0 additions & 3 deletions crates/core/utils/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ pub const DAYS_PER_WEEK: u16 = 7;
/// Number of days per year.
pub const DAYS_PER_YEAR: u16 = 365;

/// Maximum number of units (days, weeks, years) for the security structure recovery confirmation fallback period.
pub const MAX_RECOVERY_CONFIRMATION_FALLBACK_PERIOD_UNITS: u16 = 9999;

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,12 +423,8 @@ impl MatrixBuilder {
pub fn remove_all_factors_from_primary_override(
&mut self,
) -> MatrixBuilderMutateResult {
let primary_override_factors =
self.primary_role.get_override_factors().clone();

primary_override_factors.iter().try_for_each(|fsid| {
self.remove_factor_from_primary(fsid, FactorListKind::Override)
})
self.primary_role.remove_all_override_factors();
Ok(())
}

pub fn remove_factor_from_recovery(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,18 @@ pub(crate) type RoleBuilder<const ROLE: u8> =
impl<const ROLE: u8, const MODE: u8, FACTOR: IsMaybeKeySpaceAware>
AbstractRoleBuilderOrBuilt<ROLE, MODE, FACTOR>
{
/// Removes all factors from this role and set threshold to 0.
/// Removes all factors from this role and set threshold to `All`.
pub fn reset(&mut self) {
self.threshold_factors.clear();
self.threshold = Threshold::All;
self.override_factors.clear();
}

/// Removes all override factors from this role.
pub fn remove_all_override_factors(&mut self) {
self.override_factors.clear();
}

pub fn role(&self) -> RoleKind {
RoleKind::from_u8(ROLE).expect("RoleKind should be valid")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ impl std::hash::Hash for SecurityShieldBuilder {
}

impl SecurityShieldBuilder {
/// Maximum number of units (days, weeks, years) for the security structure recovery confirmation fallback period.
pub const MAX_RECOVERY_CONFIRMATION_FALLBACK_PERIOD_UNITS: u16 = 9999;

pub fn new(mode: SecurityShieldBuilderMode) -> Self {
let matrix_builder = MatrixBuilder::new();
let name = RwLock::new("My Shield".to_owned());
Expand Down
35 changes: 0 additions & 35 deletions crates/profile/models/security-structures/src/time_period_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,6 @@ impl HasSampleValues for TimePeriodUnit {
}
}

impl TimePeriodUnit {
pub fn values(&self) -> Vec<u16> {
match self {
TimePeriodUnit::Days => {
(1..=MAX_RECOVERY_CONFIRMATION_FALLBACK_PERIOD_UNITS).collect()
}
TimePeriodUnit::Weeks => {
(1..=MAX_RECOVERY_CONFIRMATION_FALLBACK_PERIOD_UNITS).collect()
}
TimePeriodUnit::Years => {
(1..=MAX_RECOVERY_CONFIRMATION_FALLBACK_PERIOD_UNITS).collect()
}
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -53,23 +37,4 @@ mod tests {
fn inequality() {
assert_ne!(SUT::sample(), SUT::sample_other());
}

#[test]
fn values() {
assert_eq!(
SUT::Days.values(),
(1..=MAX_RECOVERY_CONFIRMATION_FALLBACK_PERIOD_UNITS)
.collect::<Vec<u16>>()
);
assert_eq!(
SUT::Weeks.values(),
(1..=MAX_RECOVERY_CONFIRMATION_FALLBACK_PERIOD_UNITS)
.collect::<Vec<u16>>()
);
assert_eq!(
SUT::Years.values(),
(1..=MAX_RECOVERY_CONFIRMATION_FALLBACK_PERIOD_UNITS)
.collect::<Vec<u16>>()
);
}
}
12 changes: 11 additions & 1 deletion crates/uniffi/uniffi_SPLIT_ME/src/core/utils/constants.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
#[uniffi::export]
pub fn constant_entity_name_max_length() -> u64 {
pub fn constant_display_name_max_length() -> u64 {
sargon::DisplayName::MAX_LEN as u64
}

#[uniffi::export]
pub fn constant_entity_name_max_length() -> u64 {
constant_display_name_max_length()
}

#[uniffi::export]
pub fn constant_min_required_xrd_for_account_deletion() -> f64 {
sargon::MIN_REQUIRED_XRD_FOR_ACCOUNT_DELETION
}

#[uniffi::export]
pub fn constant_max_recovery_confirmation_fallback_period_units() -> u16 {
sargon::SecurityShieldBuilder::MAX_RECOVERY_CONFIRMATION_FALLBACK_PERIOD_UNITS
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,3 @@ pub enum TimePeriodUnit {
Weeks,
Years,
}

#[uniffi::export]
pub fn time_period_unit_values(time_period_unit: &TimePeriodUnit) -> Vec<u16> {
time_period_unit
.into_internal()
.values()
.into_iter()
.collect()
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
package com.radixdlt.sargon.extensions

import com.radixdlt.sargon.Account
import com.radixdlt.sargon.DisplayName
import com.radixdlt.sargon.Persona
import com.radixdlt.sargon.annotation.KoverIgnore
import com.radixdlt.sargon.constantDisplayNameMaxLength
import com.radixdlt.sargon.constantEntityNameMaxLength
import com.radixdlt.sargon.constantMinRequiredXrdForAccountDeletion
import com.radixdlt.sargon.extensions.SharedConstants.displayNameMaxLength
import com.radixdlt.sargon.extensions.SharedConstants.entityNameMaxLength

@KoverIgnore
object SharedConstants {
val minRequiredXrdForAccountDeletion = constantMinRequiredXrdForAccountDeletion()
val entityNameMaxLength = constantEntityNameMaxLength().toLong()
val displayNameMaxLength = constantDisplayNameMaxLength().toLong()
}

@KoverIgnore
val Account.Companion.nameMaxLength: Long
get() = constantEntityNameMaxLength().toLong()
get() = entityNameMaxLength

Check warning on line 22 in jvm/sargon-android/src/main/java/com/radixdlt/sargon/extensions/SharedConstants.kt

View check run for this annotation

Codecov / codecov/patch

jvm/sargon-android/src/main/java/com/radixdlt/sargon/extensions/SharedConstants.kt#L22

Added line #L22 was not covered by tests

@KoverIgnore
val Persona.Companion.nameMaxLength: Long
get() = constantEntityNameMaxLength().toLong()
get() = entityNameMaxLength

Check warning on line 26 in jvm/sargon-android/src/main/java/com/radixdlt/sargon/extensions/SharedConstants.kt

View check run for this annotation

Codecov / codecov/patch

jvm/sargon-android/src/main/java/com/radixdlt/sargon/extensions/SharedConstants.kt#L26

Added line #L26 was not covered by tests

val DisplayName.Companion.maxLength: Long
get() = displayNameMaxLength

Check warning on line 29 in jvm/sargon-android/src/main/java/com/radixdlt/sargon/extensions/SharedConstants.kt

View check run for this annotation

Codecov / codecov/patch

jvm/sargon-android/src/main/java/com/radixdlt/sargon/extensions/SharedConstants.kt#L29

Added line #L29 was not covered by tests
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.radixdlt.sargon.extensions

import com.radixdlt.sargon.TimePeriodUnit
import com.radixdlt.sargon.timePeriodUnitValues
import com.radixdlt.sargon.constantMaxRecoveryConfirmationFallbackPeriodUnits

val TimePeriodUnit.values
get() = timePeriodUnitValues(this).toList()
.map { it.toInt() }
get() = (1..constantMaxRecoveryConfirmationFallbackPeriodUnits().toInt()).toList()

0 comments on commit bbcfd2f

Please sign in to comment.