Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macros to use path instead of ident #1474

Merged
merged 34 commits into from
Oct 14, 2023
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7102f28
use path instead of ident
juangirini Sep 8, 2023
933fd3f
fix clippy
juangirini Sep 8, 2023
dc43fa5
add path changes to frame_support
juangirini Sep 11, 2023
16668ca
add frame conditional
juangirini Sep 11, 2023
ebd13e3
remove references to the frame-crate
juangirini Sep 11, 2023
270a6b7
update fn description
juangirini Sep 11, 2023
8be65aa
update fn description
juangirini Sep 11, 2023
850a77e
make benchmarks to use generate_crate_access_2018
juangirini Sep 11, 2023
5ae6e07
undo unrelated changes
juangirini Sep 12, 2023
04dc503
undo unrelated changes
juangirini Sep 12, 2023
95444ae
update macro description
juangirini Sep 12, 2023
6a773d0
refactor `generate_crate_access`
juangirini Sep 12, 2023
bc17557
unhardcode codec import
juangirini Sep 13, 2023
6d9887b
bring in hypotetical frame crate
juangirini Sep 14, 2023
35747a1
refactor expected_system_config and add tests
juangirini Sep 15, 2023
330af4a
".git/.scripts/commands/fmt/fmt.sh"
Sep 15, 2023
10bf65c
make zepter happy
juangirini Sep 15, 2023
97bfec4
improve comment
juangirini Sep 21, 2023
6a07bb3
add event_type_bound_system_config_assoc_type test
juangirini Sep 22, 2023
f303276
implement review suggestions
juangirini Oct 2, 2023
963be94
implement review suggestions
juangirini Oct 2, 2023
76de90d
add dummy frame crate for testing
juangirini Oct 3, 2023
32f2f1e
add pallet test example with frame crate
juangirini Oct 4, 2023
877fdc3
wip
juangirini Oct 4, 2023
c89c0c7
make dummy pallet work with frame crate
juangirini Oct 4, 2023
8184085
add dummy pallet with frame crate
juangirini Oct 4, 2023
1ee920b
add min runtime ui test
juangirini Oct 6, 2023
5050625
simplify example pallet
juangirini Oct 12, 2023
55daf79
update comment
juangirini Oct 12, 2023
43ca2c2
zepter improvement
juangirini Oct 12, 2023
2a2b45f
Merge branch 'master' into jg/frame-crate-path
juangirini Oct 12, 2023
b55615b
fix broken test
juangirini Oct 12, 2023
d253b66
update compile test
juangirini Oct 13, 2023
d2009d3
fix todo
juangirini Oct 13, 2023
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
make benchmarks to use generate_crate_access_2018
  • Loading branch information
juangirini committed Sep 11, 2023
commit 850a77eadb8d6a2a785692f301d896549512dec8
23 changes: 14 additions & 9 deletions substrate/frame/support/procedural/src/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ pub fn benchmarks(
};

let krate = generate_crate_access_2018("frame-benchmarking")?;
let frame_system = generate_crate_access_2018("frame-system")?;
juangirini marked this conversation as resolved.
Show resolved Hide resolved

// benchmark name variables
let benchmark_names_str: Vec<String> = benchmark_names.iter().map(|n| n.to_string()).collect();
Expand Down Expand Up @@ -488,7 +489,7 @@ pub fn benchmarks(
}
#[cfg(any(feature = "runtime-benchmarks", test))]
impl<#type_impl_generics> #krate::Benchmarking for Pallet<#type_use_generics>
where T: frame_system::Config, #where_clause
kianenigma marked this conversation as resolved.
Show resolved Hide resolved
where T: #frame_system::Config, #where_clause
{
fn benchmarks(
extra: bool,
Expand Down Expand Up @@ -535,7 +536,7 @@ pub fn benchmarks(
_ => return Err("Could not find extrinsic.".into()),
};
let mut whitelist = whitelist.to_vec();
let whitelisted_caller_key = <frame_system::Account<
let whitelisted_caller_key = <#frame_system::Account<
T,
> as #krate::__private::storage::StorageMap<_, _,>>::hashed_key_for(
#krate::whitelisted_caller::<T::AccountId>()
Expand Down Expand Up @@ -571,8 +572,8 @@ pub fn benchmarks(
>::instance(&selected_benchmark, c, verify)?;

// Set the block number to at least 1 so events are deposited.
if #krate::__private::Zero::is_zero(&frame_system::Pallet::<T>::block_number()) {
frame_system::Pallet::<T>::set_block_number(1u32.into());
if #krate::__private::Zero::is_zero(&#frame_system::Pallet::<T>::block_number()) {
#frame_system::Pallet::<T>::set_block_number(1u32.into());
}

// Commit the externalities to the database, flushing the DB cache.
Expand Down Expand Up @@ -654,7 +655,7 @@ pub fn benchmarks(
}

#[cfg(test)]
impl<#type_impl_generics> Pallet<#type_use_generics> where T: ::frame_system::Config, #where_clause {
impl<#type_impl_generics> Pallet<#type_use_generics> where T: #frame_system::Config, #where_clause {
/// Test a particular benchmark by name.
///
/// This isn't called `test_benchmark_by_name` just in case some end-user eventually
Expand Down Expand Up @@ -723,6 +724,10 @@ fn expand_benchmark(
Ok(ident) => ident,
Err(err) => return err.to_compile_error().into(),
};
let frame_system = match generate_crate_access_2018("frame-system") {
Ok(path) => path,
Err(err) => return err.to_compile_error().into(),
};
juangirini marked this conversation as resolved.
Show resolved Hide resolved
let codec = quote!(#krate::__private::codec);
let traits = quote!(#krate::__private::traits);
let setup_stmts = benchmark_def.setup_stmts;
Expand Down Expand Up @@ -762,7 +767,7 @@ fn expand_benchmark(
Expr::Cast(t) => {
let ty = t.ty.clone();
quote! {
<<T as frame_system::Config>::RuntimeOrigin as From<#ty>>::from(#origin);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of this seem to have been hardcoded 🙈 well, not like anything broke because of it, but indeed not a good practice.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless if was intentional? but I can't see a reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see a reason either, and we need this unhardcoded moving forward to work with the frame umbrella crate

<<T as #frame_system::Config>::RuntimeOrigin as From<#ty>>::from(#origin);
}
},
_ => quote! {
Expand Down Expand Up @@ -932,7 +937,7 @@ fn expand_benchmark(
}

#[cfg(test)]
impl<#type_impl_generics> Pallet<#type_use_generics> where T: ::frame_system::Config, #where_clause {
impl<#type_impl_generics> Pallet<#type_use_generics> where T: #frame_system::Config, #where_clause {
#[allow(unused)]
fn #test_ident() -> Result<(), #krate::BenchmarkError> {
let selected_benchmark = SelectedBenchmark::#name;
Expand All @@ -951,8 +956,8 @@ fn expand_benchmark(
>::instance(&selected_benchmark, &c, true)?;

// Set the block number to at least 1 so events are deposited.
if #krate::__private::Zero::is_zero(&frame_system::Pallet::<T>::block_number()) {
frame_system::Pallet::<T>::set_block_number(1u32.into());
if #krate::__private::Zero::is_zero(&#frame_system::Pallet::<T>::block_number()) {
#frame_system::Pallet::<T>::set_block_number(1u32.into());
}

// Run execution + verification
Expand Down