diff --git a/Cargo.toml b/Cargo.toml index e5a631aca0..181b4fabb0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,7 @@ local_nodes_pool = [] [dependencies] int_traits = { version = "0.1.1", optional = true } env_logger = "0.4.2" +hex = "0.2.0" libc = "0.2.21" log = "0.3.7" openssl = { version = "0.9.11", optional = true } diff --git a/src/api/ledger.rs b/src/api/ledger.rs index d03a7d895d..83a1da7afa 100644 --- a/src/api/ledger.rs +++ b/src/api/ledger.rs @@ -357,6 +357,7 @@ pub extern fn sovrin_build_schema_request(command_handle: i32, /// #Params /// command_handle: command handle to map callback to caller context. /// submitter_did: Id of Identity stored in secured Wallet. +/// dest: Id of Identity stored in secured Wallet. /// data: name, version /// cb: Callback that takes command result as parameter. /// @@ -368,16 +369,19 @@ pub extern fn sovrin_build_schema_request(command_handle: i32, #[no_mangle] pub extern fn sovrin_build_get_schema_request(command_handle: i32, submitter_did: *const c_char, + dest: *const c_char, data: *const c_char, cb: Option) -> ErrorCode { check_useful_c_str!(submitter_did, ErrorCode::CommonInvalidParam2); - check_useful_c_str!(data, ErrorCode::CommonInvalidParam3); - check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam4); + check_useful_c_str!(dest, ErrorCode::CommonInvalidParam3); + check_useful_c_str!(data, ErrorCode::CommonInvalidParam4); + check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam5); let result = CommandExecutor::instance() .send(Command::Ledger(LedgerCommand::BuildGetSchemaRequest( submitter_did, + dest, data, Box::new(move |result| { let (err, request_json) = result_to_err_code_1!(result, String::new()); @@ -406,13 +410,12 @@ pub extern fn sovrin_build_get_schema_request(command_handle: i32, #[no_mangle] pub extern fn sovrin_build_claim_def_txn(command_handle: i32, submitter_did: *const c_char, - xref: *const c_char, + xref: i32, signature_type: *const c_char, data: *const c_char, cb: Option) -> ErrorCode { check_useful_c_str!(submitter_did, ErrorCode::CommonInvalidParam2); - check_useful_c_str!(xref, ErrorCode::CommonInvalidParam3); check_useful_c_str!(signature_type, ErrorCode::CommonInvalidParam4); check_useful_c_str!(data, ErrorCode::CommonInvalidParam5); check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam6); @@ -440,6 +443,7 @@ pub extern fn sovrin_build_claim_def_txn(command_handle: i32, /// submitter_did: Id of Identity stored in secured Wallet. /// xref: Seq. number of schema /// signature_type: signature type (only CL supported now) +/// origin /// cb: Callback that takes command result as parameter. /// /// #Returns @@ -450,20 +454,22 @@ pub extern fn sovrin_build_claim_def_txn(command_handle: i32, #[no_mangle] pub extern fn sovrin_build_get_claim_def_txn(command_handle: i32, submitter_did: *const c_char, - xref: *const c_char, + xref: i32, signature_type: *const c_char, + origin: *const c_char, cb: Option) -> ErrorCode { check_useful_c_str!(submitter_did, ErrorCode::CommonInvalidParam2); - check_useful_c_str!(xref, ErrorCode::CommonInvalidParam3); check_useful_c_str!(signature_type, ErrorCode::CommonInvalidParam4); - check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam5); + check_useful_c_str!(origin, ErrorCode::CommonInvalidParam4); + check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam6); let result = CommandExecutor::instance() .send(Command::Ledger(LedgerCommand::BuildGetClaimDefRequest( submitter_did, xref, signature_type, + origin, Box::new(move |result| { let (err, request_json) = result_to_err_code_1!(result, String::new()); let request_json = CStringUtils::string_to_cstring(request_json); diff --git a/src/api/signus.rs b/src/api/signus.rs index 47a45b5e94..67d24a1768 100644 --- a/src/api/signus.rs +++ b/src/api/signus.rs @@ -19,11 +19,14 @@ use self::libc::c_char; /// command_handle: command handle to map callback to user context. /// did_json: Identity information as json. Example: /// { -/// "did": string, (optional; if not provided then the first 16 bit of the verkey will be used -/// as a new DID; if provided, then keys will be replaced - key rotation use case) +/// "did": string, (optional; +/// if not provided and cid param is false then the first 16 bit of the verkey will be used as a new DID; +/// if not provided and cid is true then the full verkey will be used as a new DID; +/// if provided, then keys will be replaced - key rotation use case) /// "seed": string, (optional; if not provide then a random one will be created) /// "crypto_type": string, (optional; if not set then ed25519 curve is used; /// currently only 'ed25519' value is supported for this field) +/// "cid": string, (optional; if not set then false is used;) /// } /// cb: Callback that takes command result as parameter. /// diff --git a/src/commands/ledger.rs b/src/commands/ledger.rs index 5781b81346..07c3b3978b 100644 --- a/src/commands/ledger.rs +++ b/src/commands/ledger.rs @@ -66,18 +66,20 @@ pub enum LedgerCommand { Box) + Send>), BuildGetSchemaRequest( String, // submitter did + String, // dest String, // data Box) + Send>), BuildClaimDefRequest( String, // submitter did - String, // xref + i32, // xref String, // signature_type String, // data Box) + Send>), BuildGetClaimDefRequest( String, // submitter did - String, // xref + i32, // xref String, // signature_type + String, // origin Box) + Send>), BuildNodeRequest( String, // submitter did @@ -161,17 +163,17 @@ impl LedgerCommandExecutor { info!(target: "ledger_command_executor", "BuildSchemaRequest command received"); self.build_schema_request(&submitter_did, &data, cb); } - LedgerCommand::BuildGetSchemaRequest(submitter_did, data, cb) => { + LedgerCommand::BuildGetSchemaRequest(submitter_did, dest, data, cb) => { info!(target: "ledger_command_executor", "BuildGetSchemaRequest command received"); - self.build_get_schema_request(&submitter_did, &data, cb); + self.build_get_schema_request(&submitter_did, &dest, &data, cb); } LedgerCommand::BuildClaimDefRequest(submitter_did, xref, signature_type, data, cb) => { info!(target: "ledger_command_executor", "BuildClaimDefRequest command received"); - self.build_claim_def_request(&submitter_did, &xref, &signature_type, &data, cb); + self.build_claim_def_request(&submitter_did, xref, &signature_type, &data, cb); } - LedgerCommand::BuildGetClaimDefRequest(submitter_did, xref, signature_type, cb) => { + LedgerCommand::BuildGetClaimDefRequest(submitter_did, xref, signature_type, origin, cb) => { info!(target: "ledger_command_executor", "BuildGetClaimDefRequest command received"); - self.build_get_claim_def_request(&submitter_did, &xref, &signature_type, cb); + self.build_get_claim_def_request(&submitter_did, xref, &signature_type, &origin, cb); } LedgerCommand::BuildNodeRequest(submitter_did, target_did, data, cb) => { info!(target: "ledger_command_executor", "BuildNodeRequest command received"); @@ -298,16 +300,18 @@ impl LedgerCommandExecutor { fn build_get_schema_request(&self, submitter_did: &str, + dest: &str, data: &str, cb: Box) + Send>) { cb(self.ledger_service.build_get_schema_request(submitter_did, + dest, data ).map_err(|err| SovrinError::CommonError(err))) } fn build_claim_def_request(&self, submitter_did: &str, - xref: &str, + xref: i32, signature_type: &str, data: &str, cb: Box) + Send>) { @@ -320,12 +324,14 @@ impl LedgerCommandExecutor { fn build_get_claim_def_request(&self, submitter_did: &str, - xref: &str, + xref: i32, signature_type: &str, + origin: &str, cb: Box) + Send>) { cb(self.ledger_service.build_get_claim_def_request(submitter_did, xref, - signature_type + signature_type, + origin ).map_err(|err| SovrinError::CommonError(err))) } diff --git a/src/commands/signus.rs b/src/commands/signus.rs index dc5213de7c..67ee512013 100644 --- a/src/commands/signus.rs +++ b/src/commands/signus.rs @@ -174,7 +174,7 @@ impl SignusCommandExecutor { let identity_info: MyIdentityInfo = MyIdentityInfo::from_json(identity_json) .map_err(|_| CommonError::InvalidStructure(format!("Invalid identity json")))?; - let did_info = MyDidInfo::new(Some(did.to_string()), identity_info.seed, identity_info.crypto_type); + let did_info = MyDidInfo::new(Some(did.to_string()), identity_info.seed, identity_info.crypto_type, None); let my_did = self.signus_service.create_my_did(&did_info)?; let my_did_json = my_did.to_json() diff --git a/src/services/anoncreds/issuer.rs b/src/services/anoncreds/issuer.rs index b96d032f19..17022c7d78 100644 --- a/src/services/anoncreds/issuer.rs +++ b/src/services/anoncreds/issuer.rs @@ -72,7 +72,7 @@ impl Issuer { info!(target: "anoncreds_service", "Issuer generate primary keys for Schema {:?} -> start", &schema); let mut ctx = BigNumber::new_context()?; - if schema.attr_names.len() == 0 { + if schema.keys.len() == 0 { return Err(CryptoError::InvalidStructure(format!("List of attribute names is required to setup claim definition"))) } @@ -92,7 +92,7 @@ impl Issuer { let xz = Issuer::_gen_x(&p_prime, &q_prime)?; let mut r: HashMap = HashMap::new(); - for attribute in &schema.attr_names { + for attribute in &schema.keys { let random = Issuer::_gen_x(&p_prime, &q_prime)?; r.insert(attribute.to_string(), s.mod_exp(&random, &n, Some(&mut ctx))?); } @@ -508,7 +508,7 @@ mod tests { fn generate_claim_definition_does_not_works_with_empty_attributes() { let issuer = Issuer::new(); let mut schema = mocks::get_gvt_schema(); - schema.attr_names = HashSet::new(); + schema.keys = HashSet::new(); let signature_type = None; let create_non_revoc = false; @@ -573,29 +573,29 @@ pub mod mocks { } pub fn get_gvt_schema() -> Schema { - let mut attr_names: HashSet = HashSet::new(); - attr_names.insert("name".to_string()); - attr_names.insert("age".to_string()); - attr_names.insert("height".to_string()); - attr_names.insert("sex".to_string()); + let mut keys: HashSet = HashSet::new(); + keys.insert("name".to_string()); + keys.insert("age".to_string()); + keys.insert("height".to_string()); + keys.insert("sex".to_string()); Schema { name: "gvt".to_string(), version: "1.0".to_string(), - attr_names: attr_names, + keys: keys, seq_no: 1 } } pub fn get_xyz_schema() -> Schema { - let mut attr_names: HashSet = HashSet::new(); - attr_names.insert("status".to_string()); - attr_names.insert("period".to_string()); + let mut keys: HashSet = HashSet::new(); + keys.insert("status".to_string()); + keys.insert("period".to_string()); Schema { name: "xyz".to_string(), version: "1.0".to_string(), - attr_names: attr_names, + keys: keys, seq_no: 2 } } diff --git a/src/services/anoncreds/prover.rs b/src/services/anoncreds/prover.rs index 9f0d89ca74..a0509028e0 100644 --- a/src/services/anoncreds/prover.rs +++ b/src/services/anoncreds/prover.rs @@ -512,7 +512,7 @@ impl Prover { let vtilde = BigNumber::rand(LARGE_VTILDE)?; let unrevealed_attrs: Vec = - schema.attr_names + schema.keys .difference(&HashSet::from_iter(revealed_attrs.iter().cloned())) .map(|attr| attr.clone()) .collect::>(); diff --git a/src/services/anoncreds/types.rs b/src/services/anoncreds/types.rs index bc8658737e..63cab97633 100644 --- a/src/services/anoncreds/types.rs +++ b/src/services/anoncreds/types.rs @@ -1075,16 +1075,16 @@ impl RequestedProofJson { pub struct Schema { pub name: String, pub version: String, - pub attr_names: HashSet, + pub keys: HashSet, pub seq_no: i32 } impl Schema { - pub fn new(name: String, version: String, attr_names: HashSet, seq_no: i32) -> Schema { + pub fn new(name: String, version: String, keys: HashSet, seq_no: i32) -> Schema { Schema { name: name, version: version, - attr_names: attr_names, + keys: keys, seq_no: seq_no } } diff --git a/src/services/anoncreds/verifier.rs b/src/services/anoncreds/verifier.rs index c20e69be75..d581e838a3 100644 --- a/src/services/anoncreds/verifier.rs +++ b/src/services/anoncreds/verifier.rs @@ -101,7 +101,7 @@ impl Verifier { use std::iter::FromIterator; let unrevealed_attrs: Vec = - schema.attr_names + schema.keys .difference(&HashSet::from_iter(proof.revealed_attrs.keys().cloned())) .map(|attr| attr.clone()) .collect::>(); diff --git a/src/services/ledger/mod.rs b/src/services/ledger/mod.rs index cf620b6b33..b17d5a752c 100644 --- a/src/services/ledger/mod.rs +++ b/src/services/ledger/mod.rs @@ -115,9 +115,9 @@ impl LedgerService { pub fn build_schema_request(&self, identifier: &str, data: &str) -> Result { let req_id = LedgerService::get_req_id(); - let data = SchemaOperationData::from_json(&data) + SchemaOperationData::from_json(&data) .map_err(|err| CommonError::InvalidStructure(format!("Invalid data json: {}", err.to_string())))?; - let operation = SchemaOperation::new(data); + let operation = SchemaOperation::new(data.to_string()); let request = Request::new(req_id, identifier.to_string(), operation); @@ -126,11 +126,11 @@ impl LedgerService { Ok(request_json) } - pub fn build_get_schema_request(&self, identifier: &str, data: &str) -> Result { + pub fn build_get_schema_request(&self, identifier: &str, dest: &str, data: &str) -> Result { let req_id = LedgerService::get_req_id(); let data = GetSchemaOperationData::from_json(data) .map_err(|err| CommonError::InvalidStructure(format!("Invalid data json: {}", err.to_string())))?; - let operation = GetSchemaOperation::new(data); + let operation = GetSchemaOperation::new(dest.to_string(), data); let request = Request::new(req_id, identifier.to_string(), operation); @@ -139,11 +139,12 @@ impl LedgerService { Ok(request_json) } - pub fn build_claim_def_request(&self, identifier: &str, _ref: &str, signature_type: &str, data: &str) -> Result { + pub fn build_claim_def_request(&self, identifier: &str, _ref: i32, signature_type: &str, data: &str) -> Result { let req_id = LedgerService::get_req_id(); - let data = ClaimDefOperationData::from_json(&data) + println!("data {:?}", data); + ClaimDefOperationData::from_json(&data) .map_err(|err| CommonError::InvalidStructure(format!("Invalid data json: {}", err.to_string())))?; - let operation = ClaimDefOperation::new(_ref.to_string(), signature_type.to_string(), data); + let operation = ClaimDefOperation::new(_ref, signature_type.to_string(), data.to_string()); let request = Request::new(req_id, identifier.to_string(), operation); @@ -152,10 +153,11 @@ impl LedgerService { Ok(request_json) } - pub fn build_get_claim_def_request(&self, identifier: &str, _ref: &str, signature_type: &str) -> Result { + pub fn build_get_claim_def_request(&self, identifier: &str, _ref: i32, signature_type: &str, origin: &str) -> Result { let req_id = LedgerService::get_req_id(); - let operation = GetClaimDefOperation::new(_ref.to_string(), - signature_type.to_string()); + let operation = GetClaimDefOperation::new(_ref, + signature_type.to_string(), + origin.to_string()); let request = Request::new(req_id, identifier.to_string(), operation); @@ -323,9 +325,9 @@ mod tests { fn build_schema_request_works_for_correct_data() { let ledger_service = LedgerService::new(); let identifier = "some_identifier"; - let data = r#"{"name":"name", "version":"1.0", "keys": ["name", "male"]}"#; + let data = r#"{"name":"name", "version":"1.0", "keys":["name","male"]}"#; - let expected_result = r#""identifier":"some_identifier","operation":{"type":"101","data":{"name":"name","version":"1.0","keys":["name","male"]}}"#; + let expected_result = "\"operation\":{\"type\":\"101\",\"data\":\"{\\\"name\\\":\\\"name\\\", \\\"version\\\":\\\"1.0\\\", \\\"keys\\\":[\\\"name\\\",\\\"male\\\"]"; let schema_request = ledger_service.build_schema_request(identifier, data); assert!(schema_request.is_ok()); @@ -337,9 +339,9 @@ mod tests { fn build_get_schema_request_works_for_wrong_data() { let ledger_service = LedgerService::new(); let identifier = "some_identifier"; - let data = r#"{"name":"name", "keys": ["name", "male"]}"#; + let data = r#"{"name":"name","keys":["name","male"]}"#; - let get_schema_request = ledger_service.build_get_schema_request(identifier, data); + let get_schema_request = ledger_service.build_get_schema_request(identifier, identifier, data); assert!(get_schema_request.is_err()); } @@ -347,11 +349,11 @@ mod tests { fn build_get_schema_request_works_for_correct_data() { let ledger_service = LedgerService::new(); let identifier = "some_identifier"; - let data = r#"{"name":"name", "version":"1.0"}"#; + let data = r#"{"name":"name","version":"1.0"}"#; - let expected_result = r#""identifier":"some_identifier","operation":{"type":"107","data":{"name":"name","version":"1.0"}}"#; + let expected_result = r#""identifier":"some_identifier","operation":{"type":"107","dest":"some_identifier","data":{"name":"name","version":"1.0"}}"#; - let get_schema_request = ledger_service.build_get_schema_request(identifier, data); + let get_schema_request = ledger_service.build_get_schema_request(identifier, identifier, data); assert!(get_schema_request.is_ok()); let get_schema_request = get_schema_request.unwrap(); assert!(get_schema_request.contains(expected_result)); @@ -361,12 +363,13 @@ mod tests { fn build_get_claim_def_request_works() { let ledger_service = LedgerService::new(); let identifier = "some_identifier"; - let _ref = "some_ref"; + let _ref = 1; let signature_type = "signature_type"; + let origin = "some_origin"; - let expected_result = r#""identifier":"some_identifier","operation":{"type":"108","ref":"some_ref","signature_type":"signature_type"}"#; + let expected_result = r#""identifier":"some_identifier","operation":{"type":"108","ref":1,"signature_type":"signature_type","origin":"some_origin"}"#; - let get_claim_def_request = ledger_service.build_get_claim_def_request(identifier, _ref, signature_type); + let get_claim_def_request = ledger_service.build_get_claim_def_request(identifier, _ref, signature_type, origin); assert!(get_claim_def_request.is_ok()); let get_claim_def_request = get_claim_def_request.unwrap(); assert!(get_claim_def_request.contains(expected_result)); diff --git a/src/services/ledger/types.rs b/src/services/ledger/types.rs index f8f694d87f..27727ae001 100644 --- a/src/services/ledger/types.rs +++ b/src/services/ledger/types.rs @@ -181,11 +181,11 @@ impl JsonEncodable for GetAttribOperation {} pub struct SchemaOperation { #[serde(rename = "type")] pub _type: String, - pub data: SchemaOperationData + pub data: String } impl SchemaOperation { - pub fn new(data: SchemaOperationData) -> SchemaOperation { + pub fn new(data: String) -> SchemaOperation { SchemaOperation { data: data, _type: SCHEMA.to_string() @@ -220,13 +220,15 @@ impl<'a> JsonDecodable<'a> for SchemaOperationData {} pub struct GetSchemaOperation { #[serde(rename = "type")] pub _type: String, + pub dest: String, pub data: GetSchemaOperationData } impl GetSchemaOperation { - pub fn new(data: GetSchemaOperationData) -> GetSchemaOperation { + pub fn new(dest: String, data: GetSchemaOperationData) -> GetSchemaOperation { GetSchemaOperation { _type: GET_SCHEMA.to_string(), + dest: dest, data: data } } @@ -268,15 +270,15 @@ impl<'a> JsonDecodable<'a> for GetSchemaOperationData {} #[derive(Serialize, PartialEq, Debug)] pub struct ClaimDefOperation { #[serde(rename = "ref")] - pub _ref: String, - pub data: ClaimDefOperationData, + pub _ref: i32, + pub data: String, #[serde(rename = "type")] pub _type: String, pub signature_type: String } impl ClaimDefOperation { - pub fn new(_ref: String, signature_type: String, data: ClaimDefOperationData) -> ClaimDefOperation { + pub fn new(_ref: i32, signature_type: String, data: String) -> ClaimDefOperation { ClaimDefOperation { _ref: _ref, signature_type: signature_type, @@ -291,20 +293,19 @@ impl JsonEncodable for ClaimDefOperation {} #[derive(Serialize, PartialEq, Debug, Deserialize)] pub struct ClaimDefOperationData { pub primary: PublicKey, - pub revocation: RevocationPublicKey, - pub signature_type: String + pub revocation: Option } impl ClaimDefOperationData { - pub fn new(primary: PublicKey, revocation: RevocationPublicKey, signature_type: String, ) -> ClaimDefOperationData { + pub fn new(primary: PublicKey, revocation: Option) -> ClaimDefOperationData { ClaimDefOperationData { primary: primary, - revocation: revocation, - signature_type: signature_type + revocation: revocation } } } + impl JsonEncodable for ClaimDefOperationData {} impl<'a> JsonDecodable<'a> for ClaimDefOperationData {} @@ -314,16 +315,18 @@ pub struct GetClaimDefOperation { #[serde(rename = "type")] pub _type: String, #[serde(rename = "ref")] - pub _ref: String, - pub signature_type: String//TODO In Python there is Origin field, {ORIGIN: id.schemaKey.issuerId}, but there is not in table. We can get it field form GET_SCHEMA response + pub _ref: i32, + pub signature_type: String, + pub origin: String } impl GetClaimDefOperation { - pub fn new(_ref: String, signature_type: String) -> GetClaimDefOperation { + pub fn new(_ref: i32, signature_type: String, origin: String) -> GetClaimDefOperation { GetClaimDefOperation { _type: GET_CLAIM_DEF.to_string(), _ref: _ref, - signature_type: signature_type + signature_type: signature_type, + origin: origin } } } @@ -350,6 +353,12 @@ impl NodeOperation { impl JsonEncodable for NodeOperation {} +#[derive(Serialize, PartialEq, Debug, Deserialize)] +pub enum Services { + VALIDATOR, + OBSERVER +} + #[derive(Serialize, PartialEq, Debug, Deserialize)] pub struct NodeOperationData { pub node_ip: String, @@ -357,11 +366,11 @@ pub struct NodeOperationData { pub client_ip: String, pub client_port: i32, pub alias: String, - pub services: Vec + pub services: Vec } impl NodeOperationData { - pub fn new(node_ip: String, node_port: i32, client_ip: String, client_port: i32, alias: String, services: Vec) -> NodeOperationData { + pub fn new(node_ip: String, node_port: i32, client_ip: String, client_port: i32, alias: String, services: Vec) -> NodeOperationData { NodeOperationData { node_ip: node_ip, node_port: node_port, diff --git a/src/services/pool/mod.rs b/src/services/pool/mod.rs index 4282a4cfcd..e4644ac32f 100644 --- a/src/services/pool/mod.rs +++ b/src/services/pool/mod.rs @@ -18,6 +18,7 @@ use commands::{Command, CommandExecutor}; use commands::ledger::LedgerCommand; use commands::pool::PoolCommand; use errors::pool::PoolError; +use errors::sovrin::SovrinError; use errors::crypto::CryptoError; use self::catchup::CatchupHandler; use self::types::*; @@ -94,6 +95,9 @@ impl TransactionHandler { Message::Reply(reply) => { self.process_reply(&reply, raw_msg); } + Message::Reject(response) => { + self.process_reject(&response, raw_msg); + } _ => { warn!("unhandled msg {:?}", msg); } @@ -119,6 +123,25 @@ impl TransactionHandler { } } + //TODO correct handling of Reject + fn process_reject(&mut self, response: &Response, raw_msg: &String) { + let req_id = response.req_id; + let mut remove = false; + if let Some(pend_cmd) = self.pending_commands.get_mut(&req_id) { + pend_cmd.nack_cnt += 1; + if pend_cmd.nack_cnt == self.f + 1 { + for &cmd_id in &pend_cmd.cmd_ids { + CommandExecutor::instance().send( + Command::Ledger(LedgerCommand::SubmitAck(cmd_id, Err(SovrinError::PoolError(PoolError::InvalidData(raw_msg.clone())))))).unwrap(); + } + remove = true; + } + } + if remove { + self.pending_commands.remove(&req_id); + } + } + fn try_send_request(&mut self, cmd: &String, cmd_id: i32) { info!("cmd {:?}", cmd); let tmp = SimpleRequest::from_json(cmd).unwrap(); diff --git a/src/services/pool/types.rs b/src/services/pool/types.rs index 5781918230..4ac6996119 100644 --- a/src/services/pool/types.rs +++ b/src/services/pool/types.rs @@ -128,6 +128,8 @@ pub enum Message { ReqNACK(Response), #[serde(rename = "REPLY")] Reply(Reply), + #[serde(rename = "REJECT")] + Reject(Response), Ping, Pong, } diff --git a/src/services/signus/mod.rs b/src/services/signus/mod.rs index 7334cef1d9..4fc2a43c24 100644 --- a/src/services/signus/mod.rs +++ b/src/services/signus/mod.rs @@ -177,15 +177,9 @@ mod tests { #[test] fn create_my_did_with_empty_input_works() { let service = SignusService::new(); - - let did_info = MyDidInfo { - did: None, - seed: None, - crypto_type: None - }; + let did_info = MyDidInfo::new(None, None, None, None); let res = service.create_my_did(&did_info); - assert!(res.is_ok()); } @@ -194,11 +188,7 @@ mod tests { let service = SignusService::new(); let did = Some("Dbf2fjCbsiq2kfns".to_string()); - let did_info = MyDidInfo { - did: did.clone(), - seed: None, - crypto_type: None - }; + let did_info = MyDidInfo::new(did.clone(), None, None, None); let res = service.create_my_did(&did_info); assert!(res.is_ok()); @@ -212,11 +202,8 @@ mod tests { let did = Some("Dbf2fjCbsiq2kfns".to_string()); let crypto_type = Some("type".to_string()); - let did_info = MyDidInfo { - did: did.clone(), - seed: None, - crypto_type: crypto_type - }; + + let did_info = MyDidInfo::new(did.clone(), None, crypto_type, None); let res = service.create_my_did(&did_info); assert!(res.is_err()); @@ -228,16 +215,9 @@ mod tests { let did = Some("Dbf2fjCbsiq2kfns".to_string()); let seed = Some("DJASbewkdUY3265HJFDSbds278sdDSnA".to_string()); - let did_info_with_seed = MyDidInfo { - did: did.clone(), - seed: seed, - crypto_type: None - }; - let did_info_without_seed = MyDidInfo { - did: did.clone(), - seed: None, - crypto_type: None - }; + + let did_info_with_seed = MyDidInfo::new(did.clone(), seed, None, None); + let did_info_without_seed = MyDidInfo::new(did.clone(), None, None, None); let res_with_seed = service.create_my_did(&did_info_with_seed); let res_without_seed = service.create_my_did(&did_info_without_seed); @@ -252,11 +232,8 @@ mod tests { fn sign_works() { let service = SignusService::new(); - let did_info = MyDidInfo { - did: None, - seed: None, - crypto_type: None - }; + let did_info = MyDidInfo::new(None, None, None, None); + let message = r#"{ "reqId":1495034346617224651, "identifier":"GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL", @@ -278,11 +255,8 @@ mod tests { fn sign_verify_works() { let service = SignusService::new(); - let did_info = MyDidInfo { - did: None, - seed: None, - crypto_type: None - }; + let did_info = MyDidInfo::new(None, None, None, None); + let message = r#"{ "reqId":1495034346617224651, "identifier":"GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL", @@ -317,11 +291,8 @@ mod tests { fn try_verify_with_invalid_verkey() { let service = SignusService::new(); - let did_info = MyDidInfo { - did: None, - seed: None, - crypto_type: None - }; + let did_info = MyDidInfo::new(None, None, None, None); + let message = r#"{ "reqId":1495034346617224651, "identifier":"GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL", @@ -357,11 +328,8 @@ mod tests { let msg = "some message"; - let did_info = MyDidInfo { - did: None, - seed: None, - crypto_type: None - }; + let did_info = MyDidInfo::new(None, None, None, None); + let res = service.create_my_did(&did_info); assert!(res.is_ok()); let my_did = res.unwrap(); @@ -388,11 +356,8 @@ mod tests { let msg = "some message"; - let did_info = MyDidInfo { - did: None, - seed: None, - crypto_type: None - }; + let did_info = MyDidInfo::new(None, None, None, None); + let res = service.create_my_did(&did_info); assert!(res.is_ok()); let my_did = res.unwrap(); diff --git a/src/services/signus/types.rs b/src/services/signus/types.rs index 119ccf8ed0..38c3303657 100644 --- a/src/services/signus/types.rs +++ b/src/services/signus/types.rs @@ -4,15 +4,18 @@ use utils::json::{JsonEncodable, JsonDecodable}; pub struct MyDidInfo { pub did: Option, pub seed: Option, - pub crypto_type: Option + pub crypto_type: Option, + pub cid: Option } impl MyDidInfo { - pub fn new(did: Option, seed: Option, crypto_type: Option) -> MyDidInfo { + pub fn new(did: Option, seed: Option, + crypto_type: Option, cid: Option) -> MyDidInfo { MyDidInfo { did: did, seed: seed, - crypto_type: crypto_type + crypto_type: crypto_type, + cid: cid } } } diff --git a/src/utils/crypto/signature_serializer.rs b/src/utils/crypto/signature_serializer.rs index 0485f95b83..0fa15fb95e 100644 --- a/src/utils/crypto/signature_serializer.rs +++ b/src/utils/crypto/signature_serializer.rs @@ -1,10 +1,11 @@ extern crate serde_json; +extern crate hex; +use self::hex::ToHex; use self::serde_json::Value; use errors::crypto::CryptoError; use utils::crypto::hash::Hash; -use utils::crypto::base58::Base58; pub fn serialize_signature(v: Value) -> Result { match v { @@ -30,8 +31,7 @@ pub fn serialize_signature(v: Value) -> Result { if key == "raw" { let mut ctx = Hash::new_context()?; ctx.update(&value.as_str().ok_or(CryptoError::BackendError("Cannot update hash context".to_string()))?.as_bytes())?; - let vector = Base58::encode(&ctx.finish2()?.to_vec()); - value = Value::String(vector); + value = Value::String(ctx.finish2()?.as_ref().to_hex()); } result = result + key + ":" + &serialize_signature(value)?; if index < length - 1 { @@ -90,7 +90,7 @@ mod tests { }"#; let msg: Value = serde_json::from_str(data).unwrap(); - let result = "age:43|name:John Doe|operation:dest:54|hash:cool hash|raw:31L9oDUaMfZu3t3eCWuoG6PbWigVMqHqrWuS8Ly9oH4t|phones:1234567,2345678,age:1|rust:5,3"; + let result = "age:43|name:John Doe|operation:dest:54|hash:cool hash|raw:1dcd0759ce38f57049344a6b3c5fc18144fca1724713090c2ceeffa788c02711|phones:1234567,2345678,age:1|rust:5,3"; assert_eq!(serialize_signature(msg).unwrap(), result) } diff --git a/tests/anoncreds.rs b/tests/anoncreds.rs index 79a27f158f..0d0ac54699 100644 --- a/tests/anoncreds.rs +++ b/tests/anoncreds.rs @@ -32,12 +32,12 @@ fn anoncreds_works_for_single_issuer_single_prover() { let xtype = "default"; //1. Create Issuer wallet, get wallet handle - let res = WalletUtils::create_wallet(pool_name, issuer_wallet_name, xtype); + let res = WalletUtils::create_and_open_wallet(pool_name, issuer_wallet_name, xtype); assert!(res.is_ok()); let issuer_wallet_handle = res.unwrap(); //2. Create Prover wallet, get wallet handle - let res = WalletUtils::create_wallet(pool_name, prover_wallet_name, xtype); + let res = WalletUtils::create_and_open_wallet(pool_name, prover_wallet_name, xtype); assert!(res.is_ok()); let prover_wallet_handle = res.unwrap(); @@ -162,17 +162,17 @@ fn anoncreds_works_for_multiply_issuer_single_prover() { let xtype = "default"; //1. Issuer1 create wallet, get wallet handles - let res = WalletUtils::create_wallet(pool_name, issuer1_wallet_name, xtype); + let res = WalletUtils::create_and_open_wallet(pool_name, issuer1_wallet_name, xtype); assert!(res.is_ok()); let issuer_gvt_wallet_handle = res.unwrap(); //2. Issuer2 create wallet, get wallet handles - let res = WalletUtils::create_wallet(pool_name, issuer2_wallet_name, xtype); + let res = WalletUtils::create_and_open_wallet(pool_name, issuer2_wallet_name, xtype); assert!(res.is_ok()); let issuer_xyz_wallet_handle = res.unwrap(); //3. Prover create wallet, get wallet handles - let res = WalletUtils::create_wallet(pool_name, prover_wallet_name, xtype); + let res = WalletUtils::create_and_open_wallet(pool_name, prover_wallet_name, xtype); assert!(res.is_ok()); let prover_wallet_handle = res.unwrap(); @@ -385,12 +385,12 @@ fn anoncreds_works_for_single_issuer_multiply_claims_single_prover() { let xtype = "default"; //1. Issuer create wallet, get wallet handles - let res = WalletUtils::create_wallet(pool_name, issuer_wallet_name, xtype); + let res = WalletUtils::create_and_open_wallet(pool_name, issuer_wallet_name, xtype); assert!(res.is_ok()); let issuer_wallet_handle = res.unwrap(); //2. Prover create wallet, get wallet handles - let res = WalletUtils::create_wallet(pool_name, prover_wallet_name, xtype); + let res = WalletUtils::create_and_open_wallet(pool_name, prover_wallet_name, xtype); assert!(res.is_ok()); let prover_wallet_handle = res.unwrap(); diff --git a/tests/demo.rs b/tests/demo.rs index 5fffd69bda..4b17720bc2 100644 --- a/tests/demo.rs +++ b/tests/demo.rs @@ -159,7 +159,7 @@ fn anoncreds_demo_works() { let schema = format!("{{\ \"name\":\"gvt\",\ \"version\":\"1.0\",\ - \"attr_names\":[\"age\",\"sex\",\"height\",\"name\"],\ + \"keys\":[\"age\",\"sex\",\"height\",\"name\"],\ \"seq_no\":{}\ }}", schema_seq_no); diff --git a/tests/ledger.rs b/tests/ledger.rs index cef8524bde..1e8c15939a 100644 --- a/tests/ledger.rs +++ b/tests/ledger.rs @@ -18,391 +18,409 @@ use utils::test::TestUtils; #[cfg(feature = "local_nodes_pool")] use utils::pool::PoolUtils; #[cfg(feature = "local_nodes_pool")] -use utils::logger::LoggerUtils; -#[cfg(feature = "local_nodes_pool")] use utils::wallet::WalletUtils; #[cfg(feature = "local_nodes_pool")] use utils::ledger::LedgerUtils; #[cfg(feature = "local_nodes_pool")] use utils::signus::SignusUtils; - - -#[test] #[cfg(feature = "local_nodes_pool")] -fn sovrin_nym_requests_works() { - TestUtils::cleanup_storage(); - LoggerUtils::init(); +use utils::anoncreds::AnoncredsUtils; - let pool_name = "test_submit_tx"; - let my_wallet_name = "my_wallet"; - let their_wallet_name = "their_wallet"; - let wallet_type = "default"; +use std::collections::{HashMap, HashSet}; - let res = PoolUtils::create_pool_ledger_config(pool_name); - assert!(res.is_ok()); - let res = PoolUtils::open_pool_ledger(pool_name); - assert!(res.is_ok()); - let pool_handle = res.unwrap(); - let res = WalletUtils::create_wallet(pool_name, my_wallet_name, wallet_type); +// 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 +#[cfg(feature = "local_nodes_pool")] +fn get_trustee_keys(wallet_handle: i32) -> (String, String, String) { + // workaround start >>> + let res = SignusUtils::create_my_did(wallet_handle, "{\"seed\":\"000000000000000000000000Trustee1\"}"); assert!(res.is_ok()); - let my_wallet_handle = res.unwrap(); + let (trustee_did, trustee_verkey, trustee_pk) = res.unwrap(); - let res = WalletUtils::create_wallet(pool_name, their_wallet_name, wallet_type); + let res = SignusUtils::create_my_did(wallet_handle, &format!("{{\"did\":\"{}\", \"seed\":\"000000000000000000000000Trustee1\"}}", trustee_verkey)); assert!(res.is_ok()); - let their_wallet_handle = res.unwrap(); + res.unwrap() + // workaround end <<< +} - let my_did_json = "{}"; - let res = SignusUtils::create_my_did(my_wallet_handle, my_did_json); - assert!(res.is_ok()); - let (my_did, my_verkey, my_pk) = res.unwrap(); +mod high_cases { + use super::*; - let their_did_json = "{\"seed\":\"000000000000000000000000Trustee1\"}"; - let res = SignusUtils::create_my_did(their_wallet_handle, their_did_json); - assert!(res.is_ok()); - let (their_did, their_verkey, their_pk) = res.unwrap(); + mod nym_requests { + use super::*; - let res = LedgerUtils::build_nym_request(&their_verkey.clone(), &my_verkey.clone(), None, None, None, None); - assert!(res.is_ok()); - let nym_request = res.unwrap(); + #[test] + #[cfg(feature = "local_nodes_pool")] + #[ignore] + fn sovrin_nym_requests_works() { + TestUtils::cleanup_storage(); - let res = SignusUtils::sign(their_wallet_handle, &their_did, &nym_request); - assert!(res.is_ok()); - let nym_request = res.unwrap(); + let res = PoolUtils::create_and_open_pool_ledger_config("pool1"); + assert!(res.is_ok()); + let pool_handle = res.unwrap(); - println!("{}", nym_request.clone()); - let res = PoolUtils::send_request(pool_handle, &nym_request); - assert!(res.is_ok()); - let nym_response = res.unwrap(); + let res = WalletUtils::create_and_open_wallet("pool1", "wallet1", "default"); + assert!(res.is_ok()); + let wallet_handle = res.unwrap(); - let res = LedgerUtils::build_get_nym_request(&my_verkey.clone(), &my_did.clone()); - assert!(res.is_ok()); - let get_nym_request = res.unwrap(); + let (trustee_did, trustee_verkey, trustee_pk) = get_trustee_keys(wallet_handle); - println!("{}", get_nym_request.clone()); - let res = PoolUtils::send_request(pool_handle, &get_nym_request); - assert!(res.is_ok()); - let nym_response = res.unwrap(); + let res = SignusUtils::create_my_did(wallet_handle, "{\"seed\":\"00000000000000000000000000000My1\"}"); + assert!(res.is_ok()); + let (my_did, my_verkey, my_pk) = res.unwrap(); - TestUtils::cleanup_storage(); -} + let res = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), Some(&my_verkey.clone()), None, None, None); + assert!(res.is_ok()); + let nym_request = res.unwrap(); -#[test] -#[cfg(feature = "local_nodes_pool")] -#[ignore] -fn sovrin_attrib_requests_works() { - TestUtils::cleanup_storage(); - let pool_name = "test_submit_tx"; - let my_wallet_name = "my_wallet"; - let their_wallet_name = "their_wallet"; - let wallet_type = "default"; - - let res = PoolUtils::create_pool_ledger_config(pool_name); - assert!(res.is_ok()); - let res = PoolUtils::open_pool_ledger(pool_name); - assert!(res.is_ok()); - let pool_handle = res.unwrap(); + let res = LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &trustee_did, &nym_request); + assert!(res.is_ok()); + let nym_response = res.unwrap(); + println!("nym_response {:?}", nym_response); - let res = WalletUtils::create_wallet(pool_name, my_wallet_name, wallet_type); - assert!(res.is_ok()); - let my_wallet_handle = res.unwrap(); + let res = LedgerUtils::build_get_nym_request(&my_did.clone(), &my_did.clone()); + assert!(res.is_ok()); + let get_nym_request = res.unwrap(); - let res = WalletUtils::create_wallet(pool_name, their_wallet_name, wallet_type); - assert!(res.is_ok()); - let their_wallet_handle = res.unwrap(); + let res = PoolUtils::send_request(pool_handle, &get_nym_request); + assert!(res.is_ok()); + let get_nym_response = res.unwrap(); + println!("get_nym_response {:?}", get_nym_response); - let my_did_json = "{}"; - let res = SignusUtils::create_my_did(my_wallet_handle, my_did_json); - assert!(res.is_ok()); - let (my_did, my_verkey, my_pk) = res.unwrap(); + TestUtils::cleanup_storage(); + } + } - let their_did_json = "{\"seed\":\"000000000000000000000000Trustee1\"}"; - let res = SignusUtils::create_my_did(their_wallet_handle, their_did_json); - assert!(res.is_ok()); - let (their_did, their_verkey, their_pk) = res.unwrap(); + mod attrib_requests { + use super::*; - let res = LedgerUtils::build_nym_request(&their_verkey.clone(), &my_did.clone(), None, None, None, None); - assert!(res.is_ok()); - let nym_request = res.unwrap(); + #[test] + #[cfg(feature = "local_nodes_pool")] + #[ignore] + fn sovrin_attrib_requests_works() { + TestUtils::cleanup_storage(); - let res = SignusUtils::sign(their_wallet_handle, &their_did, &nym_request); - assert!(res.is_ok()); - let nym_request = res.unwrap(); + let res = PoolUtils::create_and_open_pool_ledger_config("pool1"); + assert!(res.is_ok()); + let pool_handle = res.unwrap(); - println!("nym_request {}", nym_request.clone()); - let res = PoolUtils::send_request(pool_handle, &nym_request); - assert!(res.is_ok()); - let nym_response = res.unwrap(); + let res = WalletUtils::create_and_open_wallet("pool1", "wallet1", "default"); + assert!(res.is_ok()); + let wallet_handle = res.unwrap(); - let res = LedgerUtils::build_attrib_request(&their_verkey.clone(), &my_did.clone(), None, Some("{\"endpoint\":{\"ha\":\"127.0.0.1:5555\"}}"), None); - assert!(res.is_ok()); - let attrib_request = res.unwrap(); - - let res = SignusUtils::sign(their_wallet_handle, &their_did, &attrib_request); - assert!(res.is_ok()); - let attrib_request = res.unwrap(); + let (trustee_did, trustee_verkey, trustee_pk) = get_trustee_keys(wallet_handle); - println!("attrib_request {}", attrib_request.clone()); - let res = PoolUtils::send_request(pool_handle, &attrib_request); - assert!(res.is_ok()); - let attrib_response = res.unwrap(); - - let res = LedgerUtils::build_get_attrib_request(&their_verkey.clone(), &my_did.clone(), "endpoint"); - assert!(res.is_ok()); - let get_attrib_request = res.unwrap(); + let res = SignusUtils::create_my_did(wallet_handle, "{\"seed\":\"00000000000000000000000000000My1\"}"); + assert!(res.is_ok()); + let (my_did, my_verkey, my_pk) = res.unwrap(); - println!("get_attrib_request {}", get_attrib_request.clone()); - let res = PoolUtils::send_request(pool_handle, &get_attrib_request); - assert!(res.is_ok()); - let get_attrib_response = res.unwrap(); + let res = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), Some(&my_verkey.clone()), None, None, None); + assert!(res.is_ok()); + let nym_request = res.unwrap(); - TestUtils::cleanup_storage(); -} + let res = LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &trustee_did, &nym_request); + assert!(res.is_ok()); + let nym_response = res.unwrap(); -#[test] -#[cfg(feature = "local_nodes_pool")] -#[ignore] -fn sovrin_schema_requests_works() { - TestUtils::cleanup_storage(); - let pool_name = "test_submit_tx"; - let my_wallet_name = "my_wallet"; - let their_wallet_name = "their_wallet"; - let wallet_type = "default"; - - let res = PoolUtils::create_pool_ledger_config(pool_name); - assert!(res.is_ok()); - let res = PoolUtils::open_pool_ledger(pool_name); - assert!(res.is_ok()); - let pool_handle = res.unwrap(); + let res = LedgerUtils::build_attrib_request(&my_did.clone(), &my_did.clone(), None, Some("{\"endpoint\":{\"ha\":\"127.0.0.1:5555\"}}"), None); + assert!(res.is_ok()); + let attrib_request = res.unwrap(); - let res = WalletUtils::create_wallet(pool_name, my_wallet_name, wallet_type); - assert!(res.is_ok()); - let my_wallet_handle = res.unwrap(); + let res = LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &my_did, &attrib_request); + assert!(res.is_ok()); + let attrib_response = res.unwrap(); + println!("attrib_response {}", attrib_response); - let res = WalletUtils::create_wallet(pool_name, their_wallet_name, wallet_type); - assert!(res.is_ok()); - let their_wallet_handle = res.unwrap(); + let res = LedgerUtils::build_get_attrib_request(&my_did.clone(), &my_did.clone(), "endpoint"); + assert!(res.is_ok()); + let get_attrib_request = res.unwrap(); - let my_did_json = "{}"; - let res = SignusUtils::create_my_did(my_wallet_handle, my_did_json); - assert!(res.is_ok()); - let (my_did, my_verkey, my_pk) = res.unwrap(); + println!("get_attrib_request {}", get_attrib_request); + let res = PoolUtils::send_request(pool_handle, &get_attrib_request); + assert!(res.is_ok()); + let get_attrib_response = res.unwrap(); + println!("get_attrib_response {}", get_attrib_response); - let their_did_json = "{\"seed\":\"000000000000000000000000Trustee1\"}"; - let res = SignusUtils::create_my_did(their_wallet_handle, their_did_json); - assert!(res.is_ok()); - let (their_did, their_verkey, their_pk) = res.unwrap(); + TestUtils::cleanup_storage(); + } + } + + mod schema_requests { + use super::*; + + #[test] + #[cfg(feature = "local_nodes_pool")] + #[ignore] + fn sovrin_schema_requests_works() { + TestUtils::cleanup_storage(); + // TODO: FIXME: Understand why we use verkey insted of did as submitter id in NYM transaction - let res = LedgerUtils::build_nym_request(&their_verkey.clone(), &my_did.clone(), None, None, None, None); - assert!(res.is_ok()); - let nym_request = res.unwrap(); + let res = PoolUtils::create_and_open_pool_ledger_config("pool1"); + assert!(res.is_ok()); + let pool_handle = res.unwrap(); - let res = SignusUtils::sign(their_wallet_handle, &their_did, &nym_request); - assert!(res.is_ok()); - let nym_request = res.unwrap(); + let res = WalletUtils::create_and_open_wallet("pool1", "wallet1", "default"); + assert!(res.is_ok()); + let wallet_handle = res.unwrap(); - println!("nym_request {}", nym_request.clone()); - let res = PoolUtils::send_request(pool_handle, &nym_request); - assert!(res.is_ok()); - let nym_response = res.unwrap(); + let (trustee_did, trustee_verkey, trustee_pk) = get_trustee_keys(wallet_handle); + + let res = SignusUtils::create_my_did(wallet_handle, "{}"); + assert!(res.is_ok()); + let (my_did, my_verkey, my_pk) = res.unwrap(); + + let res = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), Some(&my_verkey.clone()), None, None, None); + assert!(res.is_ok()); + let nym_request = res.unwrap(); + + let res = LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &trustee_did, &nym_request); + assert!(res.is_ok()); + let nym_response = res.unwrap(); + println!("nym_response {}", nym_response.clone()); - let schema_data = "{\"name\":\"gvt\",\ - \"version\":\"1.0\",\ + let schema_data = "{\"name\":\"gvt2\",\ + \"version\":\"2.0\",\ \"keys\": [\"name\", \"male\"]}"; - let res = LedgerUtils::build_schema_request(&my_verkey.clone(), schema_data); - assert!(res.is_ok()); - let schema_request = res.unwrap(); - - let res = SignusUtils::sign(their_wallet_handle, &their_did, &schema_request); - assert!(res.is_ok()); - let schema_request = res.unwrap(); - - println!("schema_request {}", schema_request.clone()); - let res = PoolUtils::send_request(pool_handle, &schema_request); - assert!(res.is_ok()); - let schema_response = res.unwrap(); - - let get_schema_data = "{\"name\":\"gvt\",\"version\":\"1.0\"}"; - let res = LedgerUtils::build_get_schema_request(&my_verkey.clone(), get_schema_data); - assert!(res.is_ok()); - let get_schema_request = res.unwrap(); - - println!("get_schema_request {}", get_schema_request.clone()); - let res = PoolUtils::send_request(pool_handle, &get_schema_request); - assert!(res.is_ok()); - let get_schema_response = res.unwrap(); - - TestUtils::cleanup_storage(); -} + let res = LedgerUtils::build_schema_request(&my_did.clone(), schema_data); + assert!(res.is_ok()); + let schema_request = res.unwrap(); + + let res = LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &my_did, &schema_request); + assert!(res.is_ok()); + let schema_response = res.unwrap(); + println!("schema_response {}", schema_response.clone()); + + let get_schema_data = "{\"name\":\"gvt2\",\"version\":\"2.0\"}"; + let res = LedgerUtils::build_get_schema_request(&my_did.clone(), &my_did, get_schema_data); + assert!(res.is_ok()); + let get_schema_request = res.unwrap(); + + let res = PoolUtils::send_request(pool_handle, &get_schema_request); + assert!(res.is_ok()); + let get_schema_response = res.unwrap(); + println!("get_schema_response {}", get_schema_response.clone()); + + TestUtils::cleanup_storage(); + } + } + + mod node_request { + use super::*; + + #[test] + #[cfg(feature = "local_nodes_pool")] + #[ignore] + fn sovrin_node_request_works() { + TestUtils::cleanup_storage(); + let res = PoolUtils::create_and_open_pool_ledger_config("pool1"); + assert!(res.is_ok()); + let pool_handle = res.unwrap(); + + let res = WalletUtils::create_and_open_wallet("pool1", "wallet1", "default"); + assert!(res.is_ok()); + let wallet_handle = res.unwrap(); + + let res = SignusUtils::create_my_did(wallet_handle, "{\"seed\":\"000000000000000000000000Trustee1\"}"); + assert!(res.is_ok()); + let (trustee_did, trustee_verkey, trustee_pk) = res.unwrap(); + + let res = SignusUtils::create_my_did(wallet_handle, "{\"seed\":\"000000000000000000000000Steward1\"}"); + assert!(res.is_ok()); + let (my_did, my_verkey, my_pk) = res.unwrap(); + + // TODO: FIXME: Understand why we use verkey insted of did as submitter id in NYM transaction + let res = LedgerUtils::build_nym_request(&trustee_verkey.clone(), &my_did.clone(), Some(&my_verkey.clone()), None, None, None); + assert!(res.is_ok()); + let nym_request = res.unwrap(); + + println!("nym_request {}", nym_request.clone()); + let res = LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &trustee_did, &nym_request); + assert!(res.is_ok()); + let nym_response = res.unwrap(); + + let node_data = "{\"node_ip\":\"192.168.53.148\",\ + \"node_port\":9710, \ + \"client_ip\":\"192.168.53.148\",\ + \"client_port\":9709, \ + \"alias\":\"Node5\", \ + \"services\": [\"VALIDATOR\"]}"; + let res = LedgerUtils::build_node_request(&my_verkey.clone(), &my_did.clone(), node_data); + let node_request = res.unwrap(); -#[test] -#[cfg(feature = "local_nodes_pool")] -#[ignore] -fn sovrin_node_request_works() { - TestUtils::cleanup_storage(); - let pool_name = "test_submit_tx"; - let my_wallet_name = "my_wallet"; - let their_wallet_name = "their_wallet"; - let wallet_type = "default"; - - let res = PoolUtils::create_pool_ledger_config(pool_name); - assert!(res.is_ok()); - let res = PoolUtils::open_pool_ledger(pool_name); - assert!(res.is_ok()); - let pool_handle = res.unwrap(); - let res = WalletUtils::create_wallet(pool_name, my_wallet_name, wallet_type); - assert!(res.is_ok()); - let my_wallet_handle = res.unwrap(); + println!("node_request {}", node_request.clone()); + let res = LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &my_did, &node_request); + //TODO correct handling of Reject + assert!(res.is_err()); - let res = WalletUtils::create_wallet(pool_name, their_wallet_name, wallet_type); - assert!(res.is_ok()); - let their_wallet_handle = res.unwrap(); + TestUtils::cleanup_storage(); + } + } - let my_did_json = "{\"seed\":\"000000000000000000000000Steward1\"}"; - let res = SignusUtils::create_my_did(my_wallet_handle, my_did_json); - assert!(res.is_ok()); - let (my_did, my_verkey, my_pk) = res.unwrap(); + mod claim_def_requests { + use super::*; - let their_did_json = "{\"seed\":\"000000000000000000000000Trustee1\"}"; - let res = SignusUtils::create_my_did(their_wallet_handle, their_did_json); - assert!(res.is_ok()); - let (their_did, their_verkey, their_pk) = res.unwrap(); + #[test] + #[cfg(feature = "local_nodes_pool")] + #[ignore] + fn sovrin_claim_def_requests_works() { + TestUtils::cleanup_storage(); + let res = PoolUtils::create_and_open_pool_ledger_config("pool1"); + assert!(res.is_ok()); + let pool_handle = res.unwrap(); - let res = LedgerUtils::build_nym_request(&their_verkey.clone(), &my_did.clone(), None, None, None, None); - assert!(res.is_ok()); - let nym_request = res.unwrap(); + let res = WalletUtils::create_and_open_wallet("pool1", "wallet1", "default"); + assert!(res.is_ok()); + let wallet_handle = res.unwrap(); - let res = SignusUtils::sign(my_wallet_handle, &their_did, &nym_request); - assert!(res.is_ok()); - let nym_request = res.unwrap(); + let (trustee_did, trustee_verkey, trustee_pk) = get_trustee_keys(wallet_handle); - println!("nym_request {}", nym_request.clone()); - let res = PoolUtils::send_request(pool_handle, &nym_request); - assert!(res.is_ok()); - let nym_response = res.unwrap(); + let res = SignusUtils::create_my_did(wallet_handle, "{}"); + assert!(res.is_ok()); + let (my_did, my_verkey, my_pk) = res.unwrap(); + let res = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), Some(&my_verkey.clone()), None, None, None); + assert!(res.is_ok()); + let nym_request = res.unwrap(); - let node_data = "{\"node_ip\":\"192.168.53.148\",\ - \"node_port\":9710, \ - \"client_ip\":\"192.168.53.148\",\ - \"client_port\":9709, \ - \"alias\":Node5, \ - \"services\": [\"VALIDATOR\"]}"; - let res = LedgerUtils::build_node_request(&their_verkey.clone(), &my_did.clone(), node_data); - assert!(res.is_ok()); - let node_request = res.unwrap(); + let res = LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &trustee_did, &nym_request); + assert!(res.is_ok()); + let nym_response = res.unwrap(); + println!("nym_response {}", nym_response.clone()); - let res = SignusUtils::sign(my_wallet_handle, &their_did, &node_request); - assert!(res.is_ok()); - let node_request = res.unwrap(); + let schema_data = "{\"name\":\"gvt2\",\ + \"version\":\"2.0\",\ + \"keys\": [\"name\", \"male\"]}"; + let res = LedgerUtils::build_schema_request(&my_did.clone(), schema_data); + assert!(res.is_ok()); + let schema_request = res.unwrap(); + + let res = LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &my_did, &schema_request); + assert!(res.is_ok()); + let schema_response = res.unwrap(); + println!("schema_response {}", schema_response.clone()); + + let get_schema_data = "{\"name\":\"gvt2\",\"version\":\"2.0\"}"; + let res = LedgerUtils::build_get_schema_request(&my_did.clone(), &my_did, get_schema_data); + assert!(res.is_ok()); + let get_schema_request = res.unwrap(); + + let res = PoolUtils::send_request(pool_handle, &get_schema_request); + assert!(res.is_ok()); + let get_schema_response = res.unwrap(); + println!("get_schema_response {}", get_schema_response); + let get_schema_response: Reply = serde_json::from_str(&get_schema_response).unwrap(); + // let schema_result_data: GetSchemaResultData = serde_json::from_str(&get_schema_response.result.data.unwrap()).unwrap(); + + let schema = Schema { + name: get_schema_response.result.data.name, + keys: get_schema_response.result.data.keys, + version: get_schema_response.result.data.version, + seq_no: get_schema_response.result.seq_no + }; + + let res = AnoncredsUtils::issuer_create_claim_definition(wallet_handle, &serde_json::to_string(&schema).unwrap()); + assert!(res.is_ok()); + let (claim_def_json, claim_def_uuid) = res.unwrap(); + println!("claim_def_json {:}", claim_def_json); + + let claim_def: ClaimDefinition = serde_json::from_str(&claim_def_json).unwrap(); + let claim_def_data = ClaimDefinitionData { + primary: claim_def.public_key, + revocation: claim_def.public_key_revocation + }; + let claim_def_data_json = serde_json::to_string(&claim_def_data).unwrap(); + + let res = LedgerUtils::build_claim_def_txn(&my_did.clone(), schema.seq_no, &claim_def.signature_type, &claim_def_data_json); + assert!(res.is_ok()); + let claim_def_request = res.unwrap(); + + let res = LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &my_did, &claim_def_request); + assert!(res.is_ok()); + let claim_def_response = res.unwrap(); + println!("claim_def_response {}", claim_def_response); + + let res = LedgerUtils::build_get_claim_def_txn(&my_did.clone(), schema.seq_no, &claim_def.signature_type, &get_schema_response.result.data.origin); + assert!(res.is_ok()); + let get_claim_def_request = res.unwrap(); + + let res = PoolUtils::send_request(pool_handle, &get_claim_def_request); + assert!(res.is_ok()); + let get_claim_def_response = res.unwrap(); + println!("get_claim_def_response {}", get_claim_def_response); + + TestUtils::cleanup_storage(); + } + } +} - println!("node_request {}", node_request.clone()); - let res = PoolUtils::send_request(pool_handle, &node_request); - assert!(res.is_ok()); - let node_response = res.unwrap(); - TestUtils::cleanup_storage(); +#[derive(Deserialize, Eq, PartialEq, Debug)] +#[serde(rename_all = "camelCase")] +struct Response { + op: String, + reason: String, + req_id: u64, + identifier: String } -//#[test] -//#[cfg(feature = "local_nodes_pool")] -//#[ignore] -//fn sovrin_claim_def_requests_works() { -// TestUtils::cleanup_storage(); -// let pool_name = "test_submit_tx"; -// let my_wallet_name = "my_wallet"; -// let their_wallet_name = "their_wallet"; -// let wallet_type = "default"; -// -// let res = PoolUtils::create_pool_ledger_config(pool_name); -// assert!(res.is_ok()); -// let res = PoolUtils::open_pool_ledger(pool_name); -// assert!(res.is_ok()); -// let pool_handle = res.unwrap(); -// -// let res = WalletUtils::create_wallet(pool_name, my_wallet_name, wallet_type); -// assert!(res.is_ok()); -// let my_wallet_handle = res.unwrap(); -// -// let res = WalletUtils::create_wallet(pool_name, their_wallet_name, wallet_type); -// assert!(res.is_ok()); -// let their_wallet_handle = res.unwrap(); -// -// let my_did_json = "{}"; -// let res = SignusUtils::create_my_did(my_wallet_handle, my_did_json); -// assert!(res.is_ok()); -// let (my_did, my_verkey, my_pk) = res.unwrap(); -// -// let their_did_json = "{\"seed\":\"000000000000000000000000Trustee1\"}"; -// let res = SignusUtils::create_my_did(their_wallet_handle, their_did_json); -// assert!(res.is_ok()); -// let (their_did, their_verkey, their_pk) = res.unwrap(); -// -// let schema_data = "{\"name\":\"gvt\",\ -// \"version\":\"1.0\",\ -// \"keys\": [\"name\", \"male\"]}"; -// let res = LedgerUtils::build_schema_request(&my_verkey.clone(), schema_data); -// assert!(res.is_ok()); -// let schema_request = res.unwrap(); -// -// let res = SignusUtils::sign(my_wallet_handle, &their_did, &schema_request); -// assert!(res.is_ok()); -// let schema_request = res.unwrap(); -// -// println!("schema_request {}", schema_request.clone()); -// let res = PoolUtils::send_request(pool_handle, &schema_request); -// assert!(res.is_ok()); -// let schema_response = res.unwrap(); -// let schema_response: Reply = serde_json::from_str(&schema_response).unwrap(); -// let schema = schema_response.result.data; -// -// let schema: Schema = serde_json::from_str(&schema).unwrap(); -// -// let res = AnoncredsUtils::issuer_create_claim_definition(my_wallet_handle, &schema); -// assert!(res.is_ok()); -// let (claim_def_json, claim_def_uuid) = res.unwrap(); -// -// //TODO Claim_def_json cast and change json -// let signature_type = "CL".to_string(); -// let res = LedgerUtils::build_claim_def_txn(&my_verkey.clone(), schema.seq_no, signature_type, claim_def_json); -// assert!(res.is_ok()); -// let claim_def_request = res.unwrap(); -// -// let res = SignusUtils::sign(my_wallet_handle, &their_did, &claim_def_request); -// assert!(res.is_ok()); -// let claim_def_request = res.unwrap(); -// -// println!("claim_def_request {}", claim_def_request.clone()); -// let res = PoolUtils::send_request(pool_handle, &claim_def_request); -// assert!(res.is_ok()); -// let claim_def_response = res.unwrap(); -// -// TestUtils::cleanup_storage(); -//} - #[derive(Deserialize, Eq, PartialEq, Debug)] struct Reply { op: String, - result: ReplyResult, + result: GetSchemaReplyResult, } #[derive(Deserialize, Eq, PartialEq, Debug)] #[serde(rename_all = "camelCase")] -struct ReplyResult { +struct GetSchemaReplyResult { identifier: String, req_id: u64, - data: Option + seq_no: i32, + #[serde(rename = "type")] + _type: String, + data: GetSchemaResultData, + dest: Option } -#[derive(Deserialize, PartialEq, Debug)] -#[serde(rename_all = "camelCase")] +#[derive(Deserialize, Debug, PartialEq, Eq)] pub struct GetSchemaResultData { - pub attr_names: Vec, + pub keys: HashSet, pub name: String, pub origin: String, - pub seq_no: String, - #[serde(rename = "type")] - pub _type: Option, pub version: String -} \ No newline at end of file +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct Schema { + pub name: String, + pub version: String, + pub keys: HashSet, + pub seq_no: i32 +} + +#[derive(Deserialize, Debug, Serialize, PartialEq)] +pub struct ClaimDefinition { + pub public_key: PublicKey, + pub public_key_revocation: Option, + pub schema_seq_no: i32, + pub signature_type: String +} + +#[derive(Debug, Serialize, Deserialize, PartialEq)] +pub struct PublicKey { + pub n: String, + pub s: String, + pub rms: String, + pub r: HashMap, + pub rctxt: String, + pub z: String +} + +#[derive(Deserialize, Debug, Serialize, PartialEq)] +pub struct ClaimDefinitionData { + pub primary: PublicKey, + pub revocation: Option +} + + diff --git a/tests/utils/anoncreds.rs b/tests/utils/anoncreds.rs index 64c25e1e33..ac723a7e88 100644 --- a/tests/utils/anoncreds.rs +++ b/tests/utils/anoncreds.rs @@ -358,7 +358,7 @@ impl AnoncredsUtils { format!("{{\ \"name\":\"gvt\",\ \"version\":\"1.0\",\ - \"attr_names\":[\"age\",\"sex\",\"height\",\"name\"],\ + \"keys\":[\"age\",\"sex\",\"height\",\"name\"],\ \"seq_no\":{}\ }}", schema_seq_no) } @@ -367,7 +367,7 @@ impl AnoncredsUtils { format!("{{\ \"name\":\"xyz\",\ \"version\":\"1.0\",\ - \"attr_names\":[\"status\",\"period\"],\ + \"keys\":[\"status\",\"period\"],\ \"seq_no\":{}\ }}", schema_seq_no) } diff --git a/tests/utils/ledger.rs b/tests/utils/ledger.rs index 3bc355f26d..0a957317bb 100644 --- a/tests/utils/ledger.rs +++ b/tests/utils/ledger.rs @@ -39,8 +39,8 @@ impl LedgerUtils { let request_json = CString::new(request_json).unwrap(); let err = - sovrin_sign_and_submit_request(pool_handle, - command_handle, + sovrin_sign_and_submit_request(command_handle, + pool_handle, wallet_handle, submitter_did.as_ptr(), request_json.as_ptr(), @@ -133,19 +133,18 @@ impl LedgerUtils { let submitter_did = CString::new(submitter_did).unwrap(); let target_did = CString::new(target_did).unwrap(); - let verkey = verkey.map(|s| CString::new(s).unwrap()); - let xref = xref.map(|s| CString::new(s).unwrap()); - let data = data.map(|s| CString::new(s).unwrap()); - let role = role.map(|s| CString::new(s).unwrap()); - + let verkey_str = verkey.map(|s| CString::new(s).unwrap()).unwrap_or(CString::new("").unwrap());; + let xref_str = xref.map(|s| CString::new(s).unwrap()).unwrap_or(CString::new("").unwrap());; + let data_str = data.map(|s| CString::new(s).unwrap()).unwrap_or(CString::new("").unwrap());; + let role_str = role.map(|s| CString::new(s).unwrap()).unwrap_or(CString::new("").unwrap());; let err = sovrin_build_nym_request(command_handle, submitter_did.as_ptr(), target_did.as_ptr(), - if verkey.is_some() { verkey.unwrap().as_ptr() } else { null() }, - if xref.is_some() { xref.unwrap().as_ptr() } else { null() }, - if data.is_some() { data.unwrap().as_ptr() } else { null() }, - if role.is_some() { role.unwrap().as_ptr() } else { null() }, + if verkey.is_some() { verkey_str.as_ptr() } else { null() }, + if xref.is_some() { xref_str.as_ptr() } else { null() }, + if data.is_some() { data_str.as_ptr() } else { null() }, + if role.is_some() { role_str.as_ptr() } else { null() }, cb); if err != ErrorCode::Success { @@ -173,18 +172,18 @@ impl LedgerUtils { let submitter_did = CString::new(submitter_did).unwrap(); let target_did = CString::new(target_did).unwrap(); - let hash = hash.map(|s| CString::new(s).unwrap()); - let raw = raw.map(|s| CString::new(s).unwrap()); - let enc = enc.map(|s| CString::new(s).unwrap()); + let hash_str = hash.map(|s| CString::new(s).unwrap()).unwrap_or(CString::new("").unwrap()); + let raw_str = raw.map(|s| CString::new(s).unwrap()).unwrap_or(CString::new("").unwrap()); + let enc_str = enc.map(|s| CString::new(s).unwrap()).unwrap_or(CString::new("").unwrap()); let err = sovrin_build_attrib_request(command_handle, submitter_did.as_ptr(), target_did.as_ptr(), - if hash.is_some() { hash.unwrap().as_ptr() } else { null() }, - if raw.is_some() { raw.unwrap().as_ptr() } else { null() }, - if enc.is_some() { enc.unwrap().as_ptr() } else { null() }, + if hash.is_some() { hash_str.as_ptr() } else { null() }, + if raw.is_some() { raw_str.as_ptr() } else { null() }, + if enc.is_some() { enc_str.as_ptr() } else { null() }, cb); if err != ErrorCode::Success { @@ -295,7 +294,7 @@ impl LedgerUtils { Ok(request_json) } - pub fn build_get_schema_request(submitter_did: &str, data: &str) -> Result { + pub fn build_get_schema_request(submitter_did: &str, dest: &str, data: &str) -> Result { let (sender, receiver) = channel(); let cb = Box::new(move |err, request_json| { @@ -305,11 +304,13 @@ impl LedgerUtils { let (command_handle, cb) = CallbackUtils::closure_to_build_request_cb(cb); let submitter_did = CString::new(submitter_did).unwrap(); + let dest = CString::new(dest).unwrap(); let data = CString::new(data).unwrap(); let err = sovrin_build_get_schema_request(command_handle, submitter_did.as_ptr(), + dest.as_ptr(), data.as_ptr(), cb); @@ -326,7 +327,7 @@ impl LedgerUtils { Ok(request_json) } - pub fn build_claim_def_txn(submitter_did: &str, xref: &str, signature_type: &str, data: &str) -> Result { + pub fn build_claim_def_txn(submitter_did: &str, xref: i32, signature_type: &str, data: &str) -> Result { let (sender, receiver) = channel(); let cb = Box::new(move |err, request_json| { @@ -336,14 +337,13 @@ impl LedgerUtils { let (command_handle, cb) = CallbackUtils::closure_to_build_request_cb(cb); let submitter_did = CString::new(submitter_did).unwrap(); - let xref = CString::new(xref).unwrap(); let signature_type = CString::new(signature_type).unwrap(); let data = CString::new(data).unwrap(); let err = sovrin_build_claim_def_txn(command_handle, submitter_did.as_ptr(), - xref.as_ptr(), + xref, signature_type.as_ptr(), data.as_ptr(), cb); @@ -361,7 +361,7 @@ impl LedgerUtils { Ok(request_json) } - pub fn build_get_claim_def_txn(submitter_did: &str, xref: &str, signature_type: &str) -> Result { + pub fn build_get_claim_def_txn(submitter_did: &str, xref: i32, signature_type: &str, origin: &str) -> Result { let (sender, receiver) = channel(); let cb = Box::new(move |err, request_json| { @@ -371,14 +371,15 @@ impl LedgerUtils { let (command_handle, cb) = CallbackUtils::closure_to_build_request_cb(cb); let submitter_did = CString::new(submitter_did).unwrap(); - let xref = CString::new(xref).unwrap(); let signature_type = CString::new(signature_type).unwrap(); + let origin = CString::new(origin).unwrap(); let err = sovrin_build_get_claim_def_txn(command_handle, submitter_did.as_ptr(), - xref.as_ptr(), + xref, signature_type.as_ptr(), + origin.as_ptr(), cb); if err != ErrorCode::Success { diff --git a/tests/utils/pool.rs b/tests/utils/pool.rs index ada8bcbdd5..fb4e8f58d1 100644 --- a/tests/utils/pool.rs +++ b/tests/utils/pool.rs @@ -84,6 +84,62 @@ impl PoolUtils { Ok(pool_handle) } + pub fn create_and_open_pool_ledger_config(pool_name: &str) -> Result { + let (sender, receiver) = channel(); + + let cb = Box::new(move |err| { + sender.send(err).unwrap(); + }); + + let (command_handle, cb) = CallbackUtils::closure_to_create_pool_ledger_cb(cb); + + PoolUtils::create_genesis_txn_file(pool_name); + let pool_config = CString::new(PoolUtils::create_pool_config(pool_name)).unwrap(); + let pool_name = CString::new(pool_name).unwrap(); + + let err = sovrin_create_pool_ledger_config(command_handle, + pool_name.as_ptr(), + pool_config.as_ptr(), + cb); + + if err != ErrorCode::Success { + return Err(err); + } + + let err = receiver.recv_timeout(TimeoutUtils::short_timeout()).unwrap(); + + if err != ErrorCode::Success { + return Err(err); + } + + let (open_sender, open_receiver) = channel(); + + let open_cb = Box::new(move |err, pool_handle| { + open_sender.send((err, pool_handle)).unwrap(); + }); + + let (open_command_handle, open_cb) = CallbackUtils::closure_to_open_pool_ledger_cb(open_cb); + + let pool_name = CString::new(pool_name).unwrap(); + + let err = sovrin_open_pool_ledger(open_command_handle, + pool_name.as_ptr(), + null(), + open_cb); + + if err != ErrorCode::Success { + return Err(err); + } + + let (err, pool_handle) = open_receiver.recv_timeout(TimeoutUtils::short_timeout()).unwrap(); + + if err != ErrorCode::Success { + return Err(err); + } + + Ok(pool_handle) + } + pub fn send_request(pool_handle: i32, request: &str) -> Result { let (sender, receiver) = channel(); let cb_send = Box::new(move |err, resp| { @@ -101,7 +157,7 @@ impl PoolUtils { return Err(err); } - let (err, resp) = receiver.recv_timeout(TimeoutUtils::short_timeout()).unwrap(); + let (err, resp) = receiver.recv_timeout(TimeoutUtils::medium_timeout()).unwrap(); if err != ErrorCode::Success { return Err(err); diff --git a/tests/utils/wallet.rs b/tests/utils/wallet.rs index 75ba3a9877..50e299c3d7 100644 --- a/tests/utils/wallet.rs +++ b/tests/utils/wallet.rs @@ -15,7 +15,7 @@ use std::sync::mpsc::channel; pub struct WalletUtils {} impl WalletUtils { - pub fn create_wallet(pool_name: &str, wallet_name: &str, xtype: &str) -> Result { + pub fn create_and_open_wallet(pool_name: &str, wallet_name: &str, xtype: &str) -> Result { let (sender, receiver) = channel(); let (open_sender, open_receiver) = channel();