Enrich metadata with type information (#8615)

* Cargo.lock after merge

* Restore scale-info feature

* Fully qualify TypeInfo derive

* Skip PendingSwap T

* Add missing skip_type_params attr

* metadata docs features

* Reduce pallet event attribute to struct

* Cargo.lock

* Update frame/balances/src/tests_composite.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Line widths check

* Cargo.lock

* Add scale-info/std

* Update frame/system/src/lib.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Use `skip_type_params` to remove `TypeInfo` requirements on checks

* Revert "Remove unused Call metadata stuff"

This reverts commit 41311f85

* Skip BalanceSwapAction type parameter

* Remove unused event metadata macro

* Update frame-metadata

* Update primitives/npos-elections/compact/src/codec.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Manual TypeInfo for Header

* Remove TypeInfo requirement for consts in BoundedVec etc.

* Another TypeInfo bound removed

* review: fix indentation

* TypeInfo impls for Identity types

* Add some todos to add custom TypeInfo impls

* Update frame/support/procedural/src/pallet/expand/pallet_struct.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Add some todos to add custom TypeInfo impls

* Add a test for manual Data TypeInfo impl

* Add custom TypeInfo impl for Vote

* Era custom TypeInfo crimes

* Revert finality-grandpa version to 0.14.z

* review: renamed module to pallet_constants_metadata

* New line at end of file

* Add missing scale-info/std

* Update frame/support/src/storage/types/mod.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Remove StorageEntryType::Map unused flag

* Add missing scale-info dependency after merge

* SignedExtension::AdditionalSigned metadata

* Update frame-metadata, use abbreviated docs and args fields

* Update frame/example/Cargo.toml

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>

* Add scale_info/std and remove unused scale-info dependency

* Remove scale-info dependency

* Remove treasury pallet::metadata

* Remove redundant Event test

* Add back scale-info as dev dependency

* fix error metadata when no error defined in decl_module

* Add Module3 to tests

* Fix metadata test

* Add docs feature to frame-support test

* WIP fixing pallet metadata test

* Remove redundant FunctionMetadata, FunctionArgumentMetadata as per https://github.com/paritytech/frame-metadata/pull/20

* Use main branch of frame-metadata

* Use patch of scale-info for latest changes

* Use latest patched scale-info

* Manual TypeInfo for DigestItem

* Manual TypeInfo for DigestItem

* Update scale-info

* Skip __Ignore variants for Error, depends on https://github.com/paritytech/scale-info/pull/117

* Named fields for FRAME v2 pallet Call variants

* Named fields for FRAME v1 pallet Call variants

* Add missing scale-info dependency

* WIP expand benchmark call variant

* fix benchmark with new function

create a new function for each variant of a pallet call.
This function is called by benchmarking macro in order not to break call
creation with unnamed argument

* fix tests

* more fix

* Fix staking tests

* Fix offchain workers calls

* Cherry pick rustfmt.toml from master

* cargo +nightly-2021-06-22 fmt --all

* Update to new call variant structs

* More call variant struct updates

* Remove unused import

* More call variant structs

* More call variant structs

* Even more call variant structs

* Mooar variant structs

* Evermore variant structs

* Call variant structs ad infinitum

* Fmt

* More call variants

* Last call variant

* Call variants all done?

* Fix SS58Prefix type

* Potential workaround for BitFlags<IdentityFields> TypeInfo

* Enable docs capturing for Call, Event, and Error types

* Fix IdentityFields TypeInfo

* Remove metadata-docs feature

* Add capture_docs = true for legacy Call, Event and Error types

* Fmt

* Fix metadata test type

* Update benchmarks with call struct variants

* Fmt

* More test fixes

* Fmt

* Fix benches

* Use latest capture_docs attr

* Latest scale_info

* Fmt

* review: change &Vec to &[]

* Remove pallet metadata attr

* review: remove commented out test code

* review: skip_type_params trailing comma suggestion

* Update to scale-info 0.10.0

* Update construct_runtime ui tests, different because of metadata TypeInfo impls

* Add some TypeInfo derives for UI tests

* Update storage ensure span ui stderrs

* Update call argument bound ui tests

Possibly changed because change from tuple to struct variants?

* Add scale-info dev dependency

* Update to latest finality-grandpa release

* review: missing newline

* review: missing scale-info/std

* review: remove duplicate scale-info/std

* review: remove fully qualified TypeInfo

* review: add missing scale-info/std

* review: remove unnecessary imports.

* Fmt

* Use crates.io RC version of frame-metadata

* Remove scale-info/std because it is a dev dependency

* Add missing scale_info dev-dependency for test

* Delete empty metadata folder

* Fix sp_std import

* review: improve manual UncheckedExtrinsic TypeInfo impl

* review: use full scale-info for dev-dependency

* Remove DefaultByteGetter impl

* review: derive TypeInfo for generic header

* Fmt

* Update primitives/runtime/src/generic/unchecked_extrinsic.rs

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>

* Update primitives/runtime/src/generic/unchecked_extrinsic.rs

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>

* Update bin/node/executor/Cargo.toml

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update frame/identity/src/types.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update frame/support/src/dispatch.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Remove redundant derive

* Simplify scale-info dependency

* Strip underscore prefix from call variant struct names

* Another underscore field

* More underscore fields

* Another underscore field

* Update to frame-metadata 14.0.0-rc.2 with combined StorageEntryType::Map

* Fmt

* Revert weights formatting

* Fix up some tests

* Fix up some tests for StorageEntryTypeMetadata

* scale-info dev dependency

* Fix test error

* Add missing TypeInfo derives

* Add back missing scale-info dependency

* Add back missing scale-info dependency

* Fix npos compact impls

* Cargo.lock

* Fmt

* Fix errors

* Fmt

* Fix renamed raw_solution field

* Fix error

* Fmt

* Fix some benchmarks

* Fmt

* Stray R

* Fix

* Add missing TypeInfos

* ui test fix

* Fix line widths

* Revert "ui test fix"

This reverts commit 2d15ec058a216e3f92d713f1174603a2bb1eac65.

* Upgrade to scale-info 0.11.0

* Revert "Upgrade to scale-info 0.11.0"

This reverts commit 047bb179085a0059c36cd20ab405f55cf0867e28.

* Add Runtime type

* Update to scale-info 0.12

* Update to scale-info 1.0

* Update frame-metadata to version 14.0.0

* Patch finality-grandpa until release available

* Fix metadata tests

* Fix metadata tests

* Fmt

* Remove patched finality-grandpa

* Fix tests, use scale_info imports

* Fix pallet tests

* Add BlockNumber TypeInfo bound

* ui test fix

* Cargo.lock

* Remove pallet metadata

* Cargo.lock

* Add missing scale-info dependency

* Remove pallet event metadata

* Fix error

* Fix collective errors

* Semicolol

* Fmt

* Remove another metadata attribute

* Add new variant to custom digest TypeInfo

* Fmt

* Cargo.lock from master

* Remove comma lol

* Fix example call error

* Fix example call error properly

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Andrew Jones
2021-09-15 12:40:41 +01:00
committed by GitHub
parent ebe78a4c1b
commit 49b6dfd2e5
305 changed files with 4015 additions and 3947 deletions
+3 -3
View File
@@ -34,7 +34,7 @@ benchmarks! {
let c in 0 .. 1000;
let mut calls: Vec<<T as Config>::Call> = Vec::new();
for i in 0 .. c {
let call = frame_system::Call::remark(vec![]).into();
let call = frame_system::Call::remark { remark: vec![] }.into();
calls.push(call);
}
let caller = whitelisted_caller();
@@ -45,7 +45,7 @@ benchmarks! {
as_derivative {
let caller = account("caller", SEED, SEED);
let call = Box::new(frame_system::Call::remark(vec![]).into());
let call = Box::new(frame_system::Call::remark { remark: vec![] }.into());
// Whitelist caller account from further DB operations.
let caller_key = frame_system::Account::<T>::hashed_key_for(&caller);
frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into());
@@ -55,7 +55,7 @@ benchmarks! {
let c in 0 .. 1000;
let mut calls: Vec<<T as Config>::Call> = Vec::new();
for i in 0 .. c {
let call = frame_system::Call::remark(vec![]).into();
let call = frame_system::Call::remark { remark: vec![] }.into();
calls.push(call);
}
let caller = whitelisted_caller();
+1 -1
View File
@@ -304,7 +304,7 @@ pub mod pallet {
// Don't allow users to nest `batch_all` calls.
filtered_origin.add_filter(move |c: &<T as frame_system::Config>::Call| {
let c = <T as Config>::Call::from_ref(c);
!matches!(c.is_sub_type(), Some(Call::batch_all(_)))
!matches!(c.is_sub_type(), Some(Call::batch_all { .. }))
});
call.dispatch(filtered_origin)
};
+73 -83
View File
@@ -155,10 +155,10 @@ impl Contains<Call> for TestBaseCallFilter {
fn contains(c: &Call) -> bool {
match *c {
// Transfer works. Use `transfer_keep_alive` for a call that doesn't pass the filter.
Call::Balances(pallet_balances::Call::transfer(..)) => true,
Call::Balances(pallet_balances::Call::transfer { .. }) => true,
Call::Utility(_) => true,
// For benchmarking, this acts as a noop call
Call::System(frame_system::Call::remark(..)) => true,
Call::System(frame_system::Call::remark { .. }) => true,
// For tests
Call::Example(_) => true,
_ => false,
@@ -189,24 +189,24 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
ext
}
fn call_transfer(dest: u64, value: u64) -> Call {
Call::Balances(BalancesCall::transfer { dest, value })
}
fn call_foobar(err: bool, start_weight: u64, end_weight: Option<u64>) -> Call {
Call::Example(ExampleCall::foobar { err, start_weight, end_weight })
}
#[test]
fn as_derivative_works() {
new_test_ext().execute_with(|| {
let sub_1_0 = Utility::derivative_account_id(1, 0);
assert_ok!(Balances::transfer(Origin::signed(1), sub_1_0, 5));
assert_err_ignore_postinfo!(
Utility::as_derivative(
Origin::signed(1),
1,
Box::new(Call::Balances(BalancesCall::transfer(6, 3))),
),
Utility::as_derivative(Origin::signed(1), 1, Box::new(call_transfer(6, 3)),),
BalancesError::<Test, _>::InsufficientBalance
);
assert_ok!(Utility::as_derivative(
Origin::signed(1),
0,
Box::new(Call::Balances(BalancesCall::transfer(2, 3))),
));
assert_ok!(Utility::as_derivative(Origin::signed(1), 0, Box::new(call_transfer(2, 3)),));
assert_eq!(Balances::free_balance(sub_1_0), 2);
assert_eq!(Balances::free_balance(2), 13);
});
@@ -220,16 +220,18 @@ fn as_derivative_handles_weight_refund() {
let diff = start_weight - end_weight;
// Full weight when ok
let inner_call = Call::Example(ExampleCall::foobar(false, start_weight, None));
let call = Call::Utility(UtilityCall::as_derivative(0, Box::new(inner_call)));
let inner_call = call_foobar(false, start_weight, None);
let call =
Call::Utility(UtilityCall::as_derivative { index: 0, call: Box::new(inner_call) });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
assert_eq!(extract_actual_weight(&result, &info), info.weight);
// Refund weight when ok
let inner_call = Call::Example(ExampleCall::foobar(false, start_weight, Some(end_weight)));
let call = Call::Utility(UtilityCall::as_derivative(0, Box::new(inner_call)));
let inner_call = call_foobar(false, start_weight, Some(end_weight));
let call =
Call::Utility(UtilityCall::as_derivative { index: 0, call: Box::new(inner_call) });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
@@ -237,8 +239,9 @@ fn as_derivative_handles_weight_refund() {
assert_eq!(extract_actual_weight(&result, &info), info.weight - diff);
// Full weight when err
let inner_call = Call::Example(ExampleCall::foobar(true, start_weight, None));
let call = Call::Utility(UtilityCall::as_derivative(0, Box::new(inner_call)));
let inner_call = call_foobar(true, start_weight, None);
let call =
Call::Utility(UtilityCall::as_derivative { index: 0, call: Box::new(inner_call) });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_noop!(
@@ -254,8 +257,9 @@ fn as_derivative_handles_weight_refund() {
);
// Refund weight when err
let inner_call = Call::Example(ExampleCall::foobar(true, start_weight, Some(end_weight)));
let call = Call::Utility(UtilityCall::as_derivative(0, Box::new(inner_call)));
let inner_call = call_foobar(true, start_weight, Some(end_weight));
let call =
Call::Utility(UtilityCall::as_derivative { index: 0, call: Box::new(inner_call) });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_noop!(
@@ -279,7 +283,10 @@ fn as_derivative_filters() {
Utility::as_derivative(
Origin::signed(1),
1,
Box::new(Call::Balances(pallet_balances::Call::transfer_keep_alive(2, 1))),
Box::new(Call::Balances(pallet_balances::Call::transfer_keep_alive {
dest: 2,
value: 1
})),
),
DispatchError::BadOrigin
);
@@ -290,15 +297,16 @@ fn as_derivative_filters() {
fn batch_with_root_works() {
new_test_ext().execute_with(|| {
let k = b"a".to_vec();
let call = Call::System(frame_system::Call::set_storage(vec![(k.clone(), k.clone())]));
let call =
Call::System(frame_system::Call::set_storage { items: vec![(k.clone(), k.clone())] });
assert!(!TestBaseCallFilter::contains(&call));
assert_eq!(Balances::free_balance(1), 10);
assert_eq!(Balances::free_balance(2), 10);
assert_ok!(Utility::batch(
Origin::root(),
vec![
Call::Balances(BalancesCall::force_transfer(1, 2, 5)),
Call::Balances(BalancesCall::force_transfer(1, 2, 5)),
Call::Balances(BalancesCall::force_transfer { source: 1, dest: 2, value: 5 }),
Call::Balances(BalancesCall::force_transfer { source: 1, dest: 2, value: 5 }),
call, // Check filters are correctly bypassed
]
));
@@ -315,10 +323,7 @@ fn batch_with_signed_works() {
assert_eq!(Balances::free_balance(2), 10);
assert_ok!(Utility::batch(
Origin::signed(1),
vec![
Call::Balances(BalancesCall::transfer(2, 5)),
Call::Balances(BalancesCall::transfer(2, 5))
]
vec![call_transfer(2, 5), call_transfer(2, 5)]
),);
assert_eq!(Balances::free_balance(1), 0);
assert_eq!(Balances::free_balance(2), 20);
@@ -330,7 +335,7 @@ fn batch_with_signed_filters() {
new_test_ext().execute_with(|| {
assert_ok!(Utility::batch(
Origin::signed(1),
vec![Call::Balances(pallet_balances::Call::transfer_keep_alive(2, 1))]
vec![Call::Balances(pallet_balances::Call::transfer_keep_alive { dest: 2, value: 1 })]
),);
System::assert_last_event(
utility::Event::BatchInterrupted(0, DispatchError::BadOrigin).into(),
@@ -345,11 +350,7 @@ fn batch_early_exit_works() {
assert_eq!(Balances::free_balance(2), 10);
assert_ok!(Utility::batch(
Origin::signed(1),
vec![
Call::Balances(BalancesCall::transfer(2, 5)),
Call::Balances(BalancesCall::transfer(2, 10)),
Call::Balances(BalancesCall::transfer(2, 5)),
]
vec![call_transfer(2, 5), call_transfer(2, 10), call_transfer(2, 5),]
),);
assert_eq!(Balances::free_balance(1), 5);
assert_eq!(Balances::free_balance(2), 15);
@@ -360,15 +361,13 @@ fn batch_early_exit_works() {
fn batch_weight_calculation_doesnt_overflow() {
use sp_runtime::Perbill;
new_test_ext().execute_with(|| {
let big_call = Call::System(SystemCall::fill_block(Perbill::from_percent(50)));
let big_call = Call::System(SystemCall::fill_block { ratio: Perbill::from_percent(50) });
assert_eq!(big_call.get_dispatch_info().weight, Weight::max_value() / 2);
// 3 * 50% saturates to 100%
let batch_call = Call::Utility(crate::Call::batch(vec![
big_call.clone(),
big_call.clone(),
big_call.clone(),
]));
let batch_call = Call::Utility(crate::Call::batch {
calls: vec![big_call.clone(), big_call.clone(), big_call.clone()],
});
assert_eq!(batch_call.get_dispatch_info().weight, Weight::max_value());
});
@@ -383,18 +382,18 @@ fn batch_handles_weight_refund() {
let batch_len: Weight = 4;
// Full weight when ok
let inner_call = Call::Example(ExampleCall::foobar(false, start_weight, None));
let inner_call = call_foobar(false, start_weight, None);
let batch_calls = vec![inner_call; batch_len as usize];
let call = Call::Utility(UtilityCall::batch(batch_calls));
let call = Call::Utility(UtilityCall::batch { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
assert_eq!(extract_actual_weight(&result, &info), info.weight);
// Refund weight when ok
let inner_call = Call::Example(ExampleCall::foobar(false, start_weight, Some(end_weight)));
let inner_call = call_foobar(false, start_weight, Some(end_weight));
let batch_calls = vec![inner_call; batch_len as usize];
let call = Call::Utility(UtilityCall::batch(batch_calls));
let call = Call::Utility(UtilityCall::batch { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
@@ -402,10 +401,10 @@ fn batch_handles_weight_refund() {
assert_eq!(extract_actual_weight(&result, &info), info.weight - diff * batch_len);
// Full weight when err
let good_call = Call::Example(ExampleCall::foobar(false, start_weight, None));
let bad_call = Call::Example(ExampleCall::foobar(true, start_weight, None));
let good_call = call_foobar(false, start_weight, None);
let bad_call = call_foobar(true, start_weight, None);
let batch_calls = vec![good_call, bad_call];
let call = Call::Utility(UtilityCall::batch(batch_calls));
let call = Call::Utility(UtilityCall::batch { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
@@ -416,11 +415,11 @@ fn batch_handles_weight_refund() {
assert_eq!(extract_actual_weight(&result, &info), info.weight);
// Refund weight when err
let good_call = Call::Example(ExampleCall::foobar(false, start_weight, Some(end_weight)));
let bad_call = Call::Example(ExampleCall::foobar(true, start_weight, Some(end_weight)));
let good_call = call_foobar(false, start_weight, Some(end_weight));
let bad_call = call_foobar(true, start_weight, Some(end_weight));
let batch_calls = vec![good_call, bad_call];
let batch_len = batch_calls.len() as Weight;
let call = Call::Utility(UtilityCall::batch(batch_calls));
let call = Call::Utility(UtilityCall::batch { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
@@ -430,10 +429,10 @@ fn batch_handles_weight_refund() {
assert_eq!(extract_actual_weight(&result, &info), info.weight - diff * batch_len);
// Partial batch completion
let good_call = Call::Example(ExampleCall::foobar(false, start_weight, Some(end_weight)));
let bad_call = Call::Example(ExampleCall::foobar(true, start_weight, Some(end_weight)));
let good_call = call_foobar(false, start_weight, Some(end_weight));
let bad_call = call_foobar(true, start_weight, Some(end_weight));
let batch_calls = vec![good_call, bad_call.clone(), bad_call];
let call = Call::Utility(UtilityCall::batch(batch_calls));
let call = Call::Utility(UtilityCall::batch { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
@@ -455,10 +454,7 @@ fn batch_all_works() {
assert_eq!(Balances::free_balance(2), 10);
assert_ok!(Utility::batch_all(
Origin::signed(1),
vec![
Call::Balances(BalancesCall::transfer(2, 5)),
Call::Balances(BalancesCall::transfer(2, 5))
]
vec![call_transfer(2, 5), call_transfer(2, 5)]
),);
assert_eq!(Balances::free_balance(1), 0);
assert_eq!(Balances::free_balance(2), 20);
@@ -468,7 +464,7 @@ fn batch_all_works() {
#[test]
fn batch_all_revert() {
new_test_ext().execute_with(|| {
let call = Call::Balances(BalancesCall::transfer(2, 5));
let call = call_transfer(2, 5);
let info = call.get_dispatch_info();
assert_eq!(Balances::free_balance(1), 10);
@@ -476,11 +472,7 @@ fn batch_all_revert() {
assert_noop!(
Utility::batch_all(
Origin::signed(1),
vec![
Call::Balances(BalancesCall::transfer(2, 5)),
Call::Balances(BalancesCall::transfer(2, 10)),
Call::Balances(BalancesCall::transfer(2, 5)),
]
vec![call_transfer(2, 5), call_transfer(2, 10), call_transfer(2, 5),]
),
DispatchErrorWithPostInfo {
post_info: PostDispatchInfo {
@@ -506,18 +498,18 @@ fn batch_all_handles_weight_refund() {
let batch_len: Weight = 4;
// Full weight when ok
let inner_call = Call::Example(ExampleCall::foobar(false, start_weight, None));
let inner_call = call_foobar(false, start_weight, None);
let batch_calls = vec![inner_call; batch_len as usize];
let call = Call::Utility(UtilityCall::batch_all(batch_calls));
let call = Call::Utility(UtilityCall::batch_all { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
assert_eq!(extract_actual_weight(&result, &info), info.weight);
// Refund weight when ok
let inner_call = Call::Example(ExampleCall::foobar(false, start_weight, Some(end_weight)));
let inner_call = call_foobar(false, start_weight, Some(end_weight));
let batch_calls = vec![inner_call; batch_len as usize];
let call = Call::Utility(UtilityCall::batch_all(batch_calls));
let call = Call::Utility(UtilityCall::batch_all { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
@@ -525,10 +517,10 @@ fn batch_all_handles_weight_refund() {
assert_eq!(extract_actual_weight(&result, &info), info.weight - diff * batch_len);
// Full weight when err
let good_call = Call::Example(ExampleCall::foobar(false, start_weight, None));
let bad_call = Call::Example(ExampleCall::foobar(true, start_weight, None));
let good_call = call_foobar(false, start_weight, None);
let bad_call = call_foobar(true, start_weight, None);
let batch_calls = vec![good_call, bad_call];
let call = Call::Utility(UtilityCall::batch_all(batch_calls));
let call = Call::Utility(UtilityCall::batch_all { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_err_ignore_postinfo!(result, "The cake is a lie.");
@@ -536,21 +528,21 @@ fn batch_all_handles_weight_refund() {
assert_eq!(extract_actual_weight(&result, &info), info.weight);
// Refund weight when err
let good_call = Call::Example(ExampleCall::foobar(false, start_weight, Some(end_weight)));
let bad_call = Call::Example(ExampleCall::foobar(true, start_weight, Some(end_weight)));
let good_call = call_foobar(false, start_weight, Some(end_weight));
let bad_call = call_foobar(true, start_weight, Some(end_weight));
let batch_calls = vec![good_call, bad_call];
let batch_len = batch_calls.len() as Weight;
let call = Call::Utility(UtilityCall::batch_all(batch_calls));
let call = Call::Utility(UtilityCall::batch_all { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_err_ignore_postinfo!(result, "The cake is a lie.");
assert_eq!(extract_actual_weight(&result, &info), info.weight - diff * batch_len);
// Partial batch completion
let good_call = Call::Example(ExampleCall::foobar(false, start_weight, Some(end_weight)));
let bad_call = Call::Example(ExampleCall::foobar(true, start_weight, Some(end_weight)));
let good_call = call_foobar(false, start_weight, Some(end_weight));
let bad_call = call_foobar(true, start_weight, Some(end_weight));
let batch_calls = vec![good_call, bad_call.clone(), bad_call];
let call = Call::Utility(UtilityCall::batch_all(batch_calls));
let call = Call::Utility(UtilityCall::batch_all { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_err_ignore_postinfo!(result, "The cake is a lie.");
@@ -565,11 +557,9 @@ fn batch_all_handles_weight_refund() {
#[test]
fn batch_all_does_not_nest() {
new_test_ext().execute_with(|| {
let batch_all = Call::Utility(UtilityCall::batch_all(vec![
Call::Balances(BalancesCall::transfer(2, 1)),
Call::Balances(BalancesCall::transfer(2, 1)),
Call::Balances(BalancesCall::transfer(2, 1)),
]));
let batch_all = Call::Utility(UtilityCall::batch_all {
calls: vec![call_transfer(2, 1), call_transfer(2, 1), call_transfer(2, 1)],
});
let info = batch_all.get_dispatch_info();
@@ -590,7 +580,7 @@ fn batch_all_does_not_nest() {
// And for those who want to get a little fancy, we check that the filter persists across
// other kinds of dispatch wrapping functions... in this case
// `batch_all(batch(batch_all(..)))`
let batch_nested = Call::Utility(UtilityCall::batch(vec![batch_all]));
let batch_nested = Call::Utility(UtilityCall::batch { calls: vec![batch_all] });
// Batch will end with `Ok`, but does not actually execute as we can see from the event
// and balances.
assert_ok!(Utility::batch_all(Origin::signed(1), vec![batch_nested]));
@@ -605,7 +595,7 @@ fn batch_all_does_not_nest() {
#[test]
fn batch_limit() {
new_test_ext().execute_with(|| {
let calls = vec![Call::System(SystemCall::remark(vec![])); 40_000];
let calls = vec![Call::System(SystemCall::remark { remark: vec![] }); 40_000];
assert_noop!(Utility::batch(Origin::signed(1), calls.clone()), Error::<Test>::TooManyCalls);
assert_noop!(Utility::batch_all(Origin::signed(1), calls), Error::<Test>::TooManyCalls);
});