mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 21:01:05 +00:00
Custom runtime module errors (#3433)
* srml-system checks * wip * more modules compiles * node-runtime checks * build.sh passes * include dispatch error in failed event * revert some unnecessary changes * refactor based on comments * more compile error fixes * avoid unnecessary into * reorder code * fixes some tests * manually implement encode & decode to avoid i8 workaround * more test fixes * more fixes * more error fixes * Apply suggestions from code review Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * address comments * test for DispatchError encoding * tyep alias for democracy * make error printable * line width * fix balances tests * fix executive test * fix system tests * bump version * ensure consistent method signature * Apply suggestions from code review Co-Authored-By: Gavin Wood <github@gavwood.com> * changes based on review * Add issue number for TODOs * fix * line width * fix test * Update core/sr-primitives/src/lib.rs Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * Update core/sr-primitives/src/traits.rs Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * Update srml/council/src/motions.rs Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * Update srml/council/src/motions.rs Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * update based on review * More concrete macro matching * fix test build issue * Update hex-literal dependency version. (#3141) * Update hex-literal dep version. * Update lock file. * Start to rework the new error handling * More work to get it back compiling * Start to fix after master merge * The great transaction error handling refactoring * Make `decl_error` errors convertible to `&'static str` * Make srml-executive build again * Fix `sr-primitives` tests * More fixes * Last round of fix ups * Fix build * Fix build * Apply suggestions from code review Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * Rename some stuff * Fixes after master merge * Adds `CheckBlockGasLimit` signed extension * Remove debug stuff * Fix srml-balances test * Rename `InvalidIndex` to `CannotLookup` * Remove weird generic parameters * Rename function again * Fix import * Document the signed extension * Change from `Into` to `From` * Update srml/contracts/src/lib.rs Co-Authored-By: Sergei Pepyakin <sergei@parity.io> * Fix compilation * Update srml/contracts/src/lib.rs Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * Update core/sr-primitives/src/transaction_validity.rs Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * Remove unused code * Fix compilation * Some cleanups * Fix compile errors * Make `TransactionValidity` a `Result` * Apply suggestions from code review Co-Authored-By: Gavin Wood <gavin@parity.io> * Beautify the code a little bit and fix test * Make `CannotLookup` an inherent error declared by `decl_error!` * Adds some documentation * Make `ApplyOutcome` a result * Up the spec_version * Apply suggestions from code review Co-Authored-By: Gavin Wood <gavin@parity.io> Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com>
This commit is contained in:
@@ -161,19 +161,26 @@
|
||||
use rstd::prelude::*;
|
||||
use rstd::{cmp, result, mem};
|
||||
use codec::{Codec, Encode, Decode};
|
||||
use support::{StorageValue, StorageMap, Parameter, decl_event, decl_storage, decl_module};
|
||||
use support::traits::{
|
||||
UpdateBalanceOutcome, Currency, OnFreeBalanceZero, OnUnbalanced,
|
||||
WithdrawReason, WithdrawReasons, LockIdentifier, LockableCurrency, ExistenceRequirement,
|
||||
Imbalance, SignedImbalance, ReservableCurrency, Get,
|
||||
use support::{
|
||||
StorageValue, StorageMap, Parameter, decl_event, decl_storage, decl_module,
|
||||
traits::{
|
||||
UpdateBalanceOutcome, Currency, OnFreeBalanceZero, OnUnbalanced,
|
||||
WithdrawReason, WithdrawReasons, LockIdentifier, LockableCurrency, ExistenceRequirement,
|
||||
Imbalance, SignedImbalance, ReservableCurrency, Get,
|
||||
},
|
||||
dispatch::Result,
|
||||
};
|
||||
use support::dispatch::Result;
|
||||
use sr_primitives::traits::{
|
||||
Zero, SimpleArithmetic, StaticLookup, Member, CheckedAdd, CheckedSub, MaybeSerializeDebug,
|
||||
Saturating, Bounded, SignedExtension, SaturatedConversion, DispatchError, Convert,
|
||||
use sr_primitives::{
|
||||
transaction_validity::{
|
||||
TransactionPriority, ValidTransaction, InvalidTransaction, TransactionValidityError,
|
||||
TransactionValidity,
|
||||
},
|
||||
traits::{
|
||||
Zero, SimpleArithmetic, StaticLookup, Member, CheckedAdd, CheckedSub, MaybeSerializeDebug,
|
||||
Saturating, Bounded, SignedExtension, SaturatedConversion, Convert,
|
||||
},
|
||||
weights::{DispatchInfo, SimpleDispatchInfo, Weight},
|
||||
};
|
||||
use sr_primitives::transaction_validity::{TransactionPriority, ValidTransaction};
|
||||
use sr_primitives::weights::{DispatchInfo, SimpleDispatchInfo, Weight};
|
||||
use system::{IsDeadAccount, OnNewAccount, ensure_signed, ensure_root};
|
||||
|
||||
mod mock;
|
||||
@@ -1235,7 +1242,7 @@ impl<T: Trait<I>, I: Instance + Clone + Eq> SignedExtension for TakeFees<T, I> {
|
||||
type Call = T::Call;
|
||||
type AdditionalSigned = ();
|
||||
type Pre = ();
|
||||
fn additional_signed(&self) -> rstd::result::Result<(), &'static str> { Ok(()) }
|
||||
fn additional_signed(&self) -> rstd::result::Result<(), TransactionValidityError> { Ok(()) }
|
||||
|
||||
fn validate(
|
||||
&self,
|
||||
@@ -1243,15 +1250,18 @@ impl<T: Trait<I>, I: Instance + Clone + Eq> SignedExtension for TakeFees<T, I> {
|
||||
_call: &Self::Call,
|
||||
info: DispatchInfo,
|
||||
len: usize,
|
||||
) -> rstd::result::Result<ValidTransaction, DispatchError> {
|
||||
) -> TransactionValidity {
|
||||
// pay any fees.
|
||||
let fee = Self::compute_fee(len, info, self.0);
|
||||
let imbalance = <Module<T, I>>::withdraw(
|
||||
let imbalance = match <Module<T, I>>::withdraw(
|
||||
who,
|
||||
fee,
|
||||
WithdrawReason::TransactionPayment,
|
||||
ExistenceRequirement::KeepAlive,
|
||||
).map_err(|_| DispatchError::Payment)?;
|
||||
) {
|
||||
Ok(imbalance) => imbalance,
|
||||
Err(_) => return InvalidTransaction::Payment.into(),
|
||||
};
|
||||
T::TransactionPayment::on_unbalanced(imbalance);
|
||||
|
||||
let mut r = ValidTransaction::default();
|
||||
|
||||
@@ -232,7 +232,7 @@ fn default_indexing_on_new_accounts_should_not_work2() {
|
||||
// ext_deposit is 10, value is 9, not satisfies for ext_deposit
|
||||
assert_noop!(
|
||||
Balances::transfer(Some(1).into(), 5, 9),
|
||||
"value too low to create account"
|
||||
"value too low to create account",
|
||||
);
|
||||
assert_eq!(Balances::is_dead_account(&5), true); // account 5 should not exist
|
||||
assert_eq!(Balances::free_balance(&1), 100);
|
||||
@@ -359,7 +359,7 @@ fn force_transfer_works() {
|
||||
let _ = Balances::deposit_creating(&1, 111);
|
||||
assert_noop!(
|
||||
Balances::force_transfer(Some(2).into(), 1, 2, 69),
|
||||
"bad origin: expected to be a root origin"
|
||||
"RequireRootOrigin",
|
||||
);
|
||||
assert_ok!(Balances::force_transfer(RawOrigin::Root.into(), 1, 2, 69));
|
||||
assert_eq!(Balances::total_balance(&1), 42);
|
||||
@@ -389,7 +389,10 @@ fn balance_transfer_when_reserved_should_not_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
let _ = Balances::deposit_creating(&1, 111);
|
||||
assert_ok!(Balances::reserve(&1, 69));
|
||||
assert_noop!(Balances::transfer(Some(1).into(), 2, 69), "balance too low to send value");
|
||||
assert_noop!(
|
||||
Balances::transfer(Some(1).into(), 2, 69),
|
||||
"balance too low to send value",
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -517,7 +520,7 @@ fn transferring_too_high_value_should_not_panic() {
|
||||
|
||||
assert_err!(
|
||||
Balances::transfer(Some(1).into(), 2, u64::max_value()),
|
||||
"destination balance too high to receive value"
|
||||
"destination balance too high to receive value",
|
||||
);
|
||||
|
||||
assert_eq!(Balances::free_balance(&1), u64::max_value());
|
||||
@@ -595,7 +598,7 @@ fn transfer_overflow_isnt_exploitable() {
|
||||
|
||||
assert_err!(
|
||||
Balances::transfer(Some(1).into(), 5, evil_value),
|
||||
"got overflow after adding a fee to value"
|
||||
"got overflow after adding a fee to value",
|
||||
);
|
||||
}
|
||||
);
|
||||
@@ -680,7 +683,7 @@ fn unvested_balance_should_not_transfer() {
|
||||
assert_eq!(Balances::vesting_balance(&1), 45);
|
||||
assert_noop!(
|
||||
Balances::transfer(Some(1).into(), 2, 56),
|
||||
"vesting balance too high to send value"
|
||||
"vesting balance too high to send value",
|
||||
); // Account 1 cannot send more than vested amount
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user