From 9ddb7cb27d7bf2d79df79b07e0177da14883b1b8 Mon Sep 17 00:00:00 2001 From: a-moreira Date: Wed, 25 Jan 2023 13:07:39 -0300 Subject: [PATCH 1/8] pub enum Runtime -> pub struct Runtime --- .../test/tests/construct_runtime_ui/abundant_where_param.rs | 2 +- .../tests/construct_runtime_ui/both_use_and_excluded_parts.rs | 2 +- .../test/tests/construct_runtime_ui/conflicting_index.rs | 2 +- .../test/tests/construct_runtime_ui/conflicting_index_2.rs | 2 +- .../test/tests/construct_runtime_ui/conflicting_module_name.rs | 2 +- .../test/tests/construct_runtime_ui/double_module_parts.rs | 2 +- .../test/tests/construct_runtime_ui/duplicate_exclude.rs | 2 +- .../test/tests/construct_runtime_ui/empty_pallet_path.rs | 2 +- .../test/tests/construct_runtime_ui/exclude_missspell.rs | 2 +- .../test/tests/construct_runtime_ui/exclude_undefined_part.rs | 2 +- .../tests/construct_runtime_ui/feature_gated_system_pallet.rs | 2 +- .../tests/construct_runtime_ui/generics_in_invalid_module.rs | 2 +- .../test/tests/construct_runtime_ui/invalid_meta_literal.rs | 2 +- .../test/tests/construct_runtime_ui/invalid_module_details.rs | 2 +- .../construct_runtime_ui/invalid_module_details_keyword.rs | 2 +- .../test/tests/construct_runtime_ui/invalid_module_entry.rs | 2 +- .../tests/construct_runtime_ui/invalid_token_after_module.rs | 2 +- .../test/tests/construct_runtime_ui/invalid_token_after_name.rs | 2 +- .../test/tests/construct_runtime_ui/invalid_where_param.rs | 2 +- .../missing_event_generic_on_module_with_instance.rs | 2 +- .../test/tests/construct_runtime_ui/missing_module_instance.rs | 2 +- .../missing_origin_generic_on_module_with_instance.rs | 2 +- .../test/tests/construct_runtime_ui/missing_system_module.rs | 2 +- .../test/tests/construct_runtime_ui/missing_where_block.rs | 2 +- .../test/tests/construct_runtime_ui/missing_where_param.rs | 2 +- .../test/tests/construct_runtime_ui/more_than_256_modules.rs | 2 +- .../test/tests/construct_runtime_ui/no_comma_after_where.rs | 2 +- .../test/tests/construct_runtime_ui/no_std_genesis_config.rs | 2 +- .../tests/construct_runtime_ui/old_unsupported_pallet_decl.rs | 2 +- .../test/tests/construct_runtime_ui/pallet_error_too_large.rs | 2 +- .../test/tests/construct_runtime_ui/undefined_call_part.rs | 2 +- .../test/tests/construct_runtime_ui/undefined_event_part.rs | 2 +- .../tests/construct_runtime_ui/undefined_genesis_config_part.rs | 2 +- .../test/tests/construct_runtime_ui/undefined_inherent_part.rs | 2 +- .../test/tests/construct_runtime_ui/undefined_origin_part.rs | 2 +- .../construct_runtime_ui/undefined_validate_unsigned_part.rs | 2 +- .../tests/construct_runtime_ui/unsupported_meta_structure.rs | 2 +- .../test/tests/construct_runtime_ui/unsupported_pallet_attr.rs | 2 +- .../test/tests/construct_runtime_ui/use_undefined_part.rs | 2 +- 39 files changed, 39 insertions(+), 39 deletions(-) diff --git a/frame/support/test/tests/construct_runtime_ui/abundant_where_param.rs b/frame/support/test/tests/construct_runtime_ui/abundant_where_param.rs index d5e9f225219de..ab55c22e9fbf1 100644 --- a/frame/support/test/tests/construct_runtime_ui/abundant_where_param.rs +++ b/frame/support/test/tests/construct_runtime_ui/abundant_where_param.rs @@ -1,7 +1,7 @@ use frame_support::construct_runtime; construct_runtime! { - pub enum Runtime where + pub struct Runtime where Block = Block, NodeBlock = Block, Block = Block1, diff --git a/frame/support/test/tests/construct_runtime_ui/both_use_and_excluded_parts.rs b/frame/support/test/tests/construct_runtime_ui/both_use_and_excluded_parts.rs index 7a074db9986a2..ea468d6de13ee 100644 --- a/frame/support/test/tests/construct_runtime_ui/both_use_and_excluded_parts.rs +++ b/frame/support/test/tests/construct_runtime_ui/both_use_and_excluded_parts.rs @@ -20,7 +20,7 @@ pub type UncheckedExtrinsic = generic::UncheckedExtrinsic Date: Fri, 27 Jan 2023 13:38:19 -0300 Subject: [PATCH 2/8] changing some more --- bin/node/runtime/src/lib.rs | 2 +- frame/bags-list/src/mock.rs | 2 +- frame/election-provider-multi-phase/src/mock.rs | 2 +- frame/election-provider-support/src/onchain.rs | 2 +- frame/executive/src/lib.rs | 2 +- frame/fast-unstake/src/mock.rs | 2 +- frame/im-online/src/mock.rs | 2 +- frame/nomination-pools/benchmarking/src/mock.rs | 2 +- frame/nomination-pools/src/mock.rs | 2 +- frame/nomination-pools/test-staking/src/mock.rs | 2 +- frame/offences/src/mock.rs | 2 +- frame/support/test/compile_pass/src/lib.rs | 2 +- frame/support/test/tests/construct_runtime.rs | 2 +- frame/support/test/tests/instance.rs | 2 +- frame/support/test/tests/issue2219.rs | 2 +- frame/support/test/tests/pallet.rs | 2 +- frame/support/test/tests/pallet_compatibility.rs | 2 +- frame/support/test/tests/pallet_compatibility_instance.rs | 2 +- frame/support/test/tests/pallet_instance.rs | 2 +- frame/support/test/tests/pallet_with_name_trait_is_valid.rs | 2 +- frame/support/test/tests/storage_layers.rs | 2 +- frame/system/benches/bench.rs | 2 +- frame/transaction-payment/asset-tx-payment/src/mock.rs | 2 +- frame/transaction-payment/src/mock.rs | 2 +- 24 files changed, 24 insertions(+), 24 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index bd8a395d15243..7f6b1b69e4139 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -1701,7 +1701,7 @@ impl frame_benchmarking_pallet_pov::Config for Runtime { } construct_runtime!( - pub enum Runtime where + pub struct Runtime where Block = Block, NodeBlock = node_primitives::Block, UncheckedExtrinsic = UncheckedExtrinsic diff --git a/frame/bags-list/src/mock.rs b/frame/bags-list/src/mock.rs index 8cc96a988e72a..224cae29078a8 100644 --- a/frame/bags-list/src/mock.rs +++ b/frame/bags-list/src/mock.rs @@ -88,7 +88,7 @@ impl bags_list::Config for Runtime { type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; frame_support::construct_runtime!( - pub enum Runtime where + pub struct Runtime where Block = Block, NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic, diff --git a/frame/election-provider-multi-phase/src/mock.rs b/frame/election-provider-multi-phase/src/mock.rs index 347a4f19185f9..daf44157e4ffd 100644 --- a/frame/election-provider-multi-phase/src/mock.rs +++ b/frame/election-provider-multi-phase/src/mock.rs @@ -54,7 +54,7 @@ pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic; frame_support::construct_runtime!( - pub enum Runtime where + pub struct Runtime where Block = Block, NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic diff --git a/frame/election-provider-support/src/onchain.rs b/frame/election-provider-support/src/onchain.rs index 483c402fe249c..1c3a6e1c67e28 100644 --- a/frame/election-provider-support/src/onchain.rs +++ b/frame/election-provider-support/src/onchain.rs @@ -197,7 +197,7 @@ mod tests { pub type Block = sp_runtime::generic::Block; frame_support::construct_runtime!( - pub enum Runtime where + pub struct Runtime where Block = Block, NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index b454d1e276cc8..81bf32c63a9cd 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -838,7 +838,7 @@ mod tests { } frame_support::construct_runtime!( - pub enum Runtime where + pub struct Runtime where Block = TestBlock, NodeBlock = TestBlock, UncheckedExtrinsic = TestUncheckedExtrinsic diff --git a/frame/fast-unstake/src/mock.rs b/frame/fast-unstake/src/mock.rs index 38cf41fdebe8b..e7f08d400f8c4 100644 --- a/frame/fast-unstake/src/mock.rs +++ b/frame/fast-unstake/src/mock.rs @@ -193,7 +193,7 @@ impl fast_unstake::Config for Runtime { type Block = frame_system::mocking::MockBlock; type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; frame_support::construct_runtime!( - pub enum Runtime where + pub struct Runtime where Block = Block, NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic diff --git a/frame/im-online/src/mock.rs b/frame/im-online/src/mock.rs index bcb13fa1be837..2398d663959fd 100644 --- a/frame/im-online/src/mock.rs +++ b/frame/im-online/src/mock.rs @@ -43,7 +43,7 @@ type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic type Block = frame_system::mocking::MockBlock; frame_support::construct_runtime!( - pub enum Runtime where + pub struct Runtime where Block = Block, NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic, diff --git a/frame/nomination-pools/benchmarking/src/mock.rs b/frame/nomination-pools/benchmarking/src/mock.rs index 06a66838594c7..792e6f5f72bf9 100644 --- a/frame/nomination-pools/benchmarking/src/mock.rs +++ b/frame/nomination-pools/benchmarking/src/mock.rs @@ -173,7 +173,7 @@ impl crate::Config for Runtime {} type Block = frame_system::mocking::MockBlock; type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; frame_support::construct_runtime!( - pub enum Runtime where + pub struct Runtime where Block = Block, NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic diff --git a/frame/nomination-pools/src/mock.rs b/frame/nomination-pools/src/mock.rs index 99d521df3241b..e8924c0b9c0fa 100644 --- a/frame/nomination-pools/src/mock.rs +++ b/frame/nomination-pools/src/mock.rs @@ -236,7 +236,7 @@ impl pools::Config for Runtime { type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; frame_support::construct_runtime!( - pub enum Runtime where + pub struct Runtime where Block = Block, NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic, diff --git a/frame/nomination-pools/test-staking/src/mock.rs b/frame/nomination-pools/test-staking/src/mock.rs index c67aec0134b07..763a1099f941a 100644 --- a/frame/nomination-pools/test-staking/src/mock.rs +++ b/frame/nomination-pools/test-staking/src/mock.rs @@ -186,7 +186,7 @@ type Block = frame_system::mocking::MockBlock; type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; frame_support::construct_runtime!( - pub enum Runtime where + pub struct Runtime where Block = Block, NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic diff --git a/frame/offences/src/mock.rs b/frame/offences/src/mock.rs index 63d2b0de34780..8fbd2797fe0df 100644 --- a/frame/offences/src/mock.rs +++ b/frame/offences/src/mock.rs @@ -70,7 +70,7 @@ type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic type Block = frame_system::mocking::MockBlock; frame_support::construct_runtime!( - pub enum Runtime where + pub struct Runtime where Block = Block, NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic, diff --git a/frame/support/test/compile_pass/src/lib.rs b/frame/support/test/compile_pass/src/lib.rs index b46f6c48a6d99..51129306d77cd 100644 --- a/frame/support/test/compile_pass/src/lib.rs +++ b/frame/support/test/compile_pass/src/lib.rs @@ -85,7 +85,7 @@ pub type Block = generic::Block; pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; construct_runtime!( - pub enum Runtime where + pub struct Runtime where Block = Block, NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic diff --git a/frame/support/test/tests/construct_runtime.rs b/frame/support/test/tests/construct_runtime.rs index 18e4af1ac3739..4cdd8010c54a0 100644 --- a/frame/support/test/tests/construct_runtime.rs +++ b/frame/support/test/tests/construct_runtime.rs @@ -254,7 +254,7 @@ impl system::Config for Runtime { } frame_support::construct_runtime!( - pub enum Runtime where + pub struct Runtime where Block = Block, NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic diff --git a/frame/support/test/tests/instance.rs b/frame/support/test/tests/instance.rs index 043959b67ee6e..2298b58291f12 100644 --- a/frame/support/test/tests/instance.rs +++ b/frame/support/test/tests/instance.rs @@ -287,7 +287,7 @@ impl system::Config for Runtime { } frame_support::construct_runtime!( - pub enum Runtime where + pub struct Runtime where Block = Block, NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic diff --git a/frame/support/test/tests/issue2219.rs b/frame/support/test/tests/issue2219.rs index 5d24d54165c1f..a1a6e04e47af7 100644 --- a/frame/support/test/tests/issue2219.rs +++ b/frame/support/test/tests/issue2219.rs @@ -172,7 +172,7 @@ impl system::Config for Runtime { impl module::Config for Runtime {} frame_support::construct_runtime!( - pub enum Runtime where + pub struct Runtime where Block = Block, NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic diff --git a/frame/support/test/tests/pallet.rs b/frame/support/test/tests/pallet.rs index c0376d5aa450f..f7191aeff3158 100644 --- a/frame/support/test/tests/pallet.rs +++ b/frame/support/test/tests/pallet.rs @@ -650,7 +650,7 @@ pub type Block = sp_runtime::generic::Block; pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic; frame_support::construct_runtime!( - pub enum Runtime where + pub struct Runtime where Block = Block, NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic diff --git a/frame/support/test/tests/pallet_compatibility.rs b/frame/support/test/tests/pallet_compatibility.rs index 300fb9a40cf4e..a594fa1de4fa5 100644 --- a/frame/support/test/tests/pallet_compatibility.rs +++ b/frame/support/test/tests/pallet_compatibility.rs @@ -267,7 +267,7 @@ pub type Block = sp_runtime::generic::Block; pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic; frame_support::construct_runtime!( - pub enum Runtime where + pub struct Runtime where Block = Block, NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic diff --git a/frame/support/test/tests/pallet_compatibility_instance.rs b/frame/support/test/tests/pallet_compatibility_instance.rs index 79370d911b943..7c89a4ccdd382 100644 --- a/frame/support/test/tests/pallet_compatibility_instance.rs +++ b/frame/support/test/tests/pallet_compatibility_instance.rs @@ -268,7 +268,7 @@ pub type Block = sp_runtime::generic::Block; pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic; frame_support::construct_runtime!( - pub enum Runtime where + pub struct Runtime where Block = Block, NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic diff --git a/frame/support/test/tests/pallet_instance.rs b/frame/support/test/tests/pallet_instance.rs index 7fec0aa9d0e07..1327c8f6e37b5 100644 --- a/frame/support/test/tests/pallet_instance.rs +++ b/frame/support/test/tests/pallet_instance.rs @@ -334,7 +334,7 @@ pub type Block = sp_runtime::generic::Block; pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic; frame_support::construct_runtime!( - pub enum Runtime where + pub struct Runtime where Block = Block, NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic diff --git a/frame/support/test/tests/pallet_with_name_trait_is_valid.rs b/frame/support/test/tests/pallet_with_name_trait_is_valid.rs index 0066420566fe8..bc7eb5dfe6e28 100644 --- a/frame/support/test/tests/pallet_with_name_trait_is_valid.rs +++ b/frame/support/test/tests/pallet_with_name_trait_is_valid.rs @@ -114,7 +114,7 @@ mod tests { >; frame_support::construct_runtime!( - pub enum Runtime where + pub struct Runtime where Block = TestBlock, NodeBlock = TestBlock, UncheckedExtrinsic = TestUncheckedExtrinsic diff --git a/frame/support/test/tests/storage_layers.rs b/frame/support/test/tests/storage_layers.rs index cff81c0bea2ed..c2ca516e7371d 100644 --- a/frame/support/test/tests/storage_layers.rs +++ b/frame/support/test/tests/storage_layers.rs @@ -114,7 +114,7 @@ impl pallet::Config for Runtime {} impl decl_pallet::Config for Runtime {} frame_support::construct_runtime!( - pub enum Runtime where + pub struct Runtime where Block = Block, NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic diff --git a/frame/system/benches/bench.rs b/frame/system/benches/bench.rs index f2acc319d3f5d..8a50a292cfa7e 100644 --- a/frame/system/benches/bench.rs +++ b/frame/system/benches/bench.rs @@ -48,7 +48,7 @@ type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic type Block = frame_system::mocking::MockBlock; frame_support::construct_runtime!( - pub enum Runtime where + pub struct Runtime where Block = Block, NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic, diff --git a/frame/transaction-payment/asset-tx-payment/src/mock.rs b/frame/transaction-payment/asset-tx-payment/src/mock.rs index ddb02f5a611ff..e755dc2f7a4ec 100644 --- a/frame/transaction-payment/asset-tx-payment/src/mock.rs +++ b/frame/transaction-payment/asset-tx-payment/src/mock.rs @@ -40,7 +40,7 @@ type Balance = u64; type AccountId = u64; frame_support::construct_runtime!( - pub enum Runtime where + pub struct Runtime where Block = Block, NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic, diff --git a/frame/transaction-payment/src/mock.rs b/frame/transaction-payment/src/mock.rs index e214458b3766e..f32dc7a3dbbf5 100644 --- a/frame/transaction-payment/src/mock.rs +++ b/frame/transaction-payment/src/mock.rs @@ -37,7 +37,7 @@ type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic type Block = frame_system::mocking::MockBlock; frame_support::construct_runtime!( - pub enum Runtime where + pub struct Runtime where Block = Block, NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic, From 277ce53f798de7500ba59ae5fd2788eb26e842ea Mon Sep 17 00:00:00 2001 From: a-moreira Date: Sat, 28 Jan 2023 17:14:19 -0300 Subject: [PATCH 3/8] fmt --- frame/fast-unstake/src/mock.rs | 5 +++-- frame/support/test/compile_pass/src/lib.rs | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/frame/fast-unstake/src/mock.rs b/frame/fast-unstake/src/mock.rs index e7f08d400f8c4..a829c741a49dc 100644 --- a/frame/fast-unstake/src/mock.rs +++ b/frame/fast-unstake/src/mock.rs @@ -193,10 +193,11 @@ impl fast_unstake::Config for Runtime { type Block = frame_system::mocking::MockBlock; type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; frame_support::construct_runtime!( - pub struct Runtime where + pub struct Runtime + where Block = Block, NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic + UncheckedExtrinsic = UncheckedExtrinsic, { System: frame_system, Timestamp: pallet_timestamp, diff --git a/frame/support/test/compile_pass/src/lib.rs b/frame/support/test/compile_pass/src/lib.rs index 51129306d77cd..1b86f6349cc23 100644 --- a/frame/support/test/compile_pass/src/lib.rs +++ b/frame/support/test/compile_pass/src/lib.rs @@ -85,10 +85,11 @@ pub type Block = generic::Block; pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; construct_runtime!( - pub struct Runtime where + pub struct Runtime + where Block = Block, NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic + UncheckedExtrinsic = UncheckedExtrinsic, { System: frame_system, } From 4f824a4bed8af21321eb0e78c7170cb62296da96 Mon Sep 17 00:00:00 2001 From: a-moreira Date: Mon, 20 Feb 2023 04:52:09 -0300 Subject: [PATCH 4/8] updating *.stderr files --- .../invalid_module_details.stderr | 2 +- .../construct_runtime_ui/missing_where_block.stderr | 6 +++--- .../no_std_genesis_config.stderr | 6 +++--- .../old_unsupported_pallet_decl.stderr | 8 ++++---- .../pallet_error_too_large.stderr | 2 +- .../construct_runtime_ui/undefined_call_part.stderr | 2 +- .../construct_runtime_ui/undefined_event_part.stderr | 4 ++-- .../undefined_genesis_config_part.stderr | 6 +++--- .../undefined_inherent_part.stderr | 12 ++++++------ .../undefined_origin_part.stderr | 6 +++--- .../undefined_validate_unsigned_part.stderr | 8 ++++---- 11 files changed, 31 insertions(+), 31 deletions(-) diff --git a/frame/support/test/tests/construct_runtime_ui/invalid_module_details.stderr b/frame/support/test/tests/construct_runtime_ui/invalid_module_details.stderr index 0a20cf4e39a88..55abf4da9ce88 100644 --- a/frame/support/test/tests/construct_runtime_ui/invalid_module_details.stderr +++ b/frame/support/test/tests/construct_runtime_ui/invalid_module_details.stderr @@ -2,4 +2,4 @@ error: Unexpected tokens, expected one of `::$ident` `::{`, `exclude_parts`, `us --> tests/construct_runtime_ui/invalid_module_details.rs:9:17 | 9 | system: System::(), - | ^ + | ^^ diff --git a/frame/support/test/tests/construct_runtime_ui/missing_where_block.stderr b/frame/support/test/tests/construct_runtime_ui/missing_where_block.stderr index c6baf8fc24d07..d2a66f95101f4 100644 --- a/frame/support/test/tests/construct_runtime_ui/missing_where_block.stderr +++ b/frame/support/test/tests/construct_runtime_ui/missing_where_block.stderr @@ -1,5 +1,5 @@ error: expected `where` - --> tests/construct_runtime_ui/missing_where_block.rs:4:19 + --> tests/construct_runtime_ui/missing_where_block.rs:4:21 | -4 | pub enum Runtime {} - | ^ +4 | pub struct Runtime {} + | ^ diff --git a/frame/support/test/tests/construct_runtime_ui/no_std_genesis_config.stderr b/frame/support/test/tests/construct_runtime_ui/no_std_genesis_config.stderr index d35565fb933ac..2cf451aa65135 100644 --- a/frame/support/test/tests/construct_runtime_ui/no_std_genesis_config.stderr +++ b/frame/support/test/tests/construct_runtime_ui/no_std_genesis_config.stderr @@ -2,7 +2,7 @@ error: `Pallet` does not have the std feature enabled, this will cause the `test --> tests/construct_runtime_ui/no_std_genesis_config.rs:40:1 | 40 | / construct_runtime! { -41 | | pub enum Runtime where +41 | | pub struct Runtime where 42 | | Block = Block, 43 | | NodeBlock = Block, ... | @@ -16,7 +16,7 @@ error[E0412]: cannot find type `GenesisConfig` in crate `test_pallet` --> tests/construct_runtime_ui/no_std_genesis_config.rs:40:1 | 40 | / construct_runtime! { -41 | | pub enum Runtime where +41 | | pub struct Runtime where 42 | | Block = Block, 43 | | NodeBlock = Block, ... | @@ -34,7 +34,7 @@ error[E0283]: type annotations needed --> tests/construct_runtime_ui/no_std_genesis_config.rs:40:1 | 40 | / construct_runtime! { -41 | | pub enum Runtime where +41 | | pub struct Runtime where 42 | | Block = Block, 43 | | NodeBlock = Block, ... | diff --git a/frame/support/test/tests/construct_runtime_ui/old_unsupported_pallet_decl.stderr b/frame/support/test/tests/construct_runtime_ui/old_unsupported_pallet_decl.stderr index f8ec07e00106f..6029e7e6f48bb 100644 --- a/frame/support/test/tests/construct_runtime_ui/old_unsupported_pallet_decl.stderr +++ b/frame/support/test/tests/construct_runtime_ui/old_unsupported_pallet_decl.stderr @@ -1,8 +1,8 @@ error[E0433]: failed to resolve: could not find `tt_default_parts` in `pallet_old` - --> $DIR/old_unsupported_pallet_decl.rs:15:1 + --> tests/construct_runtime_ui/old_unsupported_pallet_decl.rs:15:1 | 15 | / construct_runtime! { -16 | | pub enum Runtime where +16 | | pub struct Runtime where 17 | | UncheckedExtrinsic = UncheckedExtrinsic, 18 | | Block = Block, ... | @@ -13,7 +13,7 @@ error[E0433]: failed to resolve: could not find `tt_default_parts` in `pallet_ol = note: this error originates in the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info) error: cannot find macro `decl_storage` in this scope - --> $DIR/old_unsupported_pallet_decl.rs:6:2 + --> tests/construct_runtime_ui/old_unsupported_pallet_decl.rs:6:2 | 6 | decl_storage! { | ^^^^^^^^^^^^ @@ -22,7 +22,7 @@ error: cannot find macro `decl_storage` in this scope frame_support::decl_storage error: cannot find macro `decl_module` in this scope - --> $DIR/old_unsupported_pallet_decl.rs:10:2 + --> tests/construct_runtime_ui/old_unsupported_pallet_decl.rs:10:2 | 10 | decl_module! { | ^^^^^^^^^^^ diff --git a/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.stderr b/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.stderr index 99a543eef7a8a..b9cec02a2b092 100644 --- a/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.stderr +++ b/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.stderr @@ -2,7 +2,7 @@ error[E0080]: evaluation of constant value failed --> tests/construct_runtime_ui/pallet_error_too_large.rs:74:1 | 74 | / construct_runtime! { -75 | | pub enum Runtime where +75 | | pub struct Runtime where 76 | | Block = Block, 77 | | NodeBlock = Block, ... | diff --git a/frame/support/test/tests/construct_runtime_ui/undefined_call_part.stderr b/frame/support/test/tests/construct_runtime_ui/undefined_call_part.stderr index 6baf01e866f64..c2092edea05b5 100644 --- a/frame/support/test/tests/construct_runtime_ui/undefined_call_part.stderr +++ b/frame/support/test/tests/construct_runtime_ui/undefined_call_part.stderr @@ -5,7 +5,7 @@ error: `Pallet` does not have #[pallet::call] defined, perhaps you should remove | ^^^^^^^^^^^^^^^^^^^^^^^^ ... 49 | / construct_runtime! { -50 | | pub enum Runtime where +50 | | pub struct Runtime where 51 | | Block = Block, 52 | | NodeBlock = Block, ... | diff --git a/frame/support/test/tests/construct_runtime_ui/undefined_event_part.stderr b/frame/support/test/tests/construct_runtime_ui/undefined_event_part.stderr index ff8ecf3041bf6..1ca64f381b005 100644 --- a/frame/support/test/tests/construct_runtime_ui/undefined_event_part.stderr +++ b/frame/support/test/tests/construct_runtime_ui/undefined_event_part.stderr @@ -5,7 +5,7 @@ error: `Pallet` does not have #[pallet::event] defined, perhaps you should remov | ^^^^^^^^^^^^^^^^^^^^^^^^ ... 49 | / construct_runtime! { -50 | | pub enum Runtime where +50 | | pub struct Runtime where 51 | | Block = Block, 52 | | NodeBlock = Block, ... | @@ -19,7 +19,7 @@ error[E0412]: cannot find type `Event` in module `pallet` --> tests/construct_runtime_ui/undefined_event_part.rs:49:1 | 49 | / construct_runtime! { -50 | | pub enum Runtime where +50 | | pub struct Runtime where 51 | | Block = Block, 52 | | NodeBlock = Block, ... | diff --git a/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.stderr b/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.stderr index 046369e1112b0..72099c1b94c0d 100644 --- a/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.stderr +++ b/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.stderr @@ -5,7 +5,7 @@ error: `Pallet` does not have #[pallet::genesis_config] defined, perhaps you sho | ^^^^^^^^^^^^^^^^^^^^^^^^ ... 49 | / construct_runtime! { -50 | | pub enum Runtime where +50 | | pub struct Runtime where 51 | | Block = Block, 52 | | NodeBlock = Block, ... | @@ -19,7 +19,7 @@ error[E0412]: cannot find type `GenesisConfig` in module `pallet` --> tests/construct_runtime_ui/undefined_genesis_config_part.rs:49:1 | 49 | / construct_runtime! { -50 | | pub enum Runtime where +50 | | pub struct Runtime where 51 | | Block = Block, 52 | | NodeBlock = Block, ... | @@ -37,7 +37,7 @@ error[E0283]: type annotations needed --> tests/construct_runtime_ui/undefined_genesis_config_part.rs:49:1 | 49 | / construct_runtime! { -50 | | pub enum Runtime where +50 | | pub struct Runtime where 51 | | Block = Block, 52 | | NodeBlock = Block, ... | diff --git a/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.stderr b/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.stderr index 74af0c264cd5e..dab6514261420 100644 --- a/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.stderr +++ b/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.stderr @@ -5,7 +5,7 @@ error: `Pallet` does not have #[pallet::inherent] defined, perhaps you should re | ^^^^^^^^^^^^^^^^^^^^^^^^ ... 49 | / construct_runtime! { -50 | | pub enum Runtime where +50 | | pub struct Runtime where 51 | | Block = Block, 52 | | NodeBlock = Block, ... | @@ -22,7 +22,7 @@ error[E0599]: no function or associated item named `create_inherent` found for s | -------------------- function or associated item `create_inherent` not found for this struct ... 49 | / construct_runtime! { -50 | | pub enum Runtime where +50 | | pub struct Runtime where 51 | | Block = Block, 52 | | NodeBlock = Block, ... | @@ -42,7 +42,7 @@ error[E0599]: no function or associated item named `is_inherent` found for struc | -------------------- function or associated item `is_inherent` not found for this struct ... 49 | / construct_runtime! { -50 | | pub enum Runtime where +50 | | pub struct Runtime where 51 | | Block = Block, 52 | | NodeBlock = Block, ... | @@ -62,7 +62,7 @@ error[E0599]: no function or associated item named `check_inherent` found for st | -------------------- function or associated item `check_inherent` not found for this struct ... 49 | / construct_runtime! { -50 | | pub enum Runtime where +50 | | pub struct Runtime where 51 | | Block = Block, 52 | | NodeBlock = Block, ... | @@ -82,7 +82,7 @@ error[E0599]: no associated item named `INHERENT_IDENTIFIER` found for struct `p | -------------------- associated item `INHERENT_IDENTIFIER` not found for this struct ... 49 | / construct_runtime! { -50 | | pub enum Runtime where +50 | | pub struct Runtime where 51 | | Block = Block, 52 | | NodeBlock = Block, ... | @@ -102,7 +102,7 @@ error[E0599]: no function or associated item named `is_inherent_required` found | -------------------- function or associated item `is_inherent_required` not found for this struct ... 49 | / construct_runtime! { -50 | | pub enum Runtime where +50 | | pub struct Runtime where 51 | | Block = Block, 52 | | NodeBlock = Block, ... | diff --git a/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.stderr b/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.stderr index 4907053b12877..dd1bdf76106e6 100644 --- a/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.stderr +++ b/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.stderr @@ -5,7 +5,7 @@ error: `Pallet` does not have #[pallet::origin] defined, perhaps you should remo | ^^^^^^^^^^^^^^^^^^^^^^^^ ... 49 | / construct_runtime! { -50 | | pub enum Runtime where +50 | | pub struct Runtime where 51 | | Block = Block, 52 | | NodeBlock = Block, ... | @@ -19,7 +19,7 @@ error[E0412]: cannot find type `Origin` in module `pallet` --> tests/construct_runtime_ui/undefined_origin_part.rs:49:1 | 49 | / construct_runtime! { -50 | | pub enum Runtime where +50 | | pub struct Runtime where 51 | | Block = Block, 52 | | NodeBlock = Block, ... | @@ -37,7 +37,7 @@ error[E0282]: type annotations needed --> tests/construct_runtime_ui/undefined_origin_part.rs:49:1 | 49 | / construct_runtime! { -50 | | pub enum Runtime where +50 | | pub struct Runtime where 51 | | Block = Block, 52 | | NodeBlock = Block, ... | diff --git a/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.stderr b/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.stderr index 6f0b13c58933e..14106ddd09c17 100644 --- a/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.stderr +++ b/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.stderr @@ -5,7 +5,7 @@ error: `Pallet` does not have #[pallet::validate_unsigned] defined, perhaps you | ^^^^^^^^^^^^^^^^^^^^^^^^ ... 49 | / construct_runtime! { -50 | | pub enum Runtime where +50 | | pub struct Runtime where 51 | | Block = Block, 52 | | NodeBlock = Block, ... | @@ -19,7 +19,7 @@ error[E0599]: no variant or associated item named `Pallet` found for enum `Runti --> tests/construct_runtime_ui/undefined_validate_unsigned_part.rs:56:3 | 49 | / construct_runtime! { -50 | | pub enum Runtime where +50 | | pub struct Runtime where 51 | | Block = Block, 52 | | NodeBlock = Block, ... | @@ -36,7 +36,7 @@ error[E0599]: no function or associated item named `pre_dispatch` found for stru | -------------------- function or associated item `pre_dispatch` not found for this struct ... 49 | / construct_runtime! { -50 | | pub enum Runtime where +50 | | pub struct Runtime where 51 | | Block = Block, 52 | | NodeBlock = Block, ... | @@ -57,7 +57,7 @@ error[E0599]: no function or associated item named `validate_unsigned` found for | -------------------- function or associated item `validate_unsigned` not found for this struct ... 49 | / construct_runtime! { -50 | | pub enum Runtime where +50 | | pub struct Runtime where 51 | | Block = Block, 52 | | NodeBlock = Block, ... | From 4242bf056facf7ff3001787d24114d41e3e4137e Mon Sep 17 00:00:00 2001 From: a-moreira Date: Mon, 20 Feb 2023 06:07:39 -0300 Subject: [PATCH 5/8] re-run trybuild after rust update --- .../tests/construct_runtime_ui/invalid_module_details.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/support/test/tests/construct_runtime_ui/invalid_module_details.stderr b/frame/support/test/tests/construct_runtime_ui/invalid_module_details.stderr index 55abf4da9ce88..0a20cf4e39a88 100644 --- a/frame/support/test/tests/construct_runtime_ui/invalid_module_details.stderr +++ b/frame/support/test/tests/construct_runtime_ui/invalid_module_details.stderr @@ -2,4 +2,4 @@ error: Unexpected tokens, expected one of `::$ident` `::{`, `exclude_parts`, `us --> tests/construct_runtime_ui/invalid_module_details.rs:9:17 | 9 | system: System::(), - | ^^ + | ^ From a3dc40450049fc4faafc97525a403afdb1b1a27d Mon Sep 17 00:00:00 2001 From: a-moreira Date: Wed, 22 Feb 2023 03:51:35 -0300 Subject: [PATCH 6/8] keep a test file for `pub enum Runtime` --- frame/support/test/tests/construct_runtime.rs | 2 +- .../support/test/tests/construct_runtime_2.rs | 794 ++++++++++++++++++ 2 files changed, 795 insertions(+), 1 deletion(-) create mode 100644 frame/support/test/tests/construct_runtime_2.rs diff --git a/frame/support/test/tests/construct_runtime.rs b/frame/support/test/tests/construct_runtime.rs index 4cdd8010c54a0..e8499a9177fb2 100644 --- a/frame/support/test/tests/construct_runtime.rs +++ b/frame/support/test/tests/construct_runtime.rs @@ -16,7 +16,7 @@ // limitations under the License. //! General tests for construct_runtime macro, test for: -//! * error declareed with decl_error works +//! * error declared with decl_error works //! * integrity test is generated #![recursion_limit = "128"] diff --git a/frame/support/test/tests/construct_runtime_2.rs b/frame/support/test/tests/construct_runtime_2.rs new file mode 100644 index 0000000000000..062b21ad14a06 --- /dev/null +++ b/frame/support/test/tests/construct_runtime_2.rs @@ -0,0 +1,794 @@ +// This file is part of Substrate. + +// Copyright (C) 2019-2022 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! General tests for construct_runtime macro, test for: +//! * error declared with decl_error works +//! * integrity test is generated + +#![recursion_limit = "128"] + +use codec::MaxEncodedLen; +use frame_support::{parameter_types, traits::PalletInfo as _}; +use scale_info::TypeInfo; +use sp_core::{sr25519, H256}; +use sp_runtime::{ + generic, + traits::{BlakeTwo256, Verify}, + DispatchError, ModuleError, +}; + +mod system; + +pub trait Currency {} + +parameter_types! { + pub static IntegrityTestExec: u32 = 0; +} + +mod module1 { + use super::*; + + pub trait Config: system::Config {} + + frame_support::decl_module! { + pub struct Module, I: Instance = DefaultInstance> for enum Call + where origin: ::RuntimeOrigin, system=system + { + #[weight = 0] + pub fn fail(_origin) -> frame_support::dispatch::DispatchResult { + Err(Error::::Something.into()) + } + } + } + + #[derive( + Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode, TypeInfo, MaxEncodedLen, + )] + pub struct Origin(pub core::marker::PhantomData<(T, I)>); + + frame_support::decl_event! { + pub enum Event where + ::AccountId + { + A(AccountId), + } + } + + frame_support::decl_error! { + pub enum Error for Module, I: Instance> { + Something + } + } + + frame_support::decl_storage! { + trait Store for Module, I: Instance=DefaultInstance> as Module {} + } +} + +mod module2 { + use super::*; + + pub trait Config: system::Config {} + + frame_support::decl_module! { + pub struct Module for enum Call + where origin: ::RuntimeOrigin, system=system + { + #[weight = 0] + pub fn fail(_origin) -> frame_support::dispatch::DispatchResult { + Err(Error::::Something.into()) + } + + fn integrity_test() { + IntegrityTestExec::mutate(|i| *i += 1); + } + } + } + + #[derive( + Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode, TypeInfo, MaxEncodedLen, + )] + pub struct Origin; + + frame_support::decl_event! { + pub enum Event { + A, + } + } + + frame_support::decl_error! { + pub enum Error for Module { + Something + } + } + + frame_support::decl_storage! { + trait Store for Module as Module {} + } +} + +mod nested { + use super::*; + + pub mod module3 { + use super::*; + + pub trait Config: system::Config {} + + frame_support::decl_module! { + pub struct Module for enum Call + where origin: ::RuntimeOrigin, system=system + { + #[weight = 0] + pub fn fail(_origin) -> frame_support::dispatch::DispatchResult { + Err(Error::::Something.into()) + } + + fn integrity_test() { + IntegrityTestExec::mutate(|i| *i += 1); + } + } + } + + #[derive( + Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode, TypeInfo, MaxEncodedLen, + )] + pub struct Origin; + + frame_support::decl_event! { + pub enum Event { + A, + } + } + + frame_support::decl_error! { + pub enum Error for Module { + Something + } + } + + frame_support::decl_storage! { + trait Store for Module as Module {} + add_extra_genesis { + build(|_config| {}) + } + } + } +} + +pub mod module3 { + use super::*; + + pub trait Config: system::Config {} + + frame_support::decl_module! { + pub struct Module for enum Call + where origin: ::RuntimeOrigin, system=system + { + #[weight = 0] + pub fn fail(_origin) -> frame_support::dispatch::DispatchResult { + Err(Error::::Something.into()) + } + #[weight = 0] + pub fn aux_1(_origin, #[compact] _data: u32) -> frame_support::dispatch::DispatchResult { + unreachable!() + } + #[weight = 0] + pub fn aux_2(_origin, _data: i32, #[compact] _data2: u32) -> frame_support::dispatch::DispatchResult { + unreachable!() + } + #[weight = 0] + fn aux_3(_origin, _data: i32, _data2: String) -> frame_support::dispatch::DispatchResult { + unreachable!() + } + #[weight = 3] + fn aux_4(_origin) -> frame_support::dispatch::DispatchResult { unreachable!() } + #[weight = (5, frame_support::dispatch::DispatchClass::Operational)] + fn operational(_origin) { unreachable!() } + } + } + + #[derive( + Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode, TypeInfo, MaxEncodedLen, + )] + pub struct Origin(pub core::marker::PhantomData); + + frame_support::decl_event! { + pub enum Event { + A, + } + } + + frame_support::decl_error! { + pub enum Error for Module { + Something + } + } + + frame_support::decl_storage! { + trait Store for Module as Module {} + add_extra_genesis { + build(|_config| {}) + } + } +} + +impl module1::Config for Runtime {} +impl module2::Config for Runtime {} +impl nested::module3::Config for Runtime {} +impl module3::Config for Runtime {} + +pub type Signature = sr25519::Signature; +pub type AccountId = ::Signer; +pub type BlockNumber = u64; +pub type Index = u64; + +fn test_pub() -> AccountId { + AccountId::from_raw([0; 32]) +} + +impl system::Config for Runtime { + type BaseCallFilter = frame_support::traits::Everything; + type Hash = H256; + type RuntimeOrigin = RuntimeOrigin; + type BlockNumber = BlockNumber; + type AccountId = AccountId; + type RuntimeEvent = RuntimeEvent; + type PalletInfo = PalletInfo; + type RuntimeCall = RuntimeCall; + type DbWeight = (); +} + +frame_support::construct_runtime!( + pub enum Runtime where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic + { + System: system::{Pallet, Call, Event, Origin} = 30, + Module1_1: module1::::{Pallet, Call, Storage, Event, Origin}, + Module2: module2::{Pallet, Call, Storage, Event, Origin}, + Module1_2: module1::::{Pallet, Call, Storage, Event, Origin}, + NestedModule3: nested::module3::{Pallet, Call, Config, Storage, Event, Origin}, + Module3: self::module3::{Pallet, Call, Config, Storage, Event, Origin}, + Module1_3: module1::::{Pallet, Storage} = 6, + Module1_4: module1::::{Pallet, Call} = 3, + Module1_5: module1::::{Pallet, Event}, + Module1_6: module1::::{Pallet, Call, Storage, Event, Origin} = 1, + Module1_7: module1::::{Pallet, Call, Storage, Event, Origin}, + Module1_8: module1::::{Pallet, Call, Storage, Event, Origin} = 12, + Module1_9: module1::::{Pallet, Call, Storage, Event, Origin}, + } +); + +pub type Header = generic::Header; +pub type Block = generic::Block; +pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; + +#[test] +fn check_modules_error_type() { + sp_io::TestExternalities::default().execute_with(|| { + assert_eq!( + Module1_1::fail(system::Origin::::Root.into()), + Err(DispatchError::Module(ModuleError { + index: 31, + error: [0; 4], + message: Some("Something") + })), + ); + assert_eq!( + Module2::fail(system::Origin::::Root.into()), + Err(DispatchError::Module(ModuleError { + index: 32, + error: [0; 4], + message: Some("Something") + })), + ); + assert_eq!( + Module1_2::fail(system::Origin::::Root.into()), + Err(DispatchError::Module(ModuleError { + index: 33, + error: [0; 4], + message: Some("Something") + })), + ); + assert_eq!( + NestedModule3::fail(system::Origin::::Root.into()), + Err(DispatchError::Module(ModuleError { + index: 34, + error: [0; 4], + message: Some("Something") + })), + ); + assert_eq!( + Module1_3::fail(system::Origin::::Root.into()), + Err(DispatchError::Module(ModuleError { + index: 6, + error: [0; 4], + message: Some("Something") + })), + ); + assert_eq!( + Module1_4::fail(system::Origin::::Root.into()), + Err(DispatchError::Module(ModuleError { + index: 3, + error: [0; 4], + message: Some("Something") + })), + ); + assert_eq!( + Module1_5::fail(system::Origin::::Root.into()), + Err(DispatchError::Module(ModuleError { + index: 4, + error: [0; 4], + message: Some("Something") + })), + ); + assert_eq!( + Module1_6::fail(system::Origin::::Root.into()), + Err(DispatchError::Module(ModuleError { + index: 1, + error: [0; 4], + message: Some("Something") + })), + ); + assert_eq!( + Module1_7::fail(system::Origin::::Root.into()), + Err(DispatchError::Module(ModuleError { + index: 2, + error: [0; 4], + message: Some("Something") + })), + ); + assert_eq!( + Module1_8::fail(system::Origin::::Root.into()), + Err(DispatchError::Module(ModuleError { + index: 12, + error: [0; 4], + message: Some("Something") + })), + ); + assert_eq!( + Module1_9::fail(system::Origin::::Root.into()), + Err(DispatchError::Module(ModuleError { + index: 13, + error: [0; 4], + message: Some("Something") + })), + ); + }) +} + +#[test] +fn integrity_test_works() { + __construct_runtime_integrity_test::runtime_integrity_tests(); + assert_eq!(IntegrityTestExec::get(), 2); +} + +#[test] +fn origin_codec() { + use codec::Encode; + + let origin = OriginCaller::system(system::RawOrigin::None); + assert_eq!(origin.encode()[0], 30); + + let origin = OriginCaller::Module1_1(module1::Origin(Default::default())); + assert_eq!(origin.encode()[0], 31); + + let origin = OriginCaller::Module2(module2::Origin); + assert_eq!(origin.encode()[0], 32); + + let origin = OriginCaller::Module1_2(module1::Origin(Default::default())); + assert_eq!(origin.encode()[0], 33); + + let origin = OriginCaller::NestedModule3(nested::module3::Origin); + assert_eq!(origin.encode()[0], 34); + + let origin = OriginCaller::Module3(module3::Origin(Default::default())); + assert_eq!(origin.encode()[0], 35); + + let origin = OriginCaller::Module1_6(module1::Origin(Default::default())); + assert_eq!(origin.encode()[0], 1); + + let origin = OriginCaller::Module1_7(module1::Origin(Default::default())); + assert_eq!(origin.encode()[0], 2); + + let origin = OriginCaller::Module1_8(module1::Origin(Default::default())); + assert_eq!(origin.encode()[0], 12); + + let origin = OriginCaller::Module1_9(module1::Origin(Default::default())); + assert_eq!(origin.encode()[0], 13); +} + +#[test] +fn event_codec() { + use codec::Encode; + + let event = system::Event::::ExtrinsicSuccess; + assert_eq!(RuntimeEvent::from(event).encode()[0], 30); + + let event = module1::Event::::A(test_pub()); + assert_eq!(RuntimeEvent::from(event).encode()[0], 31); + + let event = module2::Event::A; + assert_eq!(RuntimeEvent::from(event).encode()[0], 32); + + let event = module1::Event::::A(test_pub()); + assert_eq!(RuntimeEvent::from(event).encode()[0], 33); + + let event = nested::module3::Event::A; + assert_eq!(RuntimeEvent::from(event).encode()[0], 34); + + let event = module3::Event::A; + assert_eq!(RuntimeEvent::from(event).encode()[0], 35); + + let event = module1::Event::::A(test_pub()); + assert_eq!(RuntimeEvent::from(event).encode()[0], 4); + + let event = module1::Event::::A(test_pub()); + assert_eq!(RuntimeEvent::from(event).encode()[0], 1); + + let event = module1::Event::::A(test_pub()); + assert_eq!(RuntimeEvent::from(event).encode()[0], 2); + + let event = module1::Event::::A(test_pub()); + assert_eq!(RuntimeEvent::from(event).encode()[0], 12); + + let event = module1::Event::::A(test_pub()); + assert_eq!(RuntimeEvent::from(event).encode()[0], 13); +} + +#[test] +fn call_codec() { + use codec::Encode; + assert_eq!(RuntimeCall::System(system::Call::noop {}).encode()[0], 30); + assert_eq!(RuntimeCall::Module1_1(module1::Call::fail {}).encode()[0], 31); + assert_eq!(RuntimeCall::Module2(module2::Call::fail {}).encode()[0], 32); + assert_eq!(RuntimeCall::Module1_2(module1::Call::fail {}).encode()[0], 33); + assert_eq!(RuntimeCall::NestedModule3(nested::module3::Call::fail {}).encode()[0], 34); + assert_eq!(RuntimeCall::Module3(module3::Call::fail {}).encode()[0], 35); + assert_eq!(RuntimeCall::Module1_4(module1::Call::fail {}).encode()[0], 3); + assert_eq!(RuntimeCall::Module1_6(module1::Call::fail {}).encode()[0], 1); + assert_eq!(RuntimeCall::Module1_7(module1::Call::fail {}).encode()[0], 2); + assert_eq!(RuntimeCall::Module1_8(module1::Call::fail {}).encode()[0], 12); + assert_eq!(RuntimeCall::Module1_9(module1::Call::fail {}).encode()[0], 13); +} + +#[test] +fn call_compact_attr() { + use codec::Encode; + let call: module3::Call = module3::Call::aux_1 { _data: 1 }; + let encoded = call.encode(); + assert_eq!(2, encoded.len()); + assert_eq!(vec![1, 4], encoded); + + let call: module3::Call = module3::Call::aux_2 { _data: 1, _data2: 2 }; + let encoded = call.encode(); + assert_eq!(6, encoded.len()); + assert_eq!(vec![2, 1, 0, 0, 0, 8], encoded); +} + +#[test] +fn call_encode_is_correct_and_decode_works() { + use codec::{Decode, Encode}; + let call: module3::Call = module3::Call::fail {}; + let encoded = call.encode(); + assert_eq!(vec![0], encoded); + let decoded = module3::Call::::decode(&mut &encoded[..]).unwrap(); + assert_eq!(decoded, call); + + let call: module3::Call = module3::Call::aux_3 { _data: 32, _data2: "hello".into() }; + let encoded = call.encode(); + assert_eq!(vec![3, 32, 0, 0, 0, 20, 104, 101, 108, 108, 111], encoded); + let decoded = module3::Call::::decode(&mut &encoded[..]).unwrap(); + assert_eq!(decoded, call); +} + +#[test] +fn call_weight_should_attach_to_call_enum() { + use frame_support::{ + dispatch::{DispatchClass, DispatchInfo, GetDispatchInfo, Pays}, + weights::Weight, + }; + // operational. + assert_eq!( + module3::Call::::operational {}.get_dispatch_info(), + DispatchInfo { + weight: Weight::from_ref_time(5), + class: DispatchClass::Operational, + pays_fee: Pays::Yes + }, + ); + // custom basic + assert_eq!( + module3::Call::::aux_4 {}.get_dispatch_info(), + DispatchInfo { + weight: Weight::from_ref_time(3), + class: DispatchClass::Normal, + pays_fee: Pays::Yes + }, + ); +} + +#[test] +fn call_name() { + use frame_support::dispatch::GetCallName; + let name = module3::Call::::aux_4 {}.get_call_name(); + assert_eq!("aux_4", name); +} + +#[test] +fn call_metadata() { + use frame_support::dispatch::{CallMetadata, GetCallMetadata}; + let call = RuntimeCall::Module3(module3::Call::::aux_4 {}); + let metadata = call.get_call_metadata(); + let expected = CallMetadata { function_name: "aux_4".into(), pallet_name: "Module3".into() }; + assert_eq!(metadata, expected); +} + +#[test] +fn get_call_names() { + use frame_support::dispatch::GetCallName; + let call_names = module3::Call::::get_call_names(); + assert_eq!(["fail", "aux_1", "aux_2", "aux_3", "aux_4", "operational"], call_names); +} + +#[test] +fn get_module_names() { + use frame_support::dispatch::GetCallMetadata; + let module_names = RuntimeCall::get_module_names(); + assert_eq!( + [ + "System", + "Module1_1", + "Module2", + "Module1_2", + "NestedModule3", + "Module3", + "Module1_4", + "Module1_6", + "Module1_7", + "Module1_8", + "Module1_9", + ], + module_names + ); +} + +#[test] +fn call_subtype_conversion() { + use frame_support::{dispatch::CallableCallFor, traits::IsSubType}; + let call = RuntimeCall::Module3(module3::Call::::fail {}); + let subcall: Option<&CallableCallFor> = call.is_sub_type(); + let subcall_none: Option<&CallableCallFor> = call.is_sub_type(); + assert_eq!(Some(&module3::Call::::fail {}), subcall); + assert_eq!(None, subcall_none); + + let from = RuntimeCall::from(subcall.unwrap().clone()); + assert_eq!(from, call); +} + +#[test] +fn test_metadata() { + use frame_support::metadata::*; + use scale_info::meta_type; + + let pallets = vec![ + PalletMetadata { + name: "System", + storage: None, + calls: Some(meta_type::>().into()), + event: Some(meta_type::>().into()), + constants: vec![], + error: None, + index: 30, + }, + PalletMetadata { + name: "Module1_1", + storage: Some(PalletStorageMetadata { prefix: "Instance1Module", entries: vec![] }), + calls: Some(meta_type::>().into()), + event: Some(meta_type::>().into()), + constants: vec![], + error: None, + index: 31, + }, + PalletMetadata { + name: "Module2", + storage: Some(PalletStorageMetadata { prefix: "Module", entries: vec![] }), + calls: Some(meta_type::>().into()), + event: Some(meta_type::().into()), + constants: vec![], + error: None, + index: 32, + }, + PalletMetadata { + name: "Module1_2", + storage: Some(PalletStorageMetadata { prefix: "Instance2Module", entries: vec![] }), + calls: Some(meta_type::>().into()), + event: Some(meta_type::>().into()), + constants: vec![], + error: None, + index: 33, + }, + PalletMetadata { + name: "NestedModule3", + storage: Some(PalletStorageMetadata { prefix: "Module", entries: vec![] }), + calls: Some(meta_type::>().into()), + event: Some(meta_type::().into()), + constants: vec![], + error: None, + index: 34, + }, + PalletMetadata { + name: "Module3", + storage: Some(PalletStorageMetadata { prefix: "Module", entries: vec![] }), + calls: Some(meta_type::>().into()), + event: Some(meta_type::().into()), + constants: vec![], + error: None, + index: 35, + }, + PalletMetadata { + name: "Module1_3", + storage: Some(PalletStorageMetadata { prefix: "Instance3Module", entries: vec![] }), + calls: None, + event: None, + constants: vec![], + error: None, + index: 6, + }, + PalletMetadata { + name: "Module1_4", + storage: None, + calls: Some(meta_type::>().into()), + event: None, + constants: vec![], + error: None, + index: 3, + }, + PalletMetadata { + name: "Module1_5", + storage: None, + calls: None, + event: Some(meta_type::>().into()), + constants: vec![], + error: None, + index: 4, + }, + PalletMetadata { + name: "Module1_6", + storage: Some(PalletStorageMetadata { prefix: "Instance6Module", entries: vec![] }), + calls: Some(meta_type::>().into()), + event: Some(meta_type::>().into()), + constants: vec![], + error: None, + index: 1, + }, + PalletMetadata { + name: "Module1_7", + storage: Some(PalletStorageMetadata { prefix: "Instance7Module", entries: vec![] }), + calls: Some(meta_type::>().into()), + event: Some(PalletEventMetadata { + ty: meta_type::>(), + }), + constants: vec![], + error: None, + index: 2, + }, + PalletMetadata { + name: "Module1_8", + storage: Some(PalletStorageMetadata { prefix: "Instance8Module", entries: vec![] }), + calls: Some(meta_type::>().into()), + event: Some(meta_type::>().into()), + constants: vec![], + error: None, + index: 12, + }, + PalletMetadata { + name: "Module1_9", + storage: Some(PalletStorageMetadata { prefix: "Instance9Module", entries: vec![] }), + calls: Some(meta_type::>().into()), + event: Some(meta_type::>().into()), + constants: vec![], + error: None, + index: 13, + }, + ]; + + let extrinsic = ExtrinsicMetadata { + ty: meta_type::(), + version: 4, + signed_extensions: vec![SignedExtensionMetadata { + identifier: "UnitSignedExtension", + ty: meta_type::<()>(), + additional_signed: meta_type::<()>(), + }], + }; + + let expected_metadata: RuntimeMetadataPrefixed = + RuntimeMetadataLastVersion::new(pallets, extrinsic, meta_type::()).into(); + let actual_metadata = Runtime::metadata(); + pretty_assertions::assert_eq!(actual_metadata, expected_metadata); +} + +#[test] +fn pallet_in_runtime_is_correct() { + assert_eq!(PalletInfo::index::().unwrap(), 30); + assert_eq!(PalletInfo::name::().unwrap(), "System"); + assert_eq!(PalletInfo::module_name::().unwrap(), "system"); + assert!(PalletInfo::crate_version::().is_some()); + + assert_eq!(PalletInfo::index::().unwrap(), 31); + assert_eq!(PalletInfo::name::().unwrap(), "Module1_1"); + assert_eq!(PalletInfo::module_name::().unwrap(), "module1"); + assert!(PalletInfo::crate_version::().is_some()); + + assert_eq!(PalletInfo::index::().unwrap(), 32); + assert_eq!(PalletInfo::name::().unwrap(), "Module2"); + assert_eq!(PalletInfo::module_name::().unwrap(), "module2"); + assert!(PalletInfo::crate_version::().is_some()); + + assert_eq!(PalletInfo::index::().unwrap(), 33); + assert_eq!(PalletInfo::name::().unwrap(), "Module1_2"); + assert_eq!(PalletInfo::module_name::().unwrap(), "module1"); + assert!(PalletInfo::crate_version::().is_some()); + + assert_eq!(PalletInfo::index::().unwrap(), 34); + assert_eq!(PalletInfo::name::().unwrap(), "NestedModule3"); + assert_eq!(PalletInfo::module_name::().unwrap(), "nested::module3"); + assert!(PalletInfo::crate_version::().is_some()); + + assert_eq!(PalletInfo::index::().unwrap(), 35); + assert_eq!(PalletInfo::name::().unwrap(), "Module3"); + assert_eq!(PalletInfo::module_name::().unwrap(), "self::module3"); + assert!(PalletInfo::crate_version::().is_some()); + + assert_eq!(PalletInfo::index::().unwrap(), 6); + assert_eq!(PalletInfo::name::().unwrap(), "Module1_3"); + assert_eq!(PalletInfo::module_name::().unwrap(), "module1"); + assert!(PalletInfo::crate_version::().is_some()); + + assert_eq!(PalletInfo::index::().unwrap(), 3); + assert_eq!(PalletInfo::name::().unwrap(), "Module1_4"); + assert_eq!(PalletInfo::module_name::().unwrap(), "module1"); + assert!(PalletInfo::crate_version::().is_some()); + + assert_eq!(PalletInfo::index::().unwrap(), 4); + assert_eq!(PalletInfo::name::().unwrap(), "Module1_5"); + assert_eq!(PalletInfo::module_name::().unwrap(), "module1"); + assert!(PalletInfo::crate_version::().is_some()); + + assert_eq!(PalletInfo::index::().unwrap(), 1); + assert_eq!(PalletInfo::name::().unwrap(), "Module1_6"); + assert_eq!(PalletInfo::module_name::().unwrap(), "module1"); + assert!(PalletInfo::crate_version::().is_some()); + + assert_eq!(PalletInfo::index::().unwrap(), 2); + assert_eq!(PalletInfo::name::().unwrap(), "Module1_7"); + assert_eq!(PalletInfo::module_name::().unwrap(), "module1"); + assert!(PalletInfo::crate_version::().is_some()); + + assert_eq!(PalletInfo::index::().unwrap(), 12); + assert_eq!(PalletInfo::name::().unwrap(), "Module1_8"); + assert_eq!(PalletInfo::module_name::().unwrap(), "module1"); + assert!(PalletInfo::crate_version::().is_some()); + + assert_eq!(PalletInfo::index::().unwrap(), 13); + assert_eq!(PalletInfo::name::().unwrap(), "Module1_9"); + assert_eq!(PalletInfo::module_name::().unwrap(), "module1"); + assert!(PalletInfo::crate_version::().is_some()); +} From 2daecc0c983e81d827741edfe3d1e0b373a23ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 7 Mar 2023 10:16:07 +0100 Subject: [PATCH 7/8] Delete construct_runtime_2.rs --- .../support/test/tests/construct_runtime_2.rs | 794 ------------------ 1 file changed, 794 deletions(-) delete mode 100644 frame/support/test/tests/construct_runtime_2.rs diff --git a/frame/support/test/tests/construct_runtime_2.rs b/frame/support/test/tests/construct_runtime_2.rs deleted file mode 100644 index 062b21ad14a06..0000000000000 --- a/frame/support/test/tests/construct_runtime_2.rs +++ /dev/null @@ -1,794 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) 2019-2022 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! General tests for construct_runtime macro, test for: -//! * error declared with decl_error works -//! * integrity test is generated - -#![recursion_limit = "128"] - -use codec::MaxEncodedLen; -use frame_support::{parameter_types, traits::PalletInfo as _}; -use scale_info::TypeInfo; -use sp_core::{sr25519, H256}; -use sp_runtime::{ - generic, - traits::{BlakeTwo256, Verify}, - DispatchError, ModuleError, -}; - -mod system; - -pub trait Currency {} - -parameter_types! { - pub static IntegrityTestExec: u32 = 0; -} - -mod module1 { - use super::*; - - pub trait Config: system::Config {} - - frame_support::decl_module! { - pub struct Module, I: Instance = DefaultInstance> for enum Call - where origin: ::RuntimeOrigin, system=system - { - #[weight = 0] - pub fn fail(_origin) -> frame_support::dispatch::DispatchResult { - Err(Error::::Something.into()) - } - } - } - - #[derive( - Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode, TypeInfo, MaxEncodedLen, - )] - pub struct Origin(pub core::marker::PhantomData<(T, I)>); - - frame_support::decl_event! { - pub enum Event where - ::AccountId - { - A(AccountId), - } - } - - frame_support::decl_error! { - pub enum Error for Module, I: Instance> { - Something - } - } - - frame_support::decl_storage! { - trait Store for Module, I: Instance=DefaultInstance> as Module {} - } -} - -mod module2 { - use super::*; - - pub trait Config: system::Config {} - - frame_support::decl_module! { - pub struct Module for enum Call - where origin: ::RuntimeOrigin, system=system - { - #[weight = 0] - pub fn fail(_origin) -> frame_support::dispatch::DispatchResult { - Err(Error::::Something.into()) - } - - fn integrity_test() { - IntegrityTestExec::mutate(|i| *i += 1); - } - } - } - - #[derive( - Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode, TypeInfo, MaxEncodedLen, - )] - pub struct Origin; - - frame_support::decl_event! { - pub enum Event { - A, - } - } - - frame_support::decl_error! { - pub enum Error for Module { - Something - } - } - - frame_support::decl_storage! { - trait Store for Module as Module {} - } -} - -mod nested { - use super::*; - - pub mod module3 { - use super::*; - - pub trait Config: system::Config {} - - frame_support::decl_module! { - pub struct Module for enum Call - where origin: ::RuntimeOrigin, system=system - { - #[weight = 0] - pub fn fail(_origin) -> frame_support::dispatch::DispatchResult { - Err(Error::::Something.into()) - } - - fn integrity_test() { - IntegrityTestExec::mutate(|i| *i += 1); - } - } - } - - #[derive( - Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode, TypeInfo, MaxEncodedLen, - )] - pub struct Origin; - - frame_support::decl_event! { - pub enum Event { - A, - } - } - - frame_support::decl_error! { - pub enum Error for Module { - Something - } - } - - frame_support::decl_storage! { - trait Store for Module as Module {} - add_extra_genesis { - build(|_config| {}) - } - } - } -} - -pub mod module3 { - use super::*; - - pub trait Config: system::Config {} - - frame_support::decl_module! { - pub struct Module for enum Call - where origin: ::RuntimeOrigin, system=system - { - #[weight = 0] - pub fn fail(_origin) -> frame_support::dispatch::DispatchResult { - Err(Error::::Something.into()) - } - #[weight = 0] - pub fn aux_1(_origin, #[compact] _data: u32) -> frame_support::dispatch::DispatchResult { - unreachable!() - } - #[weight = 0] - pub fn aux_2(_origin, _data: i32, #[compact] _data2: u32) -> frame_support::dispatch::DispatchResult { - unreachable!() - } - #[weight = 0] - fn aux_3(_origin, _data: i32, _data2: String) -> frame_support::dispatch::DispatchResult { - unreachable!() - } - #[weight = 3] - fn aux_4(_origin) -> frame_support::dispatch::DispatchResult { unreachable!() } - #[weight = (5, frame_support::dispatch::DispatchClass::Operational)] - fn operational(_origin) { unreachable!() } - } - } - - #[derive( - Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode, TypeInfo, MaxEncodedLen, - )] - pub struct Origin(pub core::marker::PhantomData); - - frame_support::decl_event! { - pub enum Event { - A, - } - } - - frame_support::decl_error! { - pub enum Error for Module { - Something - } - } - - frame_support::decl_storage! { - trait Store for Module as Module {} - add_extra_genesis { - build(|_config| {}) - } - } -} - -impl module1::Config for Runtime {} -impl module2::Config for Runtime {} -impl nested::module3::Config for Runtime {} -impl module3::Config for Runtime {} - -pub type Signature = sr25519::Signature; -pub type AccountId = ::Signer; -pub type BlockNumber = u64; -pub type Index = u64; - -fn test_pub() -> AccountId { - AccountId::from_raw([0; 32]) -} - -impl system::Config for Runtime { - type BaseCallFilter = frame_support::traits::Everything; - type Hash = H256; - type RuntimeOrigin = RuntimeOrigin; - type BlockNumber = BlockNumber; - type AccountId = AccountId; - type RuntimeEvent = RuntimeEvent; - type PalletInfo = PalletInfo; - type RuntimeCall = RuntimeCall; - type DbWeight = (); -} - -frame_support::construct_runtime!( - pub enum Runtime where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic - { - System: system::{Pallet, Call, Event, Origin} = 30, - Module1_1: module1::::{Pallet, Call, Storage, Event, Origin}, - Module2: module2::{Pallet, Call, Storage, Event, Origin}, - Module1_2: module1::::{Pallet, Call, Storage, Event, Origin}, - NestedModule3: nested::module3::{Pallet, Call, Config, Storage, Event, Origin}, - Module3: self::module3::{Pallet, Call, Config, Storage, Event, Origin}, - Module1_3: module1::::{Pallet, Storage} = 6, - Module1_4: module1::::{Pallet, Call} = 3, - Module1_5: module1::::{Pallet, Event}, - Module1_6: module1::::{Pallet, Call, Storage, Event, Origin} = 1, - Module1_7: module1::::{Pallet, Call, Storage, Event, Origin}, - Module1_8: module1::::{Pallet, Call, Storage, Event, Origin} = 12, - Module1_9: module1::::{Pallet, Call, Storage, Event, Origin}, - } -); - -pub type Header = generic::Header; -pub type Block = generic::Block; -pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; - -#[test] -fn check_modules_error_type() { - sp_io::TestExternalities::default().execute_with(|| { - assert_eq!( - Module1_1::fail(system::Origin::::Root.into()), - Err(DispatchError::Module(ModuleError { - index: 31, - error: [0; 4], - message: Some("Something") - })), - ); - assert_eq!( - Module2::fail(system::Origin::::Root.into()), - Err(DispatchError::Module(ModuleError { - index: 32, - error: [0; 4], - message: Some("Something") - })), - ); - assert_eq!( - Module1_2::fail(system::Origin::::Root.into()), - Err(DispatchError::Module(ModuleError { - index: 33, - error: [0; 4], - message: Some("Something") - })), - ); - assert_eq!( - NestedModule3::fail(system::Origin::::Root.into()), - Err(DispatchError::Module(ModuleError { - index: 34, - error: [0; 4], - message: Some("Something") - })), - ); - assert_eq!( - Module1_3::fail(system::Origin::::Root.into()), - Err(DispatchError::Module(ModuleError { - index: 6, - error: [0; 4], - message: Some("Something") - })), - ); - assert_eq!( - Module1_4::fail(system::Origin::::Root.into()), - Err(DispatchError::Module(ModuleError { - index: 3, - error: [0; 4], - message: Some("Something") - })), - ); - assert_eq!( - Module1_5::fail(system::Origin::::Root.into()), - Err(DispatchError::Module(ModuleError { - index: 4, - error: [0; 4], - message: Some("Something") - })), - ); - assert_eq!( - Module1_6::fail(system::Origin::::Root.into()), - Err(DispatchError::Module(ModuleError { - index: 1, - error: [0; 4], - message: Some("Something") - })), - ); - assert_eq!( - Module1_7::fail(system::Origin::::Root.into()), - Err(DispatchError::Module(ModuleError { - index: 2, - error: [0; 4], - message: Some("Something") - })), - ); - assert_eq!( - Module1_8::fail(system::Origin::::Root.into()), - Err(DispatchError::Module(ModuleError { - index: 12, - error: [0; 4], - message: Some("Something") - })), - ); - assert_eq!( - Module1_9::fail(system::Origin::::Root.into()), - Err(DispatchError::Module(ModuleError { - index: 13, - error: [0; 4], - message: Some("Something") - })), - ); - }) -} - -#[test] -fn integrity_test_works() { - __construct_runtime_integrity_test::runtime_integrity_tests(); - assert_eq!(IntegrityTestExec::get(), 2); -} - -#[test] -fn origin_codec() { - use codec::Encode; - - let origin = OriginCaller::system(system::RawOrigin::None); - assert_eq!(origin.encode()[0], 30); - - let origin = OriginCaller::Module1_1(module1::Origin(Default::default())); - assert_eq!(origin.encode()[0], 31); - - let origin = OriginCaller::Module2(module2::Origin); - assert_eq!(origin.encode()[0], 32); - - let origin = OriginCaller::Module1_2(module1::Origin(Default::default())); - assert_eq!(origin.encode()[0], 33); - - let origin = OriginCaller::NestedModule3(nested::module3::Origin); - assert_eq!(origin.encode()[0], 34); - - let origin = OriginCaller::Module3(module3::Origin(Default::default())); - assert_eq!(origin.encode()[0], 35); - - let origin = OriginCaller::Module1_6(module1::Origin(Default::default())); - assert_eq!(origin.encode()[0], 1); - - let origin = OriginCaller::Module1_7(module1::Origin(Default::default())); - assert_eq!(origin.encode()[0], 2); - - let origin = OriginCaller::Module1_8(module1::Origin(Default::default())); - assert_eq!(origin.encode()[0], 12); - - let origin = OriginCaller::Module1_9(module1::Origin(Default::default())); - assert_eq!(origin.encode()[0], 13); -} - -#[test] -fn event_codec() { - use codec::Encode; - - let event = system::Event::::ExtrinsicSuccess; - assert_eq!(RuntimeEvent::from(event).encode()[0], 30); - - let event = module1::Event::::A(test_pub()); - assert_eq!(RuntimeEvent::from(event).encode()[0], 31); - - let event = module2::Event::A; - assert_eq!(RuntimeEvent::from(event).encode()[0], 32); - - let event = module1::Event::::A(test_pub()); - assert_eq!(RuntimeEvent::from(event).encode()[0], 33); - - let event = nested::module3::Event::A; - assert_eq!(RuntimeEvent::from(event).encode()[0], 34); - - let event = module3::Event::A; - assert_eq!(RuntimeEvent::from(event).encode()[0], 35); - - let event = module1::Event::::A(test_pub()); - assert_eq!(RuntimeEvent::from(event).encode()[0], 4); - - let event = module1::Event::::A(test_pub()); - assert_eq!(RuntimeEvent::from(event).encode()[0], 1); - - let event = module1::Event::::A(test_pub()); - assert_eq!(RuntimeEvent::from(event).encode()[0], 2); - - let event = module1::Event::::A(test_pub()); - assert_eq!(RuntimeEvent::from(event).encode()[0], 12); - - let event = module1::Event::::A(test_pub()); - assert_eq!(RuntimeEvent::from(event).encode()[0], 13); -} - -#[test] -fn call_codec() { - use codec::Encode; - assert_eq!(RuntimeCall::System(system::Call::noop {}).encode()[0], 30); - assert_eq!(RuntimeCall::Module1_1(module1::Call::fail {}).encode()[0], 31); - assert_eq!(RuntimeCall::Module2(module2::Call::fail {}).encode()[0], 32); - assert_eq!(RuntimeCall::Module1_2(module1::Call::fail {}).encode()[0], 33); - assert_eq!(RuntimeCall::NestedModule3(nested::module3::Call::fail {}).encode()[0], 34); - assert_eq!(RuntimeCall::Module3(module3::Call::fail {}).encode()[0], 35); - assert_eq!(RuntimeCall::Module1_4(module1::Call::fail {}).encode()[0], 3); - assert_eq!(RuntimeCall::Module1_6(module1::Call::fail {}).encode()[0], 1); - assert_eq!(RuntimeCall::Module1_7(module1::Call::fail {}).encode()[0], 2); - assert_eq!(RuntimeCall::Module1_8(module1::Call::fail {}).encode()[0], 12); - assert_eq!(RuntimeCall::Module1_9(module1::Call::fail {}).encode()[0], 13); -} - -#[test] -fn call_compact_attr() { - use codec::Encode; - let call: module3::Call = module3::Call::aux_1 { _data: 1 }; - let encoded = call.encode(); - assert_eq!(2, encoded.len()); - assert_eq!(vec![1, 4], encoded); - - let call: module3::Call = module3::Call::aux_2 { _data: 1, _data2: 2 }; - let encoded = call.encode(); - assert_eq!(6, encoded.len()); - assert_eq!(vec![2, 1, 0, 0, 0, 8], encoded); -} - -#[test] -fn call_encode_is_correct_and_decode_works() { - use codec::{Decode, Encode}; - let call: module3::Call = module3::Call::fail {}; - let encoded = call.encode(); - assert_eq!(vec![0], encoded); - let decoded = module3::Call::::decode(&mut &encoded[..]).unwrap(); - assert_eq!(decoded, call); - - let call: module3::Call = module3::Call::aux_3 { _data: 32, _data2: "hello".into() }; - let encoded = call.encode(); - assert_eq!(vec![3, 32, 0, 0, 0, 20, 104, 101, 108, 108, 111], encoded); - let decoded = module3::Call::::decode(&mut &encoded[..]).unwrap(); - assert_eq!(decoded, call); -} - -#[test] -fn call_weight_should_attach_to_call_enum() { - use frame_support::{ - dispatch::{DispatchClass, DispatchInfo, GetDispatchInfo, Pays}, - weights::Weight, - }; - // operational. - assert_eq!( - module3::Call::::operational {}.get_dispatch_info(), - DispatchInfo { - weight: Weight::from_ref_time(5), - class: DispatchClass::Operational, - pays_fee: Pays::Yes - }, - ); - // custom basic - assert_eq!( - module3::Call::::aux_4 {}.get_dispatch_info(), - DispatchInfo { - weight: Weight::from_ref_time(3), - class: DispatchClass::Normal, - pays_fee: Pays::Yes - }, - ); -} - -#[test] -fn call_name() { - use frame_support::dispatch::GetCallName; - let name = module3::Call::::aux_4 {}.get_call_name(); - assert_eq!("aux_4", name); -} - -#[test] -fn call_metadata() { - use frame_support::dispatch::{CallMetadata, GetCallMetadata}; - let call = RuntimeCall::Module3(module3::Call::::aux_4 {}); - let metadata = call.get_call_metadata(); - let expected = CallMetadata { function_name: "aux_4".into(), pallet_name: "Module3".into() }; - assert_eq!(metadata, expected); -} - -#[test] -fn get_call_names() { - use frame_support::dispatch::GetCallName; - let call_names = module3::Call::::get_call_names(); - assert_eq!(["fail", "aux_1", "aux_2", "aux_3", "aux_4", "operational"], call_names); -} - -#[test] -fn get_module_names() { - use frame_support::dispatch::GetCallMetadata; - let module_names = RuntimeCall::get_module_names(); - assert_eq!( - [ - "System", - "Module1_1", - "Module2", - "Module1_2", - "NestedModule3", - "Module3", - "Module1_4", - "Module1_6", - "Module1_7", - "Module1_8", - "Module1_9", - ], - module_names - ); -} - -#[test] -fn call_subtype_conversion() { - use frame_support::{dispatch::CallableCallFor, traits::IsSubType}; - let call = RuntimeCall::Module3(module3::Call::::fail {}); - let subcall: Option<&CallableCallFor> = call.is_sub_type(); - let subcall_none: Option<&CallableCallFor> = call.is_sub_type(); - assert_eq!(Some(&module3::Call::::fail {}), subcall); - assert_eq!(None, subcall_none); - - let from = RuntimeCall::from(subcall.unwrap().clone()); - assert_eq!(from, call); -} - -#[test] -fn test_metadata() { - use frame_support::metadata::*; - use scale_info::meta_type; - - let pallets = vec![ - PalletMetadata { - name: "System", - storage: None, - calls: Some(meta_type::>().into()), - event: Some(meta_type::>().into()), - constants: vec![], - error: None, - index: 30, - }, - PalletMetadata { - name: "Module1_1", - storage: Some(PalletStorageMetadata { prefix: "Instance1Module", entries: vec![] }), - calls: Some(meta_type::>().into()), - event: Some(meta_type::>().into()), - constants: vec![], - error: None, - index: 31, - }, - PalletMetadata { - name: "Module2", - storage: Some(PalletStorageMetadata { prefix: "Module", entries: vec![] }), - calls: Some(meta_type::>().into()), - event: Some(meta_type::().into()), - constants: vec![], - error: None, - index: 32, - }, - PalletMetadata { - name: "Module1_2", - storage: Some(PalletStorageMetadata { prefix: "Instance2Module", entries: vec![] }), - calls: Some(meta_type::>().into()), - event: Some(meta_type::>().into()), - constants: vec![], - error: None, - index: 33, - }, - PalletMetadata { - name: "NestedModule3", - storage: Some(PalletStorageMetadata { prefix: "Module", entries: vec![] }), - calls: Some(meta_type::>().into()), - event: Some(meta_type::().into()), - constants: vec![], - error: None, - index: 34, - }, - PalletMetadata { - name: "Module3", - storage: Some(PalletStorageMetadata { prefix: "Module", entries: vec![] }), - calls: Some(meta_type::>().into()), - event: Some(meta_type::().into()), - constants: vec![], - error: None, - index: 35, - }, - PalletMetadata { - name: "Module1_3", - storage: Some(PalletStorageMetadata { prefix: "Instance3Module", entries: vec![] }), - calls: None, - event: None, - constants: vec![], - error: None, - index: 6, - }, - PalletMetadata { - name: "Module1_4", - storage: None, - calls: Some(meta_type::>().into()), - event: None, - constants: vec![], - error: None, - index: 3, - }, - PalletMetadata { - name: "Module1_5", - storage: None, - calls: None, - event: Some(meta_type::>().into()), - constants: vec![], - error: None, - index: 4, - }, - PalletMetadata { - name: "Module1_6", - storage: Some(PalletStorageMetadata { prefix: "Instance6Module", entries: vec![] }), - calls: Some(meta_type::>().into()), - event: Some(meta_type::>().into()), - constants: vec![], - error: None, - index: 1, - }, - PalletMetadata { - name: "Module1_7", - storage: Some(PalletStorageMetadata { prefix: "Instance7Module", entries: vec![] }), - calls: Some(meta_type::>().into()), - event: Some(PalletEventMetadata { - ty: meta_type::>(), - }), - constants: vec![], - error: None, - index: 2, - }, - PalletMetadata { - name: "Module1_8", - storage: Some(PalletStorageMetadata { prefix: "Instance8Module", entries: vec![] }), - calls: Some(meta_type::>().into()), - event: Some(meta_type::>().into()), - constants: vec![], - error: None, - index: 12, - }, - PalletMetadata { - name: "Module1_9", - storage: Some(PalletStorageMetadata { prefix: "Instance9Module", entries: vec![] }), - calls: Some(meta_type::>().into()), - event: Some(meta_type::>().into()), - constants: vec![], - error: None, - index: 13, - }, - ]; - - let extrinsic = ExtrinsicMetadata { - ty: meta_type::(), - version: 4, - signed_extensions: vec![SignedExtensionMetadata { - identifier: "UnitSignedExtension", - ty: meta_type::<()>(), - additional_signed: meta_type::<()>(), - }], - }; - - let expected_metadata: RuntimeMetadataPrefixed = - RuntimeMetadataLastVersion::new(pallets, extrinsic, meta_type::()).into(); - let actual_metadata = Runtime::metadata(); - pretty_assertions::assert_eq!(actual_metadata, expected_metadata); -} - -#[test] -fn pallet_in_runtime_is_correct() { - assert_eq!(PalletInfo::index::().unwrap(), 30); - assert_eq!(PalletInfo::name::().unwrap(), "System"); - assert_eq!(PalletInfo::module_name::().unwrap(), "system"); - assert!(PalletInfo::crate_version::().is_some()); - - assert_eq!(PalletInfo::index::().unwrap(), 31); - assert_eq!(PalletInfo::name::().unwrap(), "Module1_1"); - assert_eq!(PalletInfo::module_name::().unwrap(), "module1"); - assert!(PalletInfo::crate_version::().is_some()); - - assert_eq!(PalletInfo::index::().unwrap(), 32); - assert_eq!(PalletInfo::name::().unwrap(), "Module2"); - assert_eq!(PalletInfo::module_name::().unwrap(), "module2"); - assert!(PalletInfo::crate_version::().is_some()); - - assert_eq!(PalletInfo::index::().unwrap(), 33); - assert_eq!(PalletInfo::name::().unwrap(), "Module1_2"); - assert_eq!(PalletInfo::module_name::().unwrap(), "module1"); - assert!(PalletInfo::crate_version::().is_some()); - - assert_eq!(PalletInfo::index::().unwrap(), 34); - assert_eq!(PalletInfo::name::().unwrap(), "NestedModule3"); - assert_eq!(PalletInfo::module_name::().unwrap(), "nested::module3"); - assert!(PalletInfo::crate_version::().is_some()); - - assert_eq!(PalletInfo::index::().unwrap(), 35); - assert_eq!(PalletInfo::name::().unwrap(), "Module3"); - assert_eq!(PalletInfo::module_name::().unwrap(), "self::module3"); - assert!(PalletInfo::crate_version::().is_some()); - - assert_eq!(PalletInfo::index::().unwrap(), 6); - assert_eq!(PalletInfo::name::().unwrap(), "Module1_3"); - assert_eq!(PalletInfo::module_name::().unwrap(), "module1"); - assert!(PalletInfo::crate_version::().is_some()); - - assert_eq!(PalletInfo::index::().unwrap(), 3); - assert_eq!(PalletInfo::name::().unwrap(), "Module1_4"); - assert_eq!(PalletInfo::module_name::().unwrap(), "module1"); - assert!(PalletInfo::crate_version::().is_some()); - - assert_eq!(PalletInfo::index::().unwrap(), 4); - assert_eq!(PalletInfo::name::().unwrap(), "Module1_5"); - assert_eq!(PalletInfo::module_name::().unwrap(), "module1"); - assert!(PalletInfo::crate_version::().is_some()); - - assert_eq!(PalletInfo::index::().unwrap(), 1); - assert_eq!(PalletInfo::name::().unwrap(), "Module1_6"); - assert_eq!(PalletInfo::module_name::().unwrap(), "module1"); - assert!(PalletInfo::crate_version::().is_some()); - - assert_eq!(PalletInfo::index::().unwrap(), 2); - assert_eq!(PalletInfo::name::().unwrap(), "Module1_7"); - assert_eq!(PalletInfo::module_name::().unwrap(), "module1"); - assert!(PalletInfo::crate_version::().is_some()); - - assert_eq!(PalletInfo::index::().unwrap(), 12); - assert_eq!(PalletInfo::name::().unwrap(), "Module1_8"); - assert_eq!(PalletInfo::module_name::().unwrap(), "module1"); - assert!(PalletInfo::crate_version::().is_some()); - - assert_eq!(PalletInfo::index::().unwrap(), 13); - assert_eq!(PalletInfo::name::().unwrap(), "Module1_9"); - assert_eq!(PalletInfo::module_name::().unwrap(), "module1"); - assert!(PalletInfo::crate_version::().is_some()); -} From 40e583973d180327f225b46bca3f927381bfd4a2 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Tue, 7 Mar 2023 09:51:53 +0000 Subject: [PATCH 8/8] ".git/.scripts/commands/fmt/fmt.sh" --- frame/transaction-payment/asset-tx-payment/src/mock.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frame/transaction-payment/asset-tx-payment/src/mock.rs b/frame/transaction-payment/asset-tx-payment/src/mock.rs index 12323778a7e89..cd5147c3acd13 100644 --- a/frame/transaction-payment/asset-tx-payment/src/mock.rs +++ b/frame/transaction-payment/asset-tx-payment/src/mock.rs @@ -40,7 +40,8 @@ type Balance = u64; type AccountId = u64; frame_support::construct_runtime!( - pub struct Runtime where + pub struct Runtime + where Block = Block, NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic,