diff --git a/libindy/src/services/ledger/constants.rs b/libindy/src/services/ledger/constants.rs index 1bf8145391..7c7cf6f879 100644 --- a/libindy/src/services/ledger/constants.rs +++ b/libindy/src/services/ledger/constants.rs @@ -12,3 +12,4 @@ pub const GET_DDO: &'static str = "120";//TODO change number pub const STEWARD: isize = 2; pub const TRUSTEE: isize = 0; +pub const TRUST_ANCHOR: isize = 101; diff --git a/libindy/src/services/ledger/mod.rs b/libindy/src/services/ledger/mod.rs index 1038df814b..f9381dc29a 100644 --- a/libindy/src/services/ledger/mod.rs +++ b/libindy/src/services/ledger/mod.rs @@ -49,8 +49,9 @@ impl LedgerService { let role = match role { Some(r) => match r.clone() { - "STEWARD" => Some(Role::STEWARD as i32), - "TRUSTEE" => Some(Role::TRUSTEE as i32), + "STEWARD" => Some(Role::Steward as i32), + "TRUSTEE" => Some(Role::Trustee as i32), + "TRUST_ANCHOR" => Some(Role::TrustAnchor as i32), role @ _ => return Err(CommonError::InvalidStructure(format!("Invalid role: {}", role))) }, _ => None diff --git a/libindy/src/services/ledger/types.rs b/libindy/src/services/ledger/types.rs index 884c2da334..00424d760e 100644 --- a/libindy/src/services/ledger/types.rs +++ b/libindy/src/services/ledger/types.rs @@ -15,6 +15,7 @@ use services::ledger::constants::{ GET_CLAIM_DEF, STEWARD, TRUSTEE, + TRUST_ANCHOR, GET_TXN }; @@ -43,8 +44,9 @@ impl JsonEncodable for Request {} #[derive(Deserialize, Serialize, PartialEq, Debug)] pub enum Role { - STEWARD = STEWARD, - TRUSTEE = TRUSTEE + Steward = STEWARD, + Trustee = TRUSTEE, + TrustAnchor = TRUST_ANCHOR } #[derive(Serialize, PartialEq, Debug)] diff --git a/libindy/tests/ledger.rs b/libindy/tests/ledger.rs index 3e6e7a35ee..24c7373658 100644 --- a/libindy/tests/ledger.rs +++ b/libindy/tests/ledger.rs @@ -39,7 +39,7 @@ use utils::types::{ GetTxnResult, SchemaData }; -use std::collections::{HashSet}; +use std::collections::HashSet; // TODO: FIXME: create_my_did doesn't support CID creation, but this trustee has CID as DID. So it is rough workaround for this issue. // See: https://github.com/hyperledger/indy-sdk/issues/25 @@ -1012,6 +1012,36 @@ mod medium_cases { TestUtils::cleanup_storage(); } + #[test] + #[cfg(feature = "local_nodes_pool")] + fn indy_send_nym_request_works_for_different_roles() { + TestUtils::cleanup_storage(); + + let pool_name = "indy_send_nym_request_works_for_different_roles"; + + let pool_handle = PoolUtils::create_and_open_pool_ledger(pool_name).unwrap(); + let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); + + let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); + + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, None).unwrap(); + let role = "STEWARD"; + let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), None, None, Some(role)).unwrap(); + LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &trustee_did, &nym_request).unwrap(); + + let (my_did2, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, None).unwrap(); + let role = "TRUSTEE"; + let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did2.clone(), None, None, Some(role)).unwrap(); + LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &trustee_did, &nym_request).unwrap(); + + let (my_did3, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, None).unwrap(); + let role = "TRUST_ANCHOR"; + let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did3.clone(), None, None, Some(role)).unwrap(); + LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &trustee_did, &nym_request).unwrap(); + + TestUtils::cleanup_storage(); + } + #[test] #[cfg(feature = "local_nodes_pool")] fn indy_build_nym_requests_works_for_wrong_role() {