use std::time::Duration; use credo::{ClaimBody, Credential, Credo, PermissionKind, SimpleCredentialSource}; use futures::{future, FutureExt, StreamExt}; use litl::json; use mofo::Mofo; macro_rules! timeout { ($f:expr) => { tokio::time::timeout(Duration::from_millis(500), $f).map(|r| r.expect("Timed out")) }; } #[tokio::test] async fn can_revoke_own_statement() { // traceful::init_test(); let background = Mofo::new(); let credo = Credo::new("credo".to_string(), background.clone()); background .run_until(async { let initial_recipient = Credential::new_random(); let credential_source = Box::new(SimpleCredentialSource::new()); let scope = credo .create_scope( initial_recipient, vec![PermissionKind::MakeStatement { path_prefix: "test".to_string(), }], None, credential_source ) .await; let updates = scope.updates( "test".to_owned()); let mut updates = updates.skip_while(|s| future::ready(s.valid_claims.len() < 8)); assert_eq!( timeout!(updates.next()).await.unwrap().valid_claims.len(), 8 ); let claim_id = scope .make_claim_after( ClaimBody::Statement { path: "test".to_string(), value: json!("hello world").into(), }, vec![], ) .await .unwrap(); let valid_claims = timeout!(updates.next()).await.unwrap().valid_claims; assert_eq!(valid_claims.len(), 9); assert!(valid_claims.contains_key(&claim_id)); assert_eq!( valid_claims.get(&claim_id).unwrap().0.body, ClaimBody::Statement { path: "test".to_string(), value: json!("hello world").into(), } ); let revocation_id = scope .make_claim_after( ClaimBody::Revocation { revoked_claim_id: claim_id, as_of: ti64::now(), }, vec![], ) .await .unwrap(); let valid_claims = timeout!(updates.next()).await.unwrap().valid_claims; assert_eq!(valid_claims.len(), 9); assert!(!valid_claims.contains_key(&claim_id)); assert!(valid_claims.contains_key(&revocation_id)); }) .await; }