Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move test helpers into a test section #709

Merged
merged 5 commits into from
Jul 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/storage-plus/src/indexed_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ where
mod test {
use super::*;

use crate::indexes::index_string_tuple;
use crate::{index_tuple, MultiIndex, UniqueIndex};
use crate::indexes::test::{index_string_tuple, index_tuple};
use crate::{MultiIndex, UniqueIndex};
use cosmwasm_std::testing::MockStorage;
use cosmwasm_std::{MemoryStorage, Order};
use serde::{Deserialize, Serialize};
Expand Down
4 changes: 2 additions & 2 deletions packages/storage-plus/src/indexed_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ where
mod test {
use super::*;

use crate::indexes::index_string_tuple;
use crate::{index_tuple, Index, MultiIndex, UniqueIndex};
use crate::indexes::test::{index_string_tuple, index_tuple};
use crate::{Index, MultiIndex, UniqueIndex};
use cosmwasm_std::testing::MockStorage;
use cosmwasm_std::{MemoryStorage, Order};
use serde::{Deserialize, Serialize};
Expand Down
32 changes: 16 additions & 16 deletions packages/storage-plus/src/indexes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,6 @@ use serde::Serialize;

use cosmwasm_std::{StdResult, Storage};

pub fn index_string(data: &str) -> Vec<u8> {
data.as_bytes().to_vec()
}

pub fn index_tuple(name: &str, age: u32) -> (Vec<u8>, u32) {
(index_string(name), age)
}

pub fn index_triple(name: &str, age: u32, pk: Vec<u8>) -> (Vec<u8>, u32, Vec<u8>) {
(index_string(name), age, pk)
}

pub fn index_string_tuple(data1: &str, data2: &str) -> (Vec<u8>, Vec<u8>) {
(index_string(data1), index_string(data2))
}

// Note: we cannot store traits with generic functions inside `Box<dyn Index>`,
// so I pull S: Storage to a top-level
pub trait Index<T>
Expand All @@ -36,3 +20,19 @@ where
fn save(&self, store: &mut dyn Storage, pk: &[u8], data: &T) -> StdResult<()>;
fn remove(&self, store: &mut dyn Storage, pk: &[u8], old_data: &T) -> StdResult<()>;
}

#[cfg(test)]
pub mod test {

pub fn index_string(data: &str) -> Vec<u8> {
data.as_bytes().to_vec()
}

pub fn index_tuple(name: &str, age: u32) -> (Vec<u8>, u32) {
(index_string(name), age)
}

pub fn index_string_tuple(data1: &str, data2: &str) -> (Vec<u8>, Vec<u8>) {
(index_string(data1), index_string(data2))
}
}
4 changes: 2 additions & 2 deletions packages/storage-plus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ pub use indexed_map::{IndexList, IndexedMap};
#[cfg(feature = "iterator")]
pub use indexed_snapshot::IndexedSnapshotMap;
#[cfg(feature = "iterator")]
pub use indexes::Index;
#[cfg(feature = "iterator")]
pub use indexes::MultiIndex;
#[cfg(feature = "iterator")]
pub use indexes::UniqueIndex;
#[cfg(feature = "iterator")]
pub use indexes::{index_string, index_string_tuple, index_triple, index_tuple, Index};
pub use int_key::CwIntKey;
pub use item::Item;
pub use keys::{Key, Prefixer, PrimaryKey};
Expand Down