mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 10:11:03 +00:00
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:
@@ -96,17 +96,17 @@ pub struct LotteryConfig<BlockNumber, Balance> {
|
||||
}
|
||||
|
||||
pub trait ValidateCall<T: Config> {
|
||||
fn validate_call(call: &<T as Config>::Call) -> bool;
|
||||
fn validate_call(call: &<T as Config>::RuntimeCall) -> bool;
|
||||
}
|
||||
|
||||
impl<T: Config> ValidateCall<T> for () {
|
||||
fn validate_call(_: &<T as Config>::Call) -> bool {
|
||||
fn validate_call(_: &<T as Config>::RuntimeCall) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> ValidateCall<T> for Pallet<T> {
|
||||
fn validate_call(call: &<T as Config>::Call) -> bool {
|
||||
fn validate_call(call: &<T as Config>::RuntimeCall) -> bool {
|
||||
let valid_calls = CallIndices::<T>::get();
|
||||
let call_index = match Self::call_to_index(call) {
|
||||
Ok(call_index) => call_index,
|
||||
@@ -134,7 +134,7 @@ pub mod pallet {
|
||||
type PalletId: Get<PalletId>;
|
||||
|
||||
/// A dispatchable call.
|
||||
type Call: Parameter
|
||||
type RuntimeCall: Parameter
|
||||
+ Dispatchable<Origin = Self::Origin>
|
||||
+ GetDispatchInfo
|
||||
+ From<frame_system::Call<Self>>;
|
||||
@@ -146,7 +146,7 @@ pub mod pallet {
|
||||
type Randomness: Randomness<Self::Hash, Self::BlockNumber>;
|
||||
|
||||
/// The overarching event type.
|
||||
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
|
||||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
|
||||
|
||||
/// The manager origin.
|
||||
type ManagerOrigin: EnsureOrigin<Self::Origin>;
|
||||
@@ -300,7 +300,10 @@ pub mod pallet {
|
||||
T::WeightInfo::buy_ticket()
|
||||
.saturating_add(call.get_dispatch_info().weight)
|
||||
)]
|
||||
pub fn buy_ticket(origin: OriginFor<T>, call: Box<<T as Config>::Call>) -> DispatchResult {
|
||||
pub fn buy_ticket(
|
||||
origin: OriginFor<T>,
|
||||
call: Box<<T as Config>::RuntimeCall>,
|
||||
) -> DispatchResult {
|
||||
let caller = ensure_signed(origin.clone())?;
|
||||
call.clone().dispatch(origin).map_err(|e| e.error)?;
|
||||
|
||||
@@ -315,7 +318,10 @@ pub mod pallet {
|
||||
///
|
||||
/// This extrinsic must be called by the Manager origin.
|
||||
#[pallet::weight(T::WeightInfo::set_calls(calls.len() as u32))]
|
||||
pub fn set_calls(origin: OriginFor<T>, calls: Vec<<T as Config>::Call>) -> DispatchResult {
|
||||
pub fn set_calls(
|
||||
origin: OriginFor<T>,
|
||||
calls: Vec<<T as Config>::RuntimeCall>,
|
||||
) -> DispatchResult {
|
||||
T::ManagerOrigin::ensure_origin(origin)?;
|
||||
ensure!(calls.len() <= T::MaxCalls::get() as usize, Error::<T>::TooManyCalls);
|
||||
if calls.is_empty() {
|
||||
@@ -404,7 +410,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
/// Converts a vector of calls into a vector of call indices.
|
||||
fn calls_to_indices(
|
||||
calls: &[<T as Config>::Call],
|
||||
calls: &[<T as Config>::RuntimeCall],
|
||||
) -> Result<BoundedVec<CallIndex, T::MaxCalls>, DispatchError> {
|
||||
let mut indices = BoundedVec::<CallIndex, T::MaxCalls>::with_bounded_capacity(calls.len());
|
||||
for c in calls.iter() {
|
||||
@@ -415,7 +421,7 @@ impl<T: Config> Pallet<T> {
|
||||
}
|
||||
|
||||
/// Convert a call to it's call index by encoding the call and taking the first two bytes.
|
||||
fn call_to_index(call: &<T as Config>::Call) -> Result<CallIndex, DispatchError> {
|
||||
fn call_to_index(call: &<T as Config>::RuntimeCall) -> Result<CallIndex, DispatchError> {
|
||||
let encoded_call = call.encode();
|
||||
if encoded_call.len() < 2 {
|
||||
return Err(Error::<T>::EncodingFailed.into())
|
||||
@@ -424,7 +430,7 @@ impl<T: Config> Pallet<T> {
|
||||
}
|
||||
|
||||
/// Logic for buying a ticket.
|
||||
fn do_buy_ticket(caller: &T::AccountId, call: &<T as Config>::Call) -> DispatchResult {
|
||||
fn do_buy_ticket(caller: &T::AccountId, call: &<T as Config>::RuntimeCall) -> DispatchResult {
|
||||
// Check the call is valid lottery
|
||||
let config = Lottery::<T>::get().ok_or(Error::<T>::NotConfigured)?;
|
||||
let block_number = frame_system::Pallet::<T>::block_number();
|
||||
|
||||
@@ -59,14 +59,14 @@ impl frame_system::Config for Test {
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type Index = u64;
|
||||
type Call = Call;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
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;
|
||||
@@ -84,7 +84,7 @@ impl pallet_balances::Config for Test {
|
||||
type MaxReserves = ();
|
||||
type ReserveIdentifier = [u8; 8];
|
||||
type Balance = u64;
|
||||
type Event = Event;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type DustRemoval = ();
|
||||
type ExistentialDeposit = ConstU64<1>;
|
||||
type AccountStore = System;
|
||||
@@ -97,10 +97,10 @@ parameter_types! {
|
||||
|
||||
impl Config for Test {
|
||||
type PalletId = LotteryPalletId;
|
||||
type Call = Call;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type Currency = Balances;
|
||||
type Randomness = TestRandomness<Self>;
|
||||
type Event = Event;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type ManagerOrigin = EnsureRoot<u64>;
|
||||
type MaxCalls = ConstU32<2>;
|
||||
type ValidateCall = Lottery;
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
use super::*;
|
||||
use frame_support::{assert_noop, assert_ok, assert_storage_noop};
|
||||
use mock::{
|
||||
new_test_ext, run_to_block, Balances, BalancesCall, Call, Lottery, Origin, SystemCall, Test,
|
||||
new_test_ext, run_to_block, Balances, BalancesCall, Lottery, Origin, RuntimeCall, SystemCall,
|
||||
Test,
|
||||
};
|
||||
use pallet_balances::Error as BalancesError;
|
||||
use sp_runtime::traits::BadOrigin;
|
||||
@@ -43,8 +44,8 @@ fn basic_end_to_end_works() {
|
||||
let length = 20;
|
||||
let delay = 5;
|
||||
let calls = vec![
|
||||
Call::Balances(BalancesCall::force_transfer { source: 0, dest: 0, value: 0 }),
|
||||
Call::Balances(BalancesCall::transfer { dest: 0, value: 0 }),
|
||||
RuntimeCall::Balances(BalancesCall::force_transfer { source: 0, dest: 0, value: 0 }),
|
||||
RuntimeCall::Balances(BalancesCall::transfer { dest: 0, value: 0 }),
|
||||
];
|
||||
|
||||
// Set calls for the lottery
|
||||
@@ -55,7 +56,7 @@ fn basic_end_to_end_works() {
|
||||
assert!(crate::Lottery::<Test>::get().is_some());
|
||||
|
||||
assert_eq!(Balances::free_balance(&1), 100);
|
||||
let call = Box::new(Call::Balances(BalancesCall::transfer { dest: 2, value: 20 }));
|
||||
let call = Box::new(RuntimeCall::Balances(BalancesCall::transfer { dest: 2, value: 20 }));
|
||||
assert_ok!(Lottery::buy_ticket(Origin::signed(1), call.clone()));
|
||||
// 20 from the transfer, 10 from buying a ticket
|
||||
assert_eq!(Balances::free_balance(&1), 100 - 20 - 10);
|
||||
@@ -127,17 +128,17 @@ fn set_calls_works() {
|
||||
assert!(!CallIndices::<Test>::exists());
|
||||
|
||||
let calls = vec![
|
||||
Call::Balances(BalancesCall::force_transfer { source: 0, dest: 0, value: 0 }),
|
||||
Call::Balances(BalancesCall::transfer { dest: 0, value: 0 }),
|
||||
RuntimeCall::Balances(BalancesCall::force_transfer { source: 0, dest: 0, value: 0 }),
|
||||
RuntimeCall::Balances(BalancesCall::transfer { dest: 0, value: 0 }),
|
||||
];
|
||||
|
||||
assert_ok!(Lottery::set_calls(Origin::root(), calls));
|
||||
assert!(CallIndices::<Test>::exists());
|
||||
|
||||
let too_many_calls = vec![
|
||||
Call::Balances(BalancesCall::force_transfer { source: 0, dest: 0, value: 0 }),
|
||||
Call::Balances(BalancesCall::transfer { dest: 0, value: 0 }),
|
||||
Call::System(SystemCall::remark { remark: vec![] }),
|
||||
RuntimeCall::Balances(BalancesCall::force_transfer { source: 0, dest: 0, value: 0 }),
|
||||
RuntimeCall::Balances(BalancesCall::transfer { dest: 0, value: 0 }),
|
||||
RuntimeCall::System(SystemCall::remark { remark: vec![] }),
|
||||
];
|
||||
|
||||
assert_noop!(
|
||||
@@ -155,8 +156,8 @@ fn set_calls_works() {
|
||||
fn call_to_indices_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let calls = vec![
|
||||
Call::Balances(BalancesCall::force_transfer { source: 0, dest: 0, value: 0 }),
|
||||
Call::Balances(BalancesCall::transfer { dest: 0, value: 0 }),
|
||||
RuntimeCall::Balances(BalancesCall::force_transfer { source: 0, dest: 0, value: 0 }),
|
||||
RuntimeCall::Balances(BalancesCall::transfer { dest: 0, value: 0 }),
|
||||
];
|
||||
let indices = Lottery::calls_to_indices(&calls).unwrap().into_inner();
|
||||
// Only comparing the length since it is otherwise dependant on the API
|
||||
@@ -164,9 +165,9 @@ fn call_to_indices_works() {
|
||||
assert_eq!(indices.len(), calls.len());
|
||||
|
||||
let too_many_calls = vec![
|
||||
Call::Balances(BalancesCall::force_transfer { source: 0, dest: 0, value: 0 }),
|
||||
Call::Balances(BalancesCall::transfer { dest: 0, value: 0 }),
|
||||
Call::System(SystemCall::remark { remark: vec![] }),
|
||||
RuntimeCall::Balances(BalancesCall::force_transfer { source: 0, dest: 0, value: 0 }),
|
||||
RuntimeCall::Balances(BalancesCall::transfer { dest: 0, value: 0 }),
|
||||
RuntimeCall::System(SystemCall::remark { remark: vec![] }),
|
||||
];
|
||||
assert_noop!(Lottery::calls_to_indices(&too_many_calls), Error::<Test>::TooManyCalls);
|
||||
});
|
||||
@@ -202,7 +203,7 @@ fn buy_ticket_works_as_simple_passthrough() {
|
||||
// as a simple passthrough to the real call.
|
||||
new_test_ext().execute_with(|| {
|
||||
// No lottery set up
|
||||
let call = Box::new(Call::Balances(BalancesCall::transfer { dest: 2, value: 20 }));
|
||||
let call = Box::new(RuntimeCall::Balances(BalancesCall::transfer { dest: 2, value: 20 }));
|
||||
// This is just a basic transfer then
|
||||
assert_ok!(Lottery::buy_ticket(Origin::signed(1), call.clone()));
|
||||
assert_eq!(Balances::free_balance(&1), 100 - 20);
|
||||
@@ -210,8 +211,8 @@ fn buy_ticket_works_as_simple_passthrough() {
|
||||
|
||||
// Lottery is set up, but too expensive to enter, so `do_buy_ticket` fails.
|
||||
let calls = vec![
|
||||
Call::Balances(BalancesCall::force_transfer { source: 0, dest: 0, value: 0 }),
|
||||
Call::Balances(BalancesCall::transfer { dest: 0, value: 0 }),
|
||||
RuntimeCall::Balances(BalancesCall::force_transfer { source: 0, dest: 0, value: 0 }),
|
||||
RuntimeCall::Balances(BalancesCall::transfer { dest: 0, value: 0 }),
|
||||
];
|
||||
assert_ok!(Lottery::set_calls(Origin::root(), calls));
|
||||
|
||||
@@ -222,24 +223,28 @@ fn buy_ticket_works_as_simple_passthrough() {
|
||||
assert_eq!(TicketsCount::<Test>::get(), 0);
|
||||
|
||||
// If call would fail, the whole thing still fails the same
|
||||
let fail_call = Box::new(Call::Balances(BalancesCall::transfer { dest: 2, value: 1000 }));
|
||||
let fail_call =
|
||||
Box::new(RuntimeCall::Balances(BalancesCall::transfer { dest: 2, value: 1000 }));
|
||||
assert_noop!(
|
||||
Lottery::buy_ticket(Origin::signed(1), fail_call),
|
||||
BalancesError::<Test, _>::InsufficientBalance,
|
||||
);
|
||||
|
||||
let bad_origin_call =
|
||||
Box::new(Call::Balances(BalancesCall::force_transfer { source: 0, dest: 0, value: 0 }));
|
||||
let bad_origin_call = Box::new(RuntimeCall::Balances(BalancesCall::force_transfer {
|
||||
source: 0,
|
||||
dest: 0,
|
||||
value: 0,
|
||||
}));
|
||||
assert_noop!(Lottery::buy_ticket(Origin::signed(1), bad_origin_call), BadOrigin,);
|
||||
|
||||
// User can call other txs, but doesn't get a ticket
|
||||
let remark_call =
|
||||
Box::new(Call::System(SystemCall::remark { remark: b"hello, world!".to_vec() }));
|
||||
Box::new(RuntimeCall::System(SystemCall::remark { remark: b"hello, world!".to_vec() }));
|
||||
assert_ok!(Lottery::buy_ticket(Origin::signed(2), remark_call));
|
||||
assert_eq!(TicketsCount::<Test>::get(), 0);
|
||||
|
||||
let successful_call =
|
||||
Box::new(Call::Balances(BalancesCall::transfer { dest: 2, value: 1 }));
|
||||
Box::new(RuntimeCall::Balances(BalancesCall::transfer { dest: 2, value: 1 }));
|
||||
assert_ok!(Lottery::buy_ticket(Origin::signed(2), successful_call));
|
||||
assert_eq!(TicketsCount::<Test>::get(), 1);
|
||||
});
|
||||
@@ -250,13 +255,13 @@ fn buy_ticket_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// Set calls for the lottery.
|
||||
let calls = vec![
|
||||
Call::System(SystemCall::remark { remark: vec![] }),
|
||||
Call::Balances(BalancesCall::transfer { dest: 0, value: 0 }),
|
||||
RuntimeCall::System(SystemCall::remark { remark: vec![] }),
|
||||
RuntimeCall::Balances(BalancesCall::transfer { dest: 0, value: 0 }),
|
||||
];
|
||||
assert_ok!(Lottery::set_calls(Origin::root(), calls));
|
||||
|
||||
// Can't buy ticket before start
|
||||
let call = Box::new(Call::Balances(BalancesCall::transfer { dest: 2, value: 1 }));
|
||||
let call = Box::new(RuntimeCall::Balances(BalancesCall::transfer { dest: 2, value: 1 }));
|
||||
assert_ok!(Lottery::buy_ticket(Origin::signed(1), call.clone()));
|
||||
assert_eq!(TicketsCount::<Test>::get(), 0);
|
||||
|
||||
@@ -269,12 +274,13 @@ fn buy_ticket_works() {
|
||||
assert_eq!(TicketsCount::<Test>::get(), 1);
|
||||
|
||||
// Can't buy another of the same ticket (even if call is slightly changed)
|
||||
let call = Box::new(Call::Balances(BalancesCall::transfer { dest: 3, value: 30 }));
|
||||
let call = Box::new(RuntimeCall::Balances(BalancesCall::transfer { dest: 3, value: 30 }));
|
||||
assert_ok!(Lottery::buy_ticket(Origin::signed(1), call));
|
||||
assert_eq!(TicketsCount::<Test>::get(), 1);
|
||||
|
||||
// Buy ticket for remark
|
||||
let call = Box::new(Call::System(SystemCall::remark { remark: b"hello, world!".to_vec() }));
|
||||
let call =
|
||||
Box::new(RuntimeCall::System(SystemCall::remark { remark: b"hello, world!".to_vec() }));
|
||||
assert_ok!(Lottery::buy_ticket(Origin::signed(1), call.clone()));
|
||||
assert_eq!(TicketsCount::<Test>::get(), 2);
|
||||
|
||||
@@ -296,7 +302,7 @@ fn buy_ticket_works() {
|
||||
#[test]
|
||||
fn do_buy_ticket_already_participating() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let calls = vec![Call::Balances(BalancesCall::transfer { dest: 0, value: 0 })];
|
||||
let calls = vec![RuntimeCall::Balances(BalancesCall::transfer { dest: 0, value: 0 })];
|
||||
assert_ok!(Lottery::set_calls(Origin::root(), calls.clone()));
|
||||
assert_ok!(Lottery::start_lottery(Origin::root(), 1, 10, 10, false));
|
||||
|
||||
@@ -311,7 +317,7 @@ fn do_buy_ticket_already_participating() {
|
||||
#[test]
|
||||
fn buy_ticket_already_participating() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let calls = vec![Call::Balances(BalancesCall::transfer { dest: 0, value: 0 })];
|
||||
let calls = vec![RuntimeCall::Balances(BalancesCall::transfer { dest: 0, value: 0 })];
|
||||
assert_ok!(Lottery::set_calls(Origin::root(), calls.clone()));
|
||||
assert_ok!(Lottery::start_lottery(Origin::root(), 1, 10, 10, false));
|
||||
|
||||
@@ -331,7 +337,7 @@ fn buy_ticket_already_participating() {
|
||||
#[test]
|
||||
fn buy_ticket_insufficient_balance() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let calls = vec![Call::Balances(BalancesCall::transfer { dest: 0, value: 0 })];
|
||||
let calls = vec![RuntimeCall::Balances(BalancesCall::transfer { dest: 0, value: 0 })];
|
||||
assert_ok!(Lottery::set_calls(Origin::root(), calls.clone()));
|
||||
// Price set to 100.
|
||||
assert_ok!(Lottery::start_lottery(Origin::root(), 100, 10, 10, false));
|
||||
@@ -346,7 +352,7 @@ fn buy_ticket_insufficient_balance() {
|
||||
#[test]
|
||||
fn do_buy_ticket_insufficient_balance() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let calls = vec![Call::Balances(BalancesCall::transfer { dest: 0, value: 0 })];
|
||||
let calls = vec![RuntimeCall::Balances(BalancesCall::transfer { dest: 0, value: 0 })];
|
||||
assert_ok!(Lottery::set_calls(Origin::root(), calls.clone()));
|
||||
// Price set to 101.
|
||||
assert_ok!(Lottery::start_lottery(Origin::root(), 101, 10, 10, false));
|
||||
@@ -363,7 +369,7 @@ fn do_buy_ticket_insufficient_balance() {
|
||||
#[test]
|
||||
fn do_buy_ticket_keep_alive() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let calls = vec![Call::Balances(BalancesCall::transfer { dest: 0, value: 0 })];
|
||||
let calls = vec![RuntimeCall::Balances(BalancesCall::transfer { dest: 0, value: 0 })];
|
||||
assert_ok!(Lottery::set_calls(Origin::root(), calls.clone()));
|
||||
// Price set to 100.
|
||||
assert_ok!(Lottery::start_lottery(Origin::root(), 100, 10, 10, false));
|
||||
@@ -415,7 +421,7 @@ fn choose_ticket_trivial_cases() {
|
||||
#[test]
|
||||
fn choose_account_one_participant() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let calls = vec![Call::Balances(BalancesCall::transfer { dest: 0, value: 0 })];
|
||||
let calls = vec![RuntimeCall::Balances(BalancesCall::transfer { dest: 0, value: 0 })];
|
||||
assert_ok!(Lottery::set_calls(Origin::root(), calls.clone()));
|
||||
assert_ok!(Lottery::start_lottery(Origin::root(), 10, 10, 10, false));
|
||||
let call = Box::new(calls[0].clone());
|
||||
|
||||
Reference in New Issue
Block a user