paritytech / polkadot-sdk

The Parity Polkadot Blockchain SDK
https://polkadot.network/
1.8k stars 652 forks source link

StorageMap remove does not clear the key #5717

Closed dvcpull closed 2 weeks ago

dvcpull commented 2 weeks ago

Is there an existing issue?

Experiencing problems? Have you tried our Stack Exchange first?

Description of bug

Lets say we have a StorageMap like this

    #[pallet::storage]
    pub type ItemsToProcess<T: Config<I>, I: 'static = ()> = StorageMap<
        _,
        Blake2_128Concat,
        BlockNumberFor<T>,
        BoundedVec<u32, T::MaxItemsToProcess>,
        ValueQuery,
    >;

Lets say we insert a key and remove it later like this

ItemsToProcess::<T>::insert(1, vec![].try_into().unwrap());

...

ItemsToProcess::<T>::remove(1);

When running test, this test fails (even after the removal of key, the contains key returns true)

assert!(!ItemsToProcess::<T>::contains_key(1))

This is inconsistent with searching for a random key, like this where it returns false correctly

assert!(ItemsToProcess::<T>::contains_key(123))

Steps to reproduce

No response

ggwpez commented 1 week ago

Why was it closed?

dvcpull commented 1 week ago

misunderstanding, not a bug