Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #209 from Artemkaaas/bugnix/build-nym-request
Browse files Browse the repository at this point in the history
Added TRUST_ANCHOR Role in Libindy
  • Loading branch information
jovfer authored Aug 22, 2017
2 parents 85dbbd7 + 5d086de commit c8e8064
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions libindy/src/services/ledger/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
5 changes: 3 additions & 2 deletions libindy/src/services/ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions libindy/src/services/ledger/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use services::ledger::constants::{
GET_CLAIM_DEF,
STEWARD,
TRUSTEE,
TRUST_ANCHOR,
GET_TXN
};

Expand Down Expand Up @@ -43,8 +44,9 @@ impl<T: JsonEncodable> JsonEncodable for Request<T> {}

#[derive(Deserialize, Serialize, PartialEq, Debug)]
pub enum Role {
STEWARD = STEWARD,
TRUSTEE = TRUSTEE
Steward = STEWARD,
Trustee = TRUSTEE,
TrustAnchor = TRUST_ANCHOR
}

#[derive(Serialize, PartialEq, Debug)]
Expand Down
32 changes: 31 additions & 1 deletion libindy/tests/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit c8e8064

Please sign in to comment.