CosmWasm / cw-storage-plus

Storage abstractions for CosmWasm smart contracts
Apache License 2.0
37 stars 27 forks source link

Error deserializing nested tuple keys #81

Closed larry0x closed 4 months ago

larry0x commented 4 months ago

When using a nested tuple as keys in a Map, the keys cannot be deserialized correctly. Example:

type NestedTuple<'a> = ((&'a str, &'a str), (&'a str, &'a str));

const MAP: Map<NestedTuple, u64> = Map::new("map");

#[test]
fn deserialize_nested_tuple_works() {
    let mut storage = MockStorage::new();

    let ((a, b), (c, d)) = (("larry", "engineer"), ("jake", "shepherd"));

    MAP.save(&mut storage, ((a, b), (c, d)), &123).unwrap();

    // Attempt to deserialize the nested tuple key by iterating the first record in the map
    let (k, _) = MAP
        .range(&storage, None, None, Order::Ascending)
        .next()
        .unwrap()
        .unwrap();

    assert_eq!(
        k,
        ((a.to_string(), b.to_string()), (c.to_string(), d.to_string()))
    );
}

This panics with message:

`at` split index (is 2) should be <= len (is 1)
chipshort commented 4 months ago

What version are you using? AFAIK, this was fixed in 2.0.0

larry0x commented 4 months ago

What version are you using? AFAIK, this was fixed in 2.0.0

You're right, I was in v1.