BREAKING: Rename Call & Event (#11981)

* rename Event to RuntimeEvent

* rename Call

* rename in runtimes

* small fix

* rename Event

* small fix & rename RuntimeCall back to Call for now

* small fixes

* more renaming

* a bit more renaming

* fmt

* small fix

* commit

* prep for renaming associated types

* fix

* rename associated Event type

* rename to RuntimeEvent

* commit

* merge conflict fixes & fmt

* additional renaming

* fix.

* fix decl_event

* rename in tests

* remove warnings

* remove accidental rename

* .

* commit

* update .stderr

* fix in test

* update .stderr

* TRYBUILD=overwrite

* docs

* fmt

* small change in docs

* rename PalletEvent to Event

* rename Call to RuntimeCall

* renamed at wrong places :P

* rename Call

* rename

* rename associated type

* fix

* fix & fmt

* commit

* frame-support-test

* passing tests

* update docs

* rustdoc fix

* update .stderr

* wrong code in docs

* merge fix

* fix in error message

* update .stderr

* docs & error message

* .

* merge fix

* merge fix

* fmt

* fmt

* merge fix

* more fixing

* fmt

* remove unused

* fmt

* fix

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Sergej Sakac
2022-09-13 00:03:31 +02:00
committed by GitHub
parent 472b5746e5
commit 6e8795afe6
228 changed files with 1791 additions and 1672 deletions
+66 -45
View File
@@ -110,12 +110,12 @@ impl frame_system::Config for Test {
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Call = Call;
type RuntimeCall = RuntimeCall;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = Event;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
type PalletInfo = PalletInfo;
@@ -134,7 +134,7 @@ impl pallet_balances::Config for Test {
type ReserveIdentifier = [u8; 8];
type Balance = u64;
type DustRemoval = ();
type Event = Event;
type RuntimeEvent = RuntimeEvent;
type ExistentialDeposit = ConstU64<1>;
type AccountStore = System;
type WeightInfo = ();
@@ -148,23 +148,23 @@ parameter_types! {
impl example::Config for Test {}
pub struct TestBaseCallFilter;
impl Contains<Call> for TestBaseCallFilter {
fn contains(c: &Call) -> bool {
impl Contains<RuntimeCall> for TestBaseCallFilter {
fn contains(c: &RuntimeCall) -> 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::Utility(_) => true,
RuntimeCall::Balances(pallet_balances::Call::transfer { .. }) => true,
RuntimeCall::Utility(_) => true,
// For benchmarking, this acts as a noop call
Call::System(frame_system::Call::remark { .. }) => true,
RuntimeCall::System(frame_system::Call::remark { .. }) => true,
// For tests
Call::Example(_) => true,
RuntimeCall::Example(_) => true,
_ => false,
}
}
}
impl Config for Test {
type Event = Event;
type Call = Call;
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type PalletsOrigin = OriginCaller;
type WeightInfo = ();
}
@@ -187,12 +187,12 @@ 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_transfer(dest: u64, value: u64) -> RuntimeCall {
RuntimeCall::Balances(BalancesCall::transfer { dest, value })
}
fn call_foobar(err: bool, start_weight: Weight, end_weight: Option<Weight>) -> Call {
Call::Example(ExampleCall::foobar { err, start_weight, end_weight })
fn call_foobar(err: bool, start_weight: Weight, end_weight: Option<Weight>) -> RuntimeCall {
RuntimeCall::Example(ExampleCall::foobar { err, start_weight, end_weight })
}
#[test]
@@ -219,8 +219,10 @@ fn as_derivative_handles_weight_refund() {
// Full weight when ok
let inner_call = call_foobar(false, start_weight, None);
let call =
Call::Utility(UtilityCall::as_derivative { index: 0, call: Box::new(inner_call) });
let call = RuntimeCall::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);
@@ -228,8 +230,10 @@ fn as_derivative_handles_weight_refund() {
// Refund weight when ok
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 call = RuntimeCall::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);
@@ -238,8 +242,10 @@ fn as_derivative_handles_weight_refund() {
// Full weight when err
let inner_call = call_foobar(true, start_weight, None);
let call =
Call::Utility(UtilityCall::as_derivative { index: 0, call: Box::new(inner_call) });
let call = RuntimeCall::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!(
@@ -256,8 +262,10 @@ fn as_derivative_handles_weight_refund() {
// Refund weight when err
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 call = RuntimeCall::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!(
@@ -281,7 +289,7 @@ fn as_derivative_filters() {
Utility::as_derivative(
Origin::signed(1),
1,
Box::new(Call::Balances(pallet_balances::Call::transfer_keep_alive {
Box::new(RuntimeCall::Balances(pallet_balances::Call::transfer_keep_alive {
dest: 2,
value: 1
})),
@@ -295,16 +303,25 @@ 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 { items: vec![(k.clone(), k.clone())] });
let call = RuntimeCall::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 { source: 1, dest: 2, value: 5 }),
Call::Balances(BalancesCall::force_transfer { source: 1, dest: 2, value: 5 }),
RuntimeCall::Balances(BalancesCall::force_transfer {
source: 1,
dest: 2,
value: 5
}),
RuntimeCall::Balances(BalancesCall::force_transfer {
source: 1,
dest: 2,
value: 5
}),
call, // Check filters are correctly bypassed
]
));
@@ -333,7 +350,10 @@ 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 { dest: 2, value: 1 })]
vec![RuntimeCall::Balances(pallet_balances::Call::transfer_keep_alive {
dest: 2,
value: 1
})]
),);
System::assert_last_event(
utility::Event::BatchInterrupted {
@@ -363,11 +383,12 @@ 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 { ratio: Perbill::from_percent(50) });
let big_call =
RuntimeCall::System(SystemCall::fill_block { ratio: Perbill::from_percent(50) });
assert_eq!(big_call.get_dispatch_info().weight, Weight::MAX / 2);
// 3 * 50% saturates to 100%
let batch_call = Call::Utility(crate::Call::batch {
let batch_call = RuntimeCall::Utility(crate::Call::batch {
calls: vec![big_call.clone(), big_call.clone(), big_call.clone()],
});
@@ -386,7 +407,7 @@ fn batch_handles_weight_refund() {
// Full weight when ok
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 { calls: batch_calls });
let call = RuntimeCall::Utility(UtilityCall::batch { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
@@ -395,7 +416,7 @@ fn batch_handles_weight_refund() {
// Refund weight when ok
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 { calls: batch_calls });
let call = RuntimeCall::Utility(UtilityCall::batch { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
@@ -406,7 +427,7 @@ fn batch_handles_weight_refund() {
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 { calls: batch_calls });
let call = RuntimeCall::Utility(UtilityCall::batch { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
@@ -421,7 +442,7 @@ fn batch_handles_weight_refund() {
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 u64;
let call = Call::Utility(UtilityCall::batch { calls: batch_calls });
let call = RuntimeCall::Utility(UtilityCall::batch { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
@@ -434,7 +455,7 @@ fn batch_handles_weight_refund() {
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 { calls: batch_calls });
let call = RuntimeCall::Utility(UtilityCall::batch { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
@@ -471,7 +492,7 @@ fn batch_all_revert() {
assert_eq!(Balances::free_balance(1), 10);
assert_eq!(Balances::free_balance(2), 10);
let batch_all_calls = Call::Utility(crate::Call::<Test>::batch_all {
let batch_all_calls = RuntimeCall::Utility(crate::Call::<Test>::batch_all {
calls: vec![call_transfer(2, 5), call_transfer(2, 10), call_transfer(2, 5)],
});
assert_noop!(
@@ -502,7 +523,7 @@ fn batch_all_handles_weight_refund() {
// Full weight when ok
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 { calls: batch_calls });
let call = RuntimeCall::Utility(UtilityCall::batch_all { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
@@ -511,7 +532,7 @@ fn batch_all_handles_weight_refund() {
// Refund weight when ok
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 { calls: batch_calls });
let call = RuntimeCall::Utility(UtilityCall::batch_all { calls: batch_calls });
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
@@ -522,7 +543,7 @@ fn batch_all_handles_weight_refund() {
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 { calls: batch_calls });
let call = RuntimeCall::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.");
@@ -534,7 +555,7 @@ fn batch_all_handles_weight_refund() {
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 u64;
let call = Call::Utility(UtilityCall::batch_all { calls: batch_calls });
let call = RuntimeCall::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.");
@@ -544,7 +565,7 @@ fn batch_all_handles_weight_refund() {
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 { calls: batch_calls });
let call = RuntimeCall::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.");
@@ -559,7 +580,7 @@ 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 {
let batch_all = RuntimeCall::Utility(UtilityCall::batch_all {
calls: vec![call_transfer(2, 1), call_transfer(2, 1), call_transfer(2, 1)],
});
@@ -582,7 +603,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 { calls: vec![batch_all] });
let batch_nested = RuntimeCall::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]));
@@ -601,7 +622,7 @@ fn batch_all_does_not_nest() {
#[test]
fn batch_limit() {
new_test_ext().execute_with(|| {
let calls = vec![Call::System(SystemCall::remark { remark: vec![] }); 40_000];
let calls = vec![RuntimeCall::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);
});