diff --git a/packages/storage-plus/src/indexed_map.rs b/packages/storage-plus/src/indexed_map.rs index 26531c2ea..d033c5746 100644 --- a/packages/storage-plus/src/indexed_map.rs +++ b/packages/storage-plus/src/indexed_map.rs @@ -278,8 +278,8 @@ mod test { struct DataIndexes<'a> { // Second arg is for storing pk pub name: MultiIndex<'a, (Vec, Vec), Data>, - pub age: UniqueIndex<'a, U32Key, Data, Vec>, - pub name_lastname: UniqueIndex<'a, (Vec, Vec), Data>, + pub age: UniqueIndex<'a, U32Key, Data, String>, + pub name_lastname: UniqueIndex<'a, (Vec, Vec), Data, String>, } // Future Note: this can likely be macro-derived @@ -826,6 +826,35 @@ mod test { assert_eq!(datas[1], marias[1].1); } + #[test] + fn unique_index_composite_key_range_de() { + let mut store = MockStorage::new(); + let map = build_map(); + + // save data + let (pks, datas) = save_data(&mut store, &map); + + let res: StdResult> = map + .idx + .name_lastname + .prefix(b"Maria".to_vec()) + .range_de(&store, None, None, Order::Ascending) + .collect(); + let marias = res.unwrap(); + + // Only two people are called "Maria" + let count = marias.len(); + assert_eq!(2, count); + + // The pks + assert_eq!(pks[0], marias[0].0); + assert_eq!(pks[1], marias[1].0); + + // The associated data + assert_eq!(datas[0], marias[0].1); + assert_eq!(datas[1], marias[1].1); + } + #[test] #[cfg(feature = "iterator")] fn range_de_simple_string_key() { diff --git a/packages/storage-plus/src/indexes.rs b/packages/storage-plus/src/indexes.rs index 1f00034d2..4b470b3a5 100644 --- a/packages/storage-plus/src/indexes.rs +++ b/packages/storage-plus/src/indexes.rs @@ -473,7 +473,7 @@ where #[cfg(feature = "iterator")] impl<'a, K, T, PK> UniqueIndex<'a, K, T, PK> where - PK: KeyDeserialize, + PK: PrimaryKey<'a> + KeyDeserialize, T: Serialize + DeserializeOwned + Clone, K: PrimaryKey<'a>, { @@ -484,8 +484,8 @@ where pub fn prefix_range_de<'c>( &self, store: &'c dyn Storage, - min: Option>, - max: Option>, + min: Option>, + max: Option>, order: cosmwasm_std::Order, ) -> Box> + 'c> where