Skip to content

Commit

Permalink
Lower log levels, reset global state after test instead of before
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Stas <patrik.stas@absa.africa>
  • Loading branch information
Patrik-Stas committed Jul 20, 2022
1 parent ee24632 commit 7c27607
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 29 deletions.
12 changes: 6 additions & 6 deletions aries_vcx/src/libindy/utils/anoncreds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ pub async fn build_cred_def_request(issuer_did: &str, cred_def_json: &str) -> Vc
pub async fn publish_cred_def(issuer_did: &str, cred_def_json: &str) -> VcxResult<()> {
trace!("publish_cred_def >>> issuer_did: {}, cred_def_json: {}", issuer_did, cred_def_json);
if settings::indy_mocks_enabled() {
warn!("publish_cred_def >>> mocked success");
debug!("publish_cred_def >>> mocked success");
return Ok(());
}
let cred_def_req = build_cred_def_request(issuer_did, &cred_def_json).await?;
Expand All @@ -498,7 +498,7 @@ pub async fn publish_cred_def(issuer_did: &str, cred_def_json: &str) -> VcxResul

pub async fn get_cred_def_json(cred_def_id: &str) -> VcxResult<(String, String)> {
if settings::indy_mocks_enabled() {
warn!("get_cred_def_json >>> returning mocked value");
debug!("get_cred_def_json >>> returning mocked value");
return Ok((CRED_DEF_ID.to_string(), CRED_DEF_JSON.to_string()));
}

Expand All @@ -511,7 +511,7 @@ pub async fn generate_rev_reg(issuer_did: &str, cred_def_id: &str, tails_dir: &s
-> VcxResult<(String, RevocationRegistryDefinition, String)> {
trace!("generate_rev_reg >>> issuer_did: {}, cred_def_id: {}, tails_file: {}, max_creds: {}, tag: {}", issuer_did, cred_def_id, tails_dir, max_creds, tag);
if settings::indy_mocks_enabled() {
warn!("generate_rev_reg >>> returning mocked value");
debug!("generate_rev_reg >>> returning mocked value");
return Ok((REV_REG_ID.to_string(), RevocationRegistryDefinition::default(), "".to_string()));
}

Expand All @@ -530,7 +530,7 @@ pub async fn generate_rev_reg(issuer_did: &str, cred_def_id: &str, tails_dir: &s

pub async fn build_rev_reg_request(issuer_did: &str, rev_reg_def_json: &str) -> VcxResult<String> {
if settings::indy_mocks_enabled() {
warn!("build_rev_reg_request >>> returning mocked value");
debug!("build_rev_reg_request >>> returning mocked value");
return Ok("".to_string());
}

Expand All @@ -542,7 +542,7 @@ pub async fn build_rev_reg_request(issuer_did: &str, rev_reg_def_json: &str) ->
pub async fn publish_rev_reg_def(issuer_did: &str, rev_reg_def: &RevocationRegistryDefinition) -> VcxResult<()> {
trace!("publish_rev_reg_def >>> issuer_did: {}, rev_reg_def: ...", issuer_did);
if settings::indy_mocks_enabled() {
warn!("publish_rev_reg_def >>> mocked success");
debug!("publish_rev_reg_def >>> mocked success");
return Ok(());
}

Expand All @@ -555,7 +555,7 @@ pub async fn publish_rev_reg_def(issuer_did: &str, rev_reg_def: &RevocationRegis

pub async fn get_rev_reg_def_json(rev_reg_id: &str) -> VcxResult<(String, String)> {
if settings::indy_mocks_enabled() {
warn!("get_rev_reg_def_json >>> returning mocked value");
debug!("get_rev_reg_def_json >>> returning mocked value");
return Ok((REV_REG_ID.to_string(), rev_def_json()));
}

Expand Down
6 changes: 3 additions & 3 deletions aries_vcx/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ pub fn set_testing_defaults() -> u32 {
}

pub fn enable_indy_mocks() -> VcxResult<()> {
warn!("enable_indy_mocks >>>");
debug!("enable_indy_mocks >>>");
set_config_value(CONFIG_ENABLE_TEST_MODE, "true")
}

pub fn disable_indy_mocks() -> VcxResult<()> {
warn!("disable_indy_mocks >>>");
debug!("disable_indy_mocks >>>");
set_config_value(CONFIG_ENABLE_TEST_MODE, "false")
}

Expand All @@ -110,7 +110,7 @@ pub fn indy_mocks_enabled() -> bool {
match config.get(CONFIG_ENABLE_TEST_MODE) {
None => false,
Some(value) => {
warn!("indy_mocks_enabled >>> {}", value);
debug!("indy_mocks_enabled >>> {}", value);
value == "true" || value == "indy"
}
}
Expand Down
2 changes: 1 addition & 1 deletion aries_vcx/src/utils/author_agreement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ mod tests {
#[test]
#[cfg(feature = "general_test")]
fn get_txn_author_agreement_works_for_not_set() {
let _setup = SetupDefaults::init();
let setup = SetupDefaults::init();

assert!(get_txn_author_agreement().unwrap().is_none());
}
Expand Down
60 changes: 41 additions & 19 deletions aries_vcx/src/utils/devsetup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ fn reset_global_state() {
AgencyMockDecrypted::clear_mocks();
PoolMocks::clear_mocks();
DidMocks::clear_mocks();
set_testing_defaults();
reset_main_wallet_handle().unwrap();
reset_pool_handle();
disable_indy_mocks();
Expand All @@ -68,38 +67,53 @@ fn reset_global_state() {
}

impl SetupEmpty {
pub fn init() {
pub fn init() -> SetupEmpty {
init_test_logging();
SetupEmpty {}
}
}

impl Drop for SetupEmpty {
fn drop(&mut self) {
reset_global_state();
}
}

impl SetupDefaults {
pub fn init() {
pub fn init() -> SetupDefaults {
init_test_logging();
reset_global_state();

set_testing_defaults();
SetupDefaults {}
}
}

impl Drop for SetupDefaults {
fn drop(&mut self) {
reset_global_state();
}
}

impl SetupMocks {
pub fn init() -> SetupMocks {
init_test_logging();
reset_global_state();

set_testing_defaults();
settings::get_agency_client_mut().unwrap().enable_test_mode();
enable_indy_mocks();
SetupMocks {} // todo: not needed since we don't implement drop
}
}

impl Drop for SetupMocks {
fn drop(&mut self) {
reset_global_state();
}
}


impl SetupLibraryWallet {
pub async fn init() -> SetupLibraryWallet {
init_test_logging();
warn!("SetupLibraryWallet::init >>");
reset_global_state();
debug!("SetupLibraryWallet::init >>");
set_testing_defaults();
let wallet_name: String = format!("Test_SetupLibraryWallet_{}", uuid::Uuid::new_v4().to_string());
let wallet_key: String = settings::DEFAULT_WALLET_KEY.into();
Expand All @@ -124,14 +138,13 @@ impl Drop for SetupLibraryWallet {
fn drop(&mut self) {
let _res = futures::executor::block_on(close_main_wallet()).unwrap();
futures::executor::block_on(delete_wallet(&self.wallet_config)).unwrap();
reset_global_state();
}
}

impl SetupWallet {
pub async fn init() -> SetupWallet {
init_test_logging();
reset_global_state();

set_testing_defaults();
let wallet_name: String = format!("Test_SetupWallet_{}", uuid::Uuid::new_v4().to_string());
settings::get_agency_client_mut().unwrap().disable_test_mode();
Expand Down Expand Up @@ -162,13 +175,13 @@ impl Drop for SetupWallet {
let _res = futures::executor::block_on(close_main_wallet()).unwrap_or_else(|_e| error!("Failed to close main wallet while dropping SetupWallet test config."));
futures::executor::block_on(delete_wallet(&self.wallet_config)).unwrap_or_else(|_e| error!("Failed to delete wallet while dropping SetupWallet test config."));
}
reset_global_state();
}
}

impl SetupPoolConfig {
pub async fn init() -> SetupPoolConfig {
init_test_logging();
reset_global_state();

create_test_ledger_config().await;
let genesis_path = utils::get_temp_dir_path(settings::DEFAULT_GENESIS_PATH).to_str().unwrap().to_string();
Expand All @@ -193,35 +206,43 @@ impl Drop for SetupPoolConfig {
futures::executor::block_on(delete_test_pool());
reset_pool_handle();
}
reset_global_state();
}
}

impl SetupPoolMocks {
pub async fn init() -> SetupPoolMocks {
init_test_logging();
reset_global_state();

setup_indy_env().await;
enable_pool_mocks();
SetupPoolMocks {}
}
}

impl Drop for SetupPoolMocks {
fn drop(&mut self) {
reset_global_state();
}
}

impl SetupIndyMocks {
pub fn init() -> SetupIndyMocks {
init_test_logging();
reset_global_state();

enable_indy_mocks();
settings::get_agency_client_mut().unwrap().enable_test_mode();
SetupIndyMocks {}
}
}

impl Drop for SetupIndyMocks {
fn drop(&mut self) {
reset_global_state();
}
}

impl SetupWithWalletAndAgency {
pub async fn init() -> SetupWithWalletAndAgency {
init_test_logging();
reset_global_state();
set_testing_defaults();

let institution_did = setup_indy_env().await;
Expand All @@ -237,13 +258,13 @@ impl SetupWithWalletAndAgency {
impl Drop for SetupWithWalletAndAgency {
fn drop(&mut self) {
futures::executor::block_on(delete_test_pool());
reset_global_state();
}
}

impl SetupAgencyMock {
pub async fn init() -> SetupAgencyMock {
init_test_logging();
reset_global_state();

let wallet_name: String = format!("Test_SetupWalletAndPool_{}", uuid::Uuid::new_v4().to_string());
settings::get_agency_client_mut().unwrap().enable_test_mode();
Expand All @@ -267,14 +288,14 @@ impl Drop for SetupAgencyMock {
fn drop(&mut self) {
let _res = futures::executor::block_on(close_main_wallet()).unwrap();
futures::executor::block_on(delete_wallet(&self.wallet_config)).unwrap();
reset_global_state();
}
}

impl SetupLibraryAgencyV2 {
pub async fn init() -> SetupLibraryAgencyV2 {
debug!("SetupLibraryAgencyV2 init >> going to setup agency environment");
init_test_logging();
reset_global_state();

settings::set_config_value(settings::CONFIG_GENESIS_PATH, utils::get_temp_dir_path(settings::DEFAULT_GENESIS_PATH).to_str().unwrap());
open_test_pool().await;
Expand All @@ -286,6 +307,7 @@ impl SetupLibraryAgencyV2 {
impl Drop for SetupLibraryAgencyV2 {
fn drop(&mut self) {
futures::executor::block_on(delete_test_pool());
reset_global_state();
}
}

Expand Down

0 comments on commit 7c27607

Please sign in to comment.