Skip to content

Commit 5077af2

Browse files
authored
Add local revocation integration test (#123)
* Add local revocation integration test Signed-off-by: Miroslav Kovar <miroslavkovar@protonmail.com> * WIP: Test batch revocation on 3 connections Signed-off-by: Miroslav Kovar <miroslavkovar@protonmail.com> * Use differnt config per consumer Signed-off-by: Miroslav Kovar <miroslavkovar@protonmail.com> * Rename credential_offer to credential_handle Signed-off-by: Miroslav Kovar <miroslavkovar@protonmail.com> * Bump version Signed-off-by: Miroslav Kovar <miroslavkovar@protonmail.com>
1 parent 96d1033 commit 5077af2

File tree

8 files changed

+212
-64
lines changed

8 files changed

+212
-64
lines changed

libvcx/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
name = "libvcx"
4-
version = "0.10.0"
4+
version = "0.11.0"
55
authors = ["Absa Group Limited", "Hyperledger Indy Contributors <hyperledger-indy@lists.hyperledger.org>"]
66
publish = false
77
description = "Absa's fork of HL LibVCX"

libvcx/src/connection.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,15 +295,15 @@ pub mod tests {
295295
handle
296296
}
297297

298-
pub fn create_connected_connections() -> (u32, u32) {
298+
pub fn create_connected_connections(consumer_handle: Option<u32>) -> (u32, u32) {
299299
debug!("Institution is going to create connection.");
300300
::utils::devsetup::set_institution();
301301
let faber_to_alice = create_connection("alice").unwrap();
302302
let _my_public_did = settings::get_config_value(settings::CONFIG_INSTITUTION_DID).unwrap();
303303
let details = connect(faber_to_alice).unwrap().unwrap();
304304
update_state(faber_to_alice).unwrap();
305305

306-
::utils::devsetup::set_consumer();
306+
::utils::devsetup::set_consumer(consumer_handle);
307307
debug!("Consumer is going to accept connection invitation.");
308308
let alice_to_faber = create_connection_with_invite("faber", &details).unwrap();
309309
connect(alice_to_faber).unwrap();
@@ -316,7 +316,7 @@ pub mod tests {
316316
update_state(faber_to_alice).unwrap();
317317

318318
debug!("Consumer is going to complete the connection protocol.");
319-
::utils::devsetup::set_consumer();
319+
::utils::devsetup::set_consumer(consumer_handle);
320320
update_state(alice_to_faber).unwrap();
321321
assert_eq!(VcxStateType::VcxStateAccepted as u32, get_state(alice_to_faber));
322322

@@ -576,13 +576,13 @@ pub mod tests {
576576
#[test]
577577
fn test_send_and_download_messages() {
578578
let _setup = SetupLibraryAgencyV2::init();
579-
let (alice_to_faber, faber_to_alice) = ::connection::tests::create_connected_connections();
579+
let (alice_to_faber, faber_to_alice) = ::connection::tests::create_connected_connections(None);
580580

581581
send_generic_message(faber_to_alice, "Hello Alice", &json!({"msg_type": "toalice", "msg_title": "msg1"}).to_string()).unwrap();
582582
send_generic_message(faber_to_alice, "How are you Alice?", &json!({"msg_type": "toalice", "msg_title": "msg2"}).to_string()).unwrap();
583583

584584
// AS CONSUMER GET MESSAGES
585-
::utils::devsetup::set_consumer();
585+
::utils::devsetup::set_consumer(None);
586586
send_generic_message(alice_to_faber, "Hello Faber", &json!({"msg_type": "tofaber", "msg_title": "msg1"}).to_string()).unwrap();
587587

588588
// make sure messages has bee delivered

libvcx/src/lib.rs

Lines changed: 161 additions & 45 deletions
Large diffs are not rendered by default.

libvcx/src/messages/agent_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ mod tests {
619619
fn test_update_agent_webhook_real() {
620620
let _setup = SetupLibraryAgencyV2::init();
621621

622-
::utils::devsetup::set_consumer();
622+
::utils::devsetup::set_consumer(None);
623623
update_agent_webhook("https://example.org").unwrap();
624624
}
625625
}

libvcx/src/messages/get_message.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ mod tests {
502502
let _setup = SetupLibraryAgencyV2::init();
503503

504504
let institution_did = settings::get_config_value(settings::CONFIG_INSTITUTION_DID).unwrap();
505-
let (_faber, alice) = ::connection::tests::create_connected_connections();
505+
let (_faber, alice) = ::connection::tests::create_connected_connections(None);
506506

507507
let (_, cred_def_handle) = ::credential_def::tests::create_cred_def_real(false);
508508

@@ -521,7 +521,7 @@ mod tests {
521521
let hello_uid = ::connection::send_generic_message(alice, "hello", &json!({"msg_type":"hello", "msg_title": "hello", "ref_msg_id": null}).to_string()).unwrap();
522522

523523
// AS CONSUMER GET MESSAGES
524-
::utils::devsetup::set_consumer();
524+
::utils::devsetup::set_consumer(None);
525525

526526
let _all_messages = download_messages(None, None, None).unwrap();
527527

libvcx/src/messages/update_message.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,14 @@ mod tests {
178178
#[test]
179179
fn test_update_agency_messages() {
180180
let _setup = SetupLibraryAgencyV2::init();
181-
let (_alice_to_faber, faber_to_alice) = ::connection::tests::create_connected_connections();
181+
let (_alice_to_faber, faber_to_alice) = ::connection::tests::create_connected_connections(None);
182182

183183
send_generic_message(faber_to_alice, "Hello 1", &json!({"msg_type": "toalice", "msg_title": "msg1"}).to_string()).unwrap();
184184
send_generic_message(faber_to_alice, "Hello 2", &json!({"msg_type": "toalice", "msg_title": "msg2"}).to_string()).unwrap();
185185
send_generic_message(faber_to_alice, "Hello 3", &json!({"msg_type": "toalice", "msg_title": "msg3"}).to_string()).unwrap();
186186

187187
thread::sleep(Duration::from_millis(1000));
188-
::utils::devsetup::set_consumer();
188+
::utils::devsetup::set_consumer(None);
189189

190190
let received = download_messages(None, Some(vec![MessageStatusCode::Received.to_string()]), None).unwrap();
191191
assert_eq!(received.len(), 1);

libvcx/src/object_cache/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ impl<T> ObjectCache<T> {
100100
let mut store = self._lock_store()?;
101101
Ok(store.clear())
102102
}
103+
104+
pub fn len(&self) -> VcxResult<usize> {
105+
let store = self._lock_store()?;
106+
Ok(store.len())
107+
}
103108
}
104109

105110
#[cfg(test)]

libvcx/src/utils/devsetup.rs

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,10 @@ macro_rules! assert_match {
373373
);
374374
}
375375

376+
// TODO: We could have an array of configs
376377
static mut INSTITUTION_CONFIG: u32 = 0;
377378
static mut CONSUMER_CONFIG: u32 = 0;
379+
// static mut CONFIGS: Vec<u32> = Vec::new(); // Vector of handles
378380

379381
lazy_static! {
380382
static ref CONFIG_STRING: ObjectCache<String> = ObjectCache::<String>::new("devsetup-config-cache");
@@ -467,7 +469,7 @@ pub fn cleanup_agency_env() {
467469
set_institution();
468470
delete_wallet(&settings::get_wallet_name().unwrap(), None, None, None).unwrap();
469471

470-
set_consumer();
472+
set_consumer(None);
471473
delete_wallet(&settings::get_wallet_name().unwrap(), None, None, None).unwrap();
472474

473475
delete_test_pool();
@@ -486,10 +488,11 @@ pub fn set_institution() {
486488
change_wallet_handle();
487489
}
488490

489-
pub fn set_consumer() {
491+
pub fn set_consumer(consumer_handle: Option<u32>) {
490492
settings::clear_config();
493+
info!("Using consumer handle: {:?}", consumer_handle);
491494
unsafe {
492-
CONFIG_STRING.get(CONSUMER_CONFIG, |t| {
495+
CONFIG_STRING.get(consumer_handle.unwrap_or(CONSUMER_CONFIG), |t| {
493496
warn!("Setting consumer config {}", t);
494497
settings::set_config_value(settings::CONFIG_PAYMENT_METHOD, settings::DEFAULT_PAYMENT_METHOD);
495498
let result = settings::process_config_string(&t, true);
@@ -571,9 +574,8 @@ pub fn setup_agency_env(protocol_type: &str, use_zero_fees: bool) {
571574
settings::set_config_value(settings::CONFIG_GENESIS_PATH, utils::get_temp_dir_path(settings::DEFAULT_GENESIS_PATH).to_str().unwrap());
572575
open_test_pool();
573576

574-
575577
// grab the generated did and vk from the consumer and enterprise
576-
set_consumer();
578+
set_consumer(None);
577579
let did2 = settings::get_config_value(settings::CONFIG_INSTITUTION_DID).unwrap();
578580
let vk2 = settings::get_config_value(settings::CONFIG_INSTITUTION_VERKEY).unwrap();
579581
set_institution();
@@ -591,7 +593,7 @@ pub fn setup_agency_env(protocol_type: &str, use_zero_fees: bool) {
591593
wallet::delete_wallet(settings::DEFAULT_WALLET_NAME, None, None, None).unwrap();
592594

593595
// as trustees, mint tokens into each wallet
594-
set_consumer();
596+
set_consumer(None);
595597
::utils::libindy::payments::tests::token_setup(None, None, use_zero_fees);
596598

597599
set_institution();
@@ -605,6 +607,31 @@ pub fn config_with_wallet_handle(wallet_n: &str, config: &str) -> String {
605607
config.to_string()
606608
}
607609

610+
pub fn create_consumer_config() -> u32 {
611+
let consumer_id: u32 = CONFIG_STRING.len().unwrap() as u32;
612+
let consumer_wallet_name = format!("{}_{}", constants::CONSUMER_PREFIX, consumer_id);
613+
let seed = create_new_seed();
614+
let config = json!({
615+
"agency_url": C_AGENCY_ENDPOINT.to_string(),
616+
"agency_did": C_AGENCY_DID.to_string(),
617+
"agency_verkey": C_AGENCY_VERKEY.to_string(),
618+
"wallet_name": consumer_wallet_name,
619+
"wallet_key": settings::DEFAULT_WALLET_KEY.to_string(),
620+
"wallet_key_derivation": settings::DEFAULT_WALLET_KEY_DERIVATION.to_string(),
621+
"enterprise_seed": seed,
622+
"agent_seed": seed,
623+
"name": format!("consumer_{}", consumer_id).to_string(),
624+
"logo": "http://www.logo.com".to_string(),
625+
"path": constants::GENESIS_PATH.to_string(),
626+
"protocol_type": "4.0"
627+
});
628+
629+
debug!("setup_agency_env >> Going to provision consumer using config: {:?}", &config);
630+
let consumer_config = ::messages::agent_utils::connect_register_provision(&config.to_string()).unwrap();
631+
632+
CONFIG_STRING.add(config_with_wallet_handle(&consumer_wallet_name, &consumer_config.to_string())).unwrap()
633+
}
634+
608635
pub fn setup_wallet_env(test_name: &str) -> Result<WalletHandle, String> {
609636
settings::set_config_value(settings::CONFIG_ENABLE_TEST_MODE, "false");
610637
init_wallet(test_name, None, None, None).map_err(|e| format!("Unable to init_wallet in tests: {}", e))
@@ -656,7 +683,7 @@ mod tests {
656683
pub fn test_two_enterprise_connections() {
657684
let _setup = SetupLibraryAgencyV2ZeroFees::init();
658685

659-
let (_faber, _alice) = ::connection::tests::create_connected_connections();
660-
let (_faber, _alice) = ::connection::tests::create_connected_connections();
686+
let (_faber, _alice) = ::connection::tests::create_connected_connections(None);
687+
let (_faber, _alice) = ::connection::tests::create_connected_connections(None);
661688
}
662689
}

0 commit comments

Comments
 (0)