Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
MAJOR MILESTONE: Profile deserialized in full.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sajjon committed Jan 31, 2024
1 parent cc65274 commit fe39b1c
Show file tree
Hide file tree
Showing 13 changed files with 1,023 additions and 66 deletions.
41 changes: 32 additions & 9 deletions profile/src/v100/entity/persona/persona.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use __private__::PhantomData;
use rand::distributions::uniform::SampleBorrow;

use crate::prelude::*;
Expand Down Expand Up @@ -95,6 +96,30 @@ impl Persona {
}
}

pub struct IDGenerator<T: From<Uuid>> {
ctr: Arc<Mutex<u64>>,
phantom: PhantomData<T>,
}
impl<T: From<Uuid>> IDGenerator<T> {
pub fn starting_at(ctr: u64) -> Self {
Self {
ctr: Arc::new(Mutex::new(ctr)),
phantom: PhantomData,
}
}

#[allow(clippy::new_without_default)]
pub fn new() -> Self {
Self::starting_at(0)

Check warning on line 113 in profile/src/v100/entity/persona/persona.rs

View check run for this annotation

Codecov / codecov/patch

profile/src/v100/entity/persona/persona.rs#L112-L113

Added lines #L112 - L113 were not covered by tests
}

pub fn next(&self) -> T {
let n = Uuid::from_u64_pair(0, *self.ctr.lock().unwrap().borrow());
self.ctr.lock().unwrap().borrow_mut().add_assign(1);
n.into()
}
}

impl Persona {
#[cfg(not(tarpaulin_include))] // false negative
fn placeholder_at_index_name_network<P, E>(
Expand All @@ -120,25 +145,23 @@ impl Persona {
let private_hd_factor_source =
PrivateHierarchicalDeterministicFactorSource::new(mwp, bdfs);

let ctr = Arc::<Mutex<u64>>::new(Mutex::new(1));
let next = || {
let n = Uuid::from_u64_pair(0, *ctr.lock().unwrap().borrow());
ctr.lock().unwrap().borrow_mut().add_assign(1);
n.into()
};

let id = IDGenerator::<PersonaDataEntryID>::starting_at(1);
let phone_numbers = CollectionOfPhoneNumbers::entries(
phone_numbers
.into_iter()
.map(|s| s.parse::<PersonaDataEntryPhoneNumber>().unwrap())
.map(|v| PersonaDataIdentifiedPhoneNumber::with_id(next(), v)),
.map(|v| {
PersonaDataIdentifiedPhoneNumber::with_id(id.next(), v)
}),
);

let email_addresses = CollectionOfEmailAddresses::entries(
email_addresses
.into_iter()
.map(|s| s.parse::<PersonaDataEntryEmailAddress>().unwrap())
.map(|v| PersonaDataIdentifiedEmailAddress::with_id(next(), v)),
.map(|v| {
PersonaDataIdentifiedEmailAddress::with_id(id.next(), v)
}),
);

let mut persona = Self::new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,34 @@ impl From<Uuid> for PersonaDataEntryID {
}
}

impl PersonaDataEntryID {
fn from_u64(value: u64) -> Self {
Uuid::from_u64_pair(0, value).into()
}

pub fn placeholder_one() -> Self {
Self::from_u64(1)
}

pub fn placeholder_two() -> Self {
Self::from_u64(2)
}

pub fn placeholder_three() -> Self {
Self::from_u64(3)

Check warning on line 78 in profile/src/v100/entity/persona/persona_data/persona_data_entry_id.rs

View check run for this annotation

Codecov / codecov/patch

profile/src/v100/entity/persona/persona_data/persona_data_entry_id.rs#L77-L78

Added lines #L77 - L78 were not covered by tests
}

pub fn placeholder_four() -> Self {
Self::from_u64(4)

Check warning on line 82 in profile/src/v100/entity/persona/persona_data/persona_data_entry_id.rs

View check run for this annotation

Codecov / codecov/patch

profile/src/v100/entity/persona/persona_data/persona_data_entry_id.rs#L81-L82

Added lines #L81 - L82 were not covered by tests
}
}

impl HasPlaceholder for PersonaDataEntryID {
fn placeholder() -> Self {
Uuid::from_str("00000000-0000-0000-0000-000000000001")
.expect("Should have a valid placeholder")
.into()
Self::placeholder_one()
}

fn placeholder_other() -> Self {
Uuid::from_str("00000000-0000-0000-0000-000000000002")
.expect("Should have a valid placeholder")
.into()
Self::placeholder_two()
}
}
142 changes: 140 additions & 2 deletions profile/src/v100/networks/network/authorized_dapp/authorized_dapp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,29 @@ mod tests {
"account_rdx16xlfcpp0vf7e3gqnswv8j9k58n6rjccu58vvspmdva22kf3aplease",
"account_rdx16yf8jxxpdtcf4afpj5ddeuazp2evep7quuhgtq28vjznee08master"
]
},
"sharedPersonaData": {
"name": "00000000-0000-0000-0000-000000000000",
"emailAddresses": {
"request": {
"quantifier": "exactly",
"quantity": 2
},
"ids": [
"00000000-0000-0000-0000-000000000001",
"00000000-0000-0000-0000-000000000002"
]
},
"phoneNumbers": {
"request": {
"quantifier": "atLeast",
"quantity": 1
},
"ids": [
"00000000-0000-0000-0000-000000000003",
"00000000-0000-0000-0000-000000000004"
]
}
}
},
{
Expand All @@ -175,6 +198,29 @@ mod tests {
"ids": [
"account_rdx16yf8jxxpdtcf4afpj5ddeuazp2evep7quuhgtq28vjznee08master"
]
},
"sharedPersonaData": {
"name": "00000000-0000-0000-0000-0000000000f0",
"emailAddresses": {
"request": {
"quantifier": "exactly",
"quantity": 2
},
"ids": [
"00000000-0000-0000-0000-0000000000f1",
"00000000-0000-0000-0000-0000000000f2"
]
},
"phoneNumbers": {
"request": {
"quantifier": "atLeast",
"quantity": 1
},
"ids": [
"00000000-0000-0000-0000-0000000000f3",
"00000000-0000-0000-0000-0000000000f4"
]
}
}
}
]
Expand All @@ -189,7 +235,7 @@ mod tests {
assert_eq_after_json_roundtrip(
&model,
r#"
{
{
"networkID": 1,
"dAppDefinitionAddress": "account_rdx12xuhw6v30chdkhcu7qznz9vu926vxefr4h4tdvc0mdckg9rq4afx9t",
"displayName": "Gumball Club",
Expand All @@ -205,6 +251,29 @@ mod tests {
"ids": [
"account_rdx16yf8jxxpdtcf4afpj5ddeuazp2evep7quuhgtq28vjznee08master"
]
},
"sharedPersonaData": {
"name": "00000000-0000-0000-0000-0000000000f0",
"emailAddresses": {
"request": {
"quantifier": "exactly",
"quantity": 2
},
"ids": [
"00000000-0000-0000-0000-0000000000f1",
"00000000-0000-0000-0000-0000000000f2"
]
},
"phoneNumbers": {
"request": {
"quantifier": "atLeast",
"quantity": 1
},
"ids": [
"00000000-0000-0000-0000-0000000000f3",
"00000000-0000-0000-0000-0000000000f4"
]
}
}
}
]
Expand All @@ -219,7 +288,7 @@ mod tests {
assert_eq_after_json_roundtrip(
&model,
r#"
{
{
"networkID": 2,
"dAppDefinitionAddress": "account_tdx_2_128evrrwfp8gj9240qq0m06ukhwaj2cmejluxxreanzjwq62vmlf8r4",
"displayName": "Dev Console",
Expand All @@ -236,6 +305,29 @@ mod tests {
"account_tdx_2_1289zm062j788dwrjefqkfgfeea5tkkdnh8htqhdrzdvjkql4kxceql",
"account_tdx_2_129663ef7fj8azge3y6sl73lf9vyqt53ewzlf7ul2l76mg5wyqlqlpr"
]
},
"sharedPersonaData": {
"name": "00000000-0000-0000-0000-000000000000",
"emailAddresses": {
"request": {
"quantifier": "exactly",
"quantity": 2
},
"ids": [
"00000000-0000-0000-0000-000000000001",
"00000000-0000-0000-0000-000000000002"
]
},
"phoneNumbers": {
"request": {
"quantifier": "atLeast",
"quantity": 1
},
"ids": [
"00000000-0000-0000-0000-000000000003",
"00000000-0000-0000-0000-000000000004"
]
}
}
},
{
Expand All @@ -249,6 +341,29 @@ mod tests {
"ids": [
"account_tdx_2_129663ef7fj8azge3y6sl73lf9vyqt53ewzlf7ul2l76mg5wyqlqlpr"
]
},
"sharedPersonaData": {
"name": "00000000-0000-0000-0000-0000000000f0",
"emailAddresses": {
"request": {
"quantifier": "exactly",
"quantity": 2
},
"ids": [
"00000000-0000-0000-0000-0000000000f1",
"00000000-0000-0000-0000-0000000000f2"
]
},
"phoneNumbers": {
"request": {
"quantifier": "atLeast",
"quantity": 1
},
"ids": [
"00000000-0000-0000-0000-0000000000f3",
"00000000-0000-0000-0000-0000000000f4"
]
}
}
}
]
Expand Down Expand Up @@ -279,6 +394,29 @@ mod tests {
"ids": [
"account_tdx_2_129663ef7fj8azge3y6sl73lf9vyqt53ewzlf7ul2l76mg5wyqlqlpr"
]
},
"sharedPersonaData": {
"name": "00000000-0000-0000-0000-0000000000f0",
"emailAddresses": {
"request": {
"quantifier": "exactly",
"quantity": 2
},
"ids": [
"00000000-0000-0000-0000-0000000000f1",
"00000000-0000-0000-0000-0000000000f2"
]
},
"phoneNumbers": {
"request": {
"quantifier": "atLeast",
"quantity": 1
},
"ids": [
"00000000-0000-0000-0000-0000000000f3",
"00000000-0000-0000-0000-0000000000f4"
]
}
}
}
]
Expand Down
Loading

0 comments on commit fe39b1c

Please sign in to comment.