Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
some tests and fixes
  • Loading branch information
ruseinov committed Feb 13, 2023
commit 60ab3e86d5bb646b0ef2851620d17948e2cb0add
9 changes: 5 additions & 4 deletions frame/support/procedural/src/storage_alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,9 +597,8 @@ fn generate_storage_instance(
let storage_name_str = storage_name.to_string();

let counter_code = is_counted_map.then(|| {

let counter_name = Ident::new(&counter_prefix(&name.to_string()), Span::call_site());
let counter_storage_name_str = "counter_".to_owned() + &storage_name_str;
let counter_storage_name_str = counter_prefix(&storage_name_str);

quote! {
#visibility struct #counter_name< #impl_generics >(
Expand All @@ -616,8 +615,10 @@ fn generate_storage_instance(
const STORAGE_PREFIX: &'static str = #counter_storage_name_str;
}

impl<#impl_generics> #crate_::storage::types::CountedStorageMapInstance for #name< #impl_generics > {
type CounterPrefix = #counter_name;
impl<#impl_generics> #crate_::storage::types::CountedStorageMapInstance
for #name< #type_generics > #where_clause
{
type CounterPrefix = #counter_name < #type_generics >;
}
}
});
Expand Down
12 changes: 12 additions & 0 deletions frame/support/test/tests/pallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

Care to elaborate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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());
})
}