mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 06:57:58 +00:00
Make decl_error! errors usable (#4449)
* Make `decl_error!` errors usable This pr implements support for returning errors of different pallets in a pallet. These errors need to be declared with `decl_error!`. The pr changes the following: - Each dispatchable function now returns a `DispatchResult` which is an alias for `Result<(), DispatchError>`. - `DispatchError` is an enum that has 4 variants: - `Other`: For storing string error messages - `CannotLookup`: Variant that is returned when something returns a `sp_runtime::LookupError` - `BadOrigin`: Variant that is returned for any kind of bad origin - `Module`: The error of a specific module. Contains the `index`, `error` and the `message`. The index is the index of the module in `construct_runtime!`. `error` is the index of the error in the error enum declared by `decl_error!`. `message` is the message to the error variant (this will not be encoded). - `construct_runtime!` now creates a new struct `ModuleToIndex`. This struct implements the trait `ModuleToIndex`. - `frame_system::Trait` has a new associated type: `ModuleToIndex` that expects the `ModuleToIndex` generated by `construct_runtime!`. - All error strings returned in any module are being converted now to `DispatchError`. - `BadOrigin` is the default error returned by any type that implements `EnsureOrigin`. * Fix frame system benchmarks
This commit is contained in:
committed by
Gavin Wood
parent
0aab5c659e
commit
8e393aa5a8
@@ -68,7 +68,7 @@ mod tests {
|
||||
weights::Weight
|
||||
};
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{Perbill, traits::{BlakeTwo256, IdentityLookup}, testing::Header};
|
||||
use sp_runtime::{Perbill, traits::{BlakeTwo256, IdentityLookup, BadOrigin}, testing::Header};
|
||||
|
||||
impl_outer_origin! {
|
||||
pub enum Origin for Test where system = frame_system {}
|
||||
@@ -108,6 +108,7 @@ mod tests {
|
||||
type MaximumBlockLength = MaximumBlockLength;
|
||||
type AvailableBlockRatio = AvailableBlockRatio;
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
}
|
||||
parameter_types! {
|
||||
pub const ExistentialDeposit: u64 = 0;
|
||||
@@ -146,10 +147,13 @@ mod tests {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_eq!(Balances::free_balance(1), 10);
|
||||
assert_eq!(Balances::free_balance(2), 0);
|
||||
assert_noop!(Utility::batch(Origin::signed(1), vec![
|
||||
Call::Balances(pallet_balances::Call::force_transfer(1, 2, 5)),
|
||||
Call::Balances(pallet_balances::Call::force_transfer(1, 2, 5))
|
||||
]), "RequireRootOrigin");
|
||||
assert_noop!(
|
||||
Utility::batch(Origin::signed(1), vec![
|
||||
Call::Balances(pallet_balances::Call::force_transfer(1, 2, 5)),
|
||||
Call::Balances(pallet_balances::Call::force_transfer(1, 2, 5))
|
||||
]),
|
||||
BadOrigin,
|
||||
);
|
||||
assert_ok!(Utility::batch(Origin::ROOT, vec![
|
||||
Call::Balances(pallet_balances::Call::force_transfer(1, 2, 5)),
|
||||
Call::Balances(pallet_balances::Call::force_transfer(1, 2, 5))
|
||||
|
||||
Reference in New Issue
Block a user