Skip to content

Commit 4a2d0b4

Browse files
committed
fix: guts for the stubbed unit test for business logic
1 parent cb2ff94 commit 4a2d0b4

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

src/web3id.rs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ pub async fn get_public_data(
260260
#[cfg(test)]
261261
mod tests {
262262
use super::*;
263-
use chrono::Days;
263+
use chrono::{Datelike, Days};
264+
use concordium_base::{contracts_common::PublicKeyEd25519, id::types::{ArIdentity, Description, YearMonth}, ps_sig::PublicKey};
264265

265266
/// valid from is before now, valid to is in the future, therefore credential status should be `active`
266267
#[test]
@@ -330,4 +331,54 @@ mod tests {
330331
let status = determine_credential_status_valid_to(now, valid_to);
331332
assert_eq!(CredentialStatus::Expired, status);
332333
}
334+
335+
// test the verification of an identity credential
336+
#[test]
337+
fn test_verify_identity_credential_metadata_success() {
338+
339+
// mock data
340+
let now = Utc::now();
341+
let issuer = IpIdentity(1u32);
342+
343+
// Identity provider
344+
let ip_description = Description {description: "dummy description".to_string(), name: "dummy name".to_string(), url: "http://dummy.com".to_string()};
345+
let ip_verify_key = None;
346+
let ip_cdi_key = None;
347+
let ip_info_stubbed = IpInfo { ip_identity: issuer, ip_description: ip_description, ip_verify_key: ip_verify_key, ip_cdi_verify_key: ip_cdi_key};
348+
let identity_providers = vec![ip_info_stubbed];
349+
350+
// the anonymity revokers for testing
351+
let ar_identity = ArIdentity(1u32);
352+
let ar_public_key = PublicKey { .. }; // some constructed public key here?
353+
let ar_description = Description {description: "ar description".to_string(), name: "ar dummy name".to_string(), url: "http://dummy.com".to_string()};
354+
let anonymity_revoker = ArInfo {ar_identity: ar_identity, ar_description: ar_description, ar_public_key: ar_public_key };
355+
let anonymity_revokers = vec![anonymity_revoker];
356+
357+
// credential validity
358+
let created_at = YearMonth { month: now.month() as u8 , year: (now.year() - 1)};
359+
let valid_to = YearMonth { month: (now.month() + 1) as u8, year: (now.year() as u16)};
360+
let credential_validity = CredentialValidity {created_at: created_at, valid_to: valid_to};
361+
362+
// invocation
363+
let result = verify_identity_credential_metadata(
364+
now, issuer, identity_providers, anonymity_revokers, validity)?;
365+
366+
// Expected anonymity revoker information returned in result
367+
let expected_ar_info_btree = BTreeMap::new();
368+
expected_ar_info_btree.insert(ar_identity, anonymity_revoker);
369+
let expected_ar_infos = ArInfos {anonymity_revokers: expected_ar_info_btree};
370+
371+
// Assertions
372+
assert_eq!(result.status, CredentialStatus::Active);
373+
374+
// Assertions for the Credential Iputs returned on the result
375+
match result.inputs {
376+
CredentialsInputs::Identity { ip_info, ars_infos } => {
377+
assert_eq!(ip_info, ip_info_stubbed);
378+
assert_eq!(ars_infos, expected_ar_infos);
379+
},
380+
_ => panic!("we should not reach here, we should have handled inputs realted to identity credentials for this test")
381+
}
382+
383+
}
333384
}

0 commit comments

Comments
 (0)