Skip to content

Commit

Permalink
Merge pull request #778 from CosmWasm/775-remove-intkeyold
Browse files Browse the repository at this point in the history
Remove deprecated `IntKeyOld`
  • Loading branch information
maurolacy authored Aug 16, 2022
2 parents 64e4a4e + 23136bb commit 3843941
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 297 deletions.
2 changes: 1 addition & 1 deletion packages/storage-plus/benches/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rand::Rng;
use std::mem;
use std::time::Duration;

use cw_storage_plus::CwIntKey;
use cw_storage_plus::IntKey;

fn bench_signed_int_key(c: &mut Criterion) {
let mut group = c.benchmark_group("Signed int keys");
Expand Down
2 changes: 1 addition & 1 deletion packages/storage-plus/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::convert::TryInto;

use cosmwasm_std::{Addr, StdError, StdResult};

use crate::int_key::CwIntKey;
use crate::int_key::IntKey;

pub trait KeyDeserialize {
type Output: Sized;
Expand Down
106 changes: 0 additions & 106 deletions packages/storage-plus/src/de_old.rs

This file was deleted.

7 changes: 3 additions & 4 deletions packages/storage-plus/src/int_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use std::mem;
/// but "sign-flipped" (xored msb) big-endian bytes for signed ints.
///
/// So that the representation of signed integers is in the right lexicographical order.
// TODO: Rename to `IntKey` after deprecating current `IntKey` (https://github.com/CosmWasm/cw-plus/issues/570)
pub trait CwIntKey: Sized + Copy {
pub trait IntKey: Sized + Copy {
type Buf: AsRef<[u8]> + AsMut<[u8]> + Into<Vec<u8>> + Default;

fn to_cw_bytes(&self) -> Self::Buf;
Expand All @@ -14,7 +13,7 @@ pub trait CwIntKey: Sized + Copy {

macro_rules! cw_uint_keys {
(for $($t:ty),+) => {
$(impl CwIntKey for $t {
$(impl IntKey for $t {
type Buf = [u8; mem::size_of::<$t>()];

#[inline]
Expand All @@ -34,7 +33,7 @@ cw_uint_keys!(for u8, u16, u32, u64, u128);

macro_rules! cw_int_keys {
(for $($t:ty, $ut:ty),+) => {
$(impl CwIntKey for $t {
$(impl IntKey for $t {
type Buf = [u8; mem::size_of::<$t>()];

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion packages/storage-plus/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use cosmwasm_std::Addr;

use crate::de::KeyDeserialize;
use crate::helpers::namespaces_with_key;
use crate::int_key::CwIntKey;
use crate::int_key::IntKey;

#[derive(Debug)]
pub enum Key<'a> {
Expand Down
105 changes: 0 additions & 105 deletions packages/storage-plus/src/keys_old.rs

This file was deleted.

5 changes: 1 addition & 4 deletions packages/storage-plus/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
mod bound;
mod de;
mod de_old;
mod endian;
mod helpers;
mod indexed_map;
Expand All @@ -10,7 +9,6 @@ mod int_key;
mod item;
mod iter_helpers;
mod keys;
mod keys_old;
mod map;
mod path;
mod prefix;
Expand All @@ -30,10 +28,9 @@ pub use indexes::Index;
pub use indexes::MultiIndex;
#[cfg(feature = "iterator")]
pub use indexes::UniqueIndex;
pub use int_key::CwIntKey;
pub use int_key::IntKey;
pub use item::Item;
pub use keys::{Key, Prefixer, PrimaryKey};
pub use keys_old::IntKeyOld;
pub use map::Map;
pub use path::Path;
#[cfg(feature = "iterator")]
Expand Down
76 changes: 1 addition & 75 deletions packages/storage-plus/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,7 @@ mod test {
#[cfg(feature = "iterator")]
use crate::bound::Bounder;

use crate::int_key::CwIntKey;
#[cfg(feature = "iterator")]
use crate::IntKeyOld;
use crate::int_key::IntKey;

#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
struct Data {
Expand All @@ -293,8 +291,6 @@ mod test {
#[cfg(feature = "iterator")]
const PEOPLE_ID: Map<u32, Data> = Map::new("people_id");
#[cfg(feature = "iterator")]
const SIGNED_ID_OLD: Map<IntKeyOld<i32>, Data> = Map::new("signed_id");
#[cfg(feature = "iterator")]
const SIGNED_ID: Map<i32, Data> = Map::new("signed_id");

const ALLOWANCE: Map<(&[u8], &[u8]), u64> = Map::new("allow");
Expand Down Expand Up @@ -860,76 +856,6 @@ mod test {
assert_eq!(all, vec![(50, data3)]);
}

#[test]
#[cfg(feature = "iterator")]
fn range_signed_integer_key_migration() {
let mut store = MockStorage::new();

// save and load three keys with the old format
let data = Data {
name: "John".to_string(),
age: 32,
};
SIGNED_ID_OLD
.save(&mut store, IntKeyOld::<i32>::from(-1234), &data)
.unwrap();

let data2 = Data {
name: "Jim".to_string(),
age: 44,
};
SIGNED_ID_OLD
.save(&mut store, IntKeyOld::<i32>::from(-56), &data2)
.unwrap();

let data3 = Data {
name: "Jules".to_string(),
age: 55,
};
SIGNED_ID_OLD
.save(&mut store, IntKeyOld::<i32>::from(50), &data3)
.unwrap();

// obtain all current keys
let current = SIGNED_ID_OLD
.range(&store, None, None, Order::Ascending)
.collect::<StdResult<Vec<_>>>()
.unwrap();
// confirm wrong current order
assert_eq!(
current,
vec![
(50, data3.clone()),
(-1234, data.clone()),
(-56, data2.clone())
]
);

// remove old entries
for (k, _) in current.iter() {
SIGNED_ID_OLD.remove(&mut store, (*k).into());
}

// confirm map is empty
assert!(SIGNED_ID_OLD
.range(&store, None, None, Order::Ascending)
.next()
.is_none());

// save in new format
for (k, v) in current.into_iter() {
SIGNED_ID.save(&mut store, k, &v).unwrap();
}

// obtain new keys
let new = SIGNED_ID
.range(&store, None, None, Order::Ascending)
.collect::<StdResult<Vec<_>>>()
.unwrap();
// confirm new order is right
assert_eq!(new, vec![(-1234, data), (-56, data2), (50, data3)]);
}

#[test]
#[cfg(feature = "iterator")]
fn range_raw_composite_key() {
Expand Down

0 comments on commit 3843941

Please sign in to comment.