-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[Feature] Introduce storage_alias for CountedStorageMap #13366
Changes from 5 commits
43b36a5
1e45f30
fc974b3
b410020
60ab3e8
51c45d3
82c71f9
7ed34ff
79378d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -543,6 +543,16 @@ mod test { | |
97 | ||
} | ||
} | ||
#[crate::storage_alias] | ||
type ExampleCountedMap = CountedStorageMap<Prefix, Twox64Concat, u16, u32>; | ||
|
||
#[test] | ||
fn storage_alias_works() { | ||
TestExternalities::default().execute_with(|| { | ||
assert_eq!(ExampleCountedMap::count(), 0); | ||
ExampleCountedMap::insert(3, 10); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add some test that the storage alias works the same as the normal counted storage map from the pallet macro? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically insert and count are the two functions that prove that CountedStorageMap works as intended thru the macro, otherwise it does not compile. The rest of the functionality is tested for the normal CountedStorageMap. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But I guess testing the prefixes would be nice, will do! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added some tests alongside pallet storage, which revealed a couple of issues. Seems to be all good now! |
||
}) | ||
} | ||
|
||
#[test] | ||
fn test_value_query() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1906,14 +1906,26 @@ fn assert_type_all_pallets_without_system_reversed_is_correct() { | |
|
||
#[test] | ||
fn test_storage_alias() { | ||
use frame_support::Twox64Concat; | ||
|
||
#[frame_support::storage_alias] | ||
type Value<T: pallet::Config> | ||
where | ||
<T as frame_system::Config>::AccountId: From<SomeType1> + SomeAssociation1, | ||
= StorageValue<pallet::Pallet<T>, u32, ValueQuery>; | ||
|
||
#[frame_support::storage_alias] | ||
type SomeCountedStorageMap<T: pallet2::Config> | ||
where | ||
<T as frame_system::Config>::AccountId: From<SomeType1> + SomeAssociation1, | ||
= CountedStorageMap<pallet2::Pallet<T>, Twox64Concat, u8, u32>; | ||
|
||
TestExternalities::default().execute_with(|| { | ||
pallet::Value::<Runtime>::put(10); | ||
assert_eq!(10, Value::<Runtime>::get()); | ||
|
||
pallet2::SomeCountedStorageMap::<Runtime>::insert(10, 100); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you also check that the returned meta-data is identical to the non-alias version? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Care to elaborate? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done in 79378d1 |
||
assert_eq!(Some(100), SomeCountedStorageMap::<Runtime>::get(10)); | ||
assert_eq!(1, SomeCountedStorageMap::<Runtime>::count()); | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bkchr couldn't find a better place tbh, felt wrong to create it's own file for it, seeing as how
lib.rs
already has a couple of helpers. If we keep moving stuff to be more general - might be worth actually considering it's own file.