I'm using a CountedStorageMap in my custom pallet to store a map of created Things.

#[pallet::getter(fn things)]
pub type Things<T> = CountedStorageMap<Hasher = Blake2_128Concat, Key = u64, Value = Thing<T>>;

I'm able to call the getter, things(THING_ID), fine in my tests.

let _ = ThingsModule::things(THING_ID);

How do I call the count function on my pallet to assert stored totals?

1 Answer 1


The count function is on the Things<T> type so:

let count = Things::<T>::count();

Also note that:

let _ = ThingsModule::things(THING_ID);

is the same as:

let _ = Things::<T>::get();

And IMO the second syntax is preferable as it is easier to audit the different uses of Things<T>, versus some simple getter function which hides that behind some macro magic.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.