Skip to content

Commit 9490701

Browse files
committed
retrieveType was not working in search
Signed-off-by: Darko Kulic <[email protected]>
1 parent c7a22ee commit 9490701

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

libindy/src/services/wallet/iterator.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ impl WalletIterator {
3535

3636
let tags = decrypt_tags(&next_storage_entity.tags, &self.keys.tag_name_key, &self.keys.tag_value_key)?;
3737

38-
Ok(Some(WalletRecord::new(name, None, value, tags)))
38+
let type_ = match next_storage_entity.type_ {
39+
None => None,
40+
Some(encrypted_type) => Some(String::from_utf8(decrypt(&encrypted_type, &self.keys.type_key)?)?)
41+
};
42+
43+
Ok(Some(WalletRecord::new(name, type_, value, tags)))
3944
} else { Ok(None) }
4045
}
4146

libindy/src/services/wallet/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ impl WalletService {
526526
}
527527
}
528528

529-
#[derive(Debug, Clone, Serialize, Deserialize)]
529+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
530530
pub struct WalletRecord {
531531
#[serde(rename = "id")]
532532
name: String,

libindy/src/services/wallet/wallet.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -747,17 +747,31 @@ mod tests {
747747
#[test]
748748
fn wallet_search_empty_query_with_count() {
749749
_cleanup();
750+
751+
let type_ = "test_type_";
752+
let name = "foo";
753+
let value = "bar";
754+
let tags = r#"{"tag1":"tag_value1"}"#;
755+
750756
let wallet = _create_wallet();
751-
wallet.add("test_type_", "foo", "bar", r#"{"tag1":"tags2"}"#).unwrap();
752-
let fetch_options = &_search_options(true, true, false, true, false);
757+
758+
wallet.add(type_, name, value, tags).unwrap();
759+
let fetch_options = &_search_options(true, true, true, true, true);
753760

754761
// successful encrypted search
755762
let query_json = "{}";
756763
let mut iterator = wallet.search("test_type_", query_json, Some(fetch_options)).unwrap();
757764

758765
let res = iterator.next().unwrap().unwrap();
759-
assert_eq!(res.name, "foo".to_string());
760-
assert_eq!(res.value.unwrap(), "bar".to_string());
766+
767+
let exp_tags: HashMap<String, String> = serde_json::from_str(tags).unwrap();
768+
let expected = WalletRecord{
769+
name: name.to_string(),
770+
value: Some(value.to_string()),
771+
tags: Some(exp_tags),
772+
type_: Some(type_.to_string()),
773+
};
774+
assert_eq!(res, expected);
761775

762776
let res = iterator.next().unwrap();
763777
assert!(res.is_none());

0 commit comments

Comments
 (0)