Skip to content

Commit

Permalink
Add local revocation integration test (#123)
Browse files Browse the repository at this point in the history
* Add local revocation integration test

Signed-off-by: Miroslav Kovar <[email protected]>

* WIP: Test batch revocation on 3 connections

Signed-off-by: Miroslav Kovar <[email protected]>

* Use differnt config per consumer

Signed-off-by: Miroslav Kovar <[email protected]>

* Rename credential_offer to credential_handle

Signed-off-by: Miroslav Kovar <[email protected]>

* Bump version

Signed-off-by: Miroslav Kovar <[email protected]>
  • Loading branch information
mirgee authored Oct 2, 2020
1 parent 96d1033 commit 5077af2
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 64 deletions.
2 changes: 1 addition & 1 deletion libvcx/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "libvcx"
version = "0.10.0"
version = "0.11.0"
authors = ["Absa Group Limited", "Hyperledger Indy Contributors <[email protected]>"]
publish = false
description = "Absa's fork of HL LibVCX"
Expand Down
10 changes: 5 additions & 5 deletions libvcx/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,15 @@ pub mod tests {
handle
}

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

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

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

Expand Down Expand Up @@ -576,13 +576,13 @@ pub mod tests {
#[test]
fn test_send_and_download_messages() {
let _setup = SetupLibraryAgencyV2::init();
let (alice_to_faber, faber_to_alice) = ::connection::tests::create_connected_connections();
let (alice_to_faber, faber_to_alice) = ::connection::tests::create_connected_connections(None);

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

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

// make sure messages has bee delivered
Expand Down
206 changes: 161 additions & 45 deletions libvcx/src/lib.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion libvcx/src/messages/agent_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ mod tests {
fn test_update_agent_webhook_real() {
let _setup = SetupLibraryAgencyV2::init();

::utils::devsetup::set_consumer();
::utils::devsetup::set_consumer(None);
update_agent_webhook("https://example.org").unwrap();
}
}
4 changes: 2 additions & 2 deletions libvcx/src/messages/get_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ mod tests {
let _setup = SetupLibraryAgencyV2::init();

let institution_did = settings::get_config_value(settings::CONFIG_INSTITUTION_DID).unwrap();
let (_faber, alice) = ::connection::tests::create_connected_connections();
let (_faber, alice) = ::connection::tests::create_connected_connections(None);

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

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

// AS CONSUMER GET MESSAGES
::utils::devsetup::set_consumer();
::utils::devsetup::set_consumer(None);

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

Expand Down
4 changes: 2 additions & 2 deletions libvcx/src/messages/update_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,14 @@ mod tests {
#[test]
fn test_update_agency_messages() {
let _setup = SetupLibraryAgencyV2::init();
let (_alice_to_faber, faber_to_alice) = ::connection::tests::create_connected_connections();
let (_alice_to_faber, faber_to_alice) = ::connection::tests::create_connected_connections(None);

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

thread::sleep(Duration::from_millis(1000));
::utils::devsetup::set_consumer();
::utils::devsetup::set_consumer(None);

let received = download_messages(None, Some(vec![MessageStatusCode::Received.to_string()]), None).unwrap();
assert_eq!(received.len(), 1);
Expand Down
5 changes: 5 additions & 0 deletions libvcx/src/object_cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ impl<T> ObjectCache<T> {
let mut store = self._lock_store()?;
Ok(store.clear())
}

pub fn len(&self) -> VcxResult<usize> {
let store = self._lock_store()?;
Ok(store.len())
}
}

#[cfg(test)]
Expand Down
43 changes: 35 additions & 8 deletions libvcx/src/utils/devsetup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,10 @@ macro_rules! assert_match {
);
}

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

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

set_consumer();
set_consumer(None);
delete_wallet(&settings::get_wallet_name().unwrap(), None, None, None).unwrap();

delete_test_pool();
Expand All @@ -486,10 +488,11 @@ pub fn set_institution() {
change_wallet_handle();
}

pub fn set_consumer() {
pub fn set_consumer(consumer_handle: Option<u32>) {
settings::clear_config();
info!("Using consumer handle: {:?}", consumer_handle);
unsafe {
CONFIG_STRING.get(CONSUMER_CONFIG, |t| {
CONFIG_STRING.get(consumer_handle.unwrap_or(CONSUMER_CONFIG), |t| {
warn!("Setting consumer config {}", t);
settings::set_config_value(settings::CONFIG_PAYMENT_METHOD, settings::DEFAULT_PAYMENT_METHOD);
let result = settings::process_config_string(&t, true);
Expand Down Expand Up @@ -571,9 +574,8 @@ pub fn setup_agency_env(protocol_type: &str, use_zero_fees: bool) {
settings::set_config_value(settings::CONFIG_GENESIS_PATH, utils::get_temp_dir_path(settings::DEFAULT_GENESIS_PATH).to_str().unwrap());
open_test_pool();


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

// as trustees, mint tokens into each wallet
set_consumer();
set_consumer(None);
::utils::libindy::payments::tests::token_setup(None, None, use_zero_fees);

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

pub fn create_consumer_config() -> u32 {
let consumer_id: u32 = CONFIG_STRING.len().unwrap() as u32;
let consumer_wallet_name = format!("{}_{}", constants::CONSUMER_PREFIX, consumer_id);
let seed = create_new_seed();
let config = json!({
"agency_url": C_AGENCY_ENDPOINT.to_string(),
"agency_did": C_AGENCY_DID.to_string(),
"agency_verkey": C_AGENCY_VERKEY.to_string(),
"wallet_name": consumer_wallet_name,
"wallet_key": settings::DEFAULT_WALLET_KEY.to_string(),
"wallet_key_derivation": settings::DEFAULT_WALLET_KEY_DERIVATION.to_string(),
"enterprise_seed": seed,
"agent_seed": seed,
"name": format!("consumer_{}", consumer_id).to_string(),
"logo": "http://www.logo.com".to_string(),
"path": constants::GENESIS_PATH.to_string(),
"protocol_type": "4.0"
});

debug!("setup_agency_env >> Going to provision consumer using config: {:?}", &config);
let consumer_config = ::messages::agent_utils::connect_register_provision(&config.to_string()).unwrap();

CONFIG_STRING.add(config_with_wallet_handle(&consumer_wallet_name, &consumer_config.to_string())).unwrap()
}

pub fn setup_wallet_env(test_name: &str) -> Result<WalletHandle, String> {
settings::set_config_value(settings::CONFIG_ENABLE_TEST_MODE, "false");
init_wallet(test_name, None, None, None).map_err(|e| format!("Unable to init_wallet in tests: {}", e))
Expand Down Expand Up @@ -656,7 +683,7 @@ mod tests {
pub fn test_two_enterprise_connections() {
let _setup = SetupLibraryAgencyV2ZeroFees::init();

let (_faber, _alice) = ::connection::tests::create_connected_connections();
let (_faber, _alice) = ::connection::tests::create_connected_connections();
let (_faber, _alice) = ::connection::tests::create_connected_connections(None);
let (_faber, _alice) = ::connection::tests::create_connected_connections(None);
}
}

0 comments on commit 5077af2

Please sign in to comment.