From 64656252e523dad0707a94b14120bcd2a89d543c Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 16 Oct 2020 18:01:06 +0200 Subject: [PATCH] Resolve some TODOs --- contracts/cw721-base/src/contract.rs | 1 - packages/storage-plus/src/indexes.rs | 1 - packages/storage-plus/src/keys.rs | 23 ++++++++++++++++++++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/contracts/cw721-base/src/contract.rs b/contracts/cw721-base/src/contract.rs index 4acfa16e1..22fe2ecd2 100644 --- a/contracts/cw721-base/src/contract.rs +++ b/contracts/cw721-base/src/contract.rs @@ -522,7 +522,6 @@ fn query_tokens( .take(limit) .map(String::from_utf8) .collect(); - // TODO: make issue on CosmWasm to add impl From for StdError let tokens = tokens.map_err(StdError::invalid_utf8)?; Ok(TokensResponse { tokens }) } diff --git a/packages/storage-plus/src/indexes.rs b/packages/storage-plus/src/indexes.rs index 244b346d7..899ee3e88 100644 --- a/packages/storage-plus/src/indexes.rs +++ b/packages/storage-plus/src/indexes.rs @@ -37,7 +37,6 @@ where S: Storage, T: Serialize + DeserializeOwned + Clone, { - // TODO: pk: PrimaryKey not just &[u8] ??? fn save(&self, store: &mut S, pk: &[u8], data: &T) -> StdResult<()>; fn remove(&self, store: &mut S, pk: &[u8], old_data: &T) -> StdResult<()>; } diff --git a/packages/storage-plus/src/keys.rs b/packages/storage-plus/src/keys.rs index 759a54c97..ecc68a680 100644 --- a/packages/storage-plus/src/keys.rs +++ b/packages/storage-plus/src/keys.rs @@ -115,7 +115,7 @@ impl EmptyPrefix for () { } // Add support for an dynamic keys - constructor functions below -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct PkOwned(pub Vec); impl<'a> PrimaryKey<'a> for PkOwned { @@ -167,7 +167,7 @@ pub type U128Key = IntKey; /// let k = U64Key::new(12345); /// let k = U32Key::from(12345); /// let k: U16Key = 12345.into(); -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct IntKey { pub wrapped: PkOwned, pub data: PhantomData, @@ -299,5 +299,22 @@ mod test { assert_eq!(key, parsed); } - // TODO: parse joined with int/owned keys + #[test] + fn parse_joined_keys_int() { + let key: U64Key = 12345678.into(); + let joined = key.joined_key(); + assert_eq!(8, joined.len()); + let parsed = U64Key::parse_key(&joined); + assert_eq!(key, parsed); + } + + #[test] + fn parse_joined_keys_string_int() { + let key: (U32Key, &str) = (54321.into(), "random"); + let joined = key.joined_key(); + assert_eq!(2 + 4 + 6, joined.len()); + let parsed = <(U32Key, &str)>::parse_key(&joined); + assert_eq!(key, parsed); + assert_eq!("random", parsed.1); + } }