Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
ba48a0a
srml-system checks
xlc Jun 17, 2019
52c6b90
wip
xlc Jun 18, 2019
bd7228f
more modules compiles
xlc Jun 18, 2019
c0cece1
node-runtime checks
xlc Jun 18, 2019
a93fedd
build.sh passes
xlc Jun 19, 2019
3039e7c
include dispatch error in failed event
xlc Jun 19, 2019
c5c2e5a
revert some unnecessary changes
xlc Jun 19, 2019
1198fb7
refactor based on comments
xlc Jun 19, 2019
ed20244
Merge remote-tracking branch 'upstream/master' into improve-error-res…
xlc Jun 19, 2019
1f964d1
more compile error fixes
xlc Jun 20, 2019
83975c0
avoid unnecessary into
xlc Jun 20, 2019
e03db0c
reorder code
xlc Jun 20, 2019
7e01497
fixes some tests
xlc Jun 21, 2019
a6c989b
manually implement encode & decode to avoid i8 workaround
xlc Jun 21, 2019
9d2dbbb
more test fixes
xlc Jun 21, 2019
31c9c84
more fixes
xlc Jun 21, 2019
6cad33a
more error fixes
xlc Jun 22, 2019
ba42e6a
Apply suggestions from code review
xlc Jun 22, 2019
0f01cc4
address comments
xlc Jun 22, 2019
cce7c08
Merge remote-tracking branch 'upstream/master' into improve-error-res…
xlc Jun 22, 2019
c7ae1b1
test for DispatchError encoding
xlc Jun 22, 2019
0e424c1
tyep alias for democracy
xlc Jun 22, 2019
a145f27
make error printable
xlc Jun 22, 2019
ef4eecd
line width
xlc Jun 22, 2019
33668d8
fix balances tests
xlc Jun 22, 2019
d128a1a
fix executive test
xlc Jun 22, 2019
a4a8cdc
fix system tests
xlc Jun 22, 2019
f4387fb
bump version
xlc Jun 22, 2019
ef2eaa6
ensure consistent method signature
xlc Jun 22, 2019
31c998f
Apply suggestions from code review
xlc Jun 26, 2019
d6b94b0
Merge remote-tracking branch 'upstream/master' into improve-error-res…
xlc Jun 26, 2019
51ec628
changes based on review
xlc Jun 26, 2019
88887ee
Add issue number for TODOs
xlc Jun 26, 2019
550c1e0
Merge remote-tracking branch 'upstream/master' into improve-error-res…
xlc Jun 26, 2019
e8324c2
Merge remote-tracking branch 'upstream/master' into improve-error-res…
xlc Jun 29, 2019
c147a8e
fix
xlc Jun 29, 2019
633a482
line width
xlc Jun 29, 2019
b61e137
fix test
xlc Jun 29, 2019
1ca74ed
Merge remote-tracking branch 'upstream/master' into improve-error-res…
xlc Jul 8, 2019
3d2c850
Update core/sr-primitives/src/lib.rs
xlc Jul 10, 2019
8330acf
Update core/sr-primitives/src/traits.rs
xlc Jul 10, 2019
d41955a
Update srml/council/src/motions.rs
xlc Jul 10, 2019
66187b3
Update srml/council/src/motions.rs
xlc Jul 10, 2019
7489d3a
update based on review
xlc Jul 10, 2019
57f7958
Merge remote-tracking branch 'upstream/master' into improve-error-res…
xlc Jul 10, 2019
6e5c3ce
More concrete macro matching
xlc Jul 10, 2019
2d9794a
Merge remote-tracking branch 'upstream/master' into improve-error-res…
xlc Jul 11, 2019
1f5faac
Merge remote-tracking branch 'upstream/master' into improve-error-res…
xlc Jul 18, 2019
efe953a
fix test build issue
xlc Jul 18, 2019
bec7926
Update hex-literal dependency version. (#3141)
kianenigma Jul 18, 2019
9a68a71
Start to rework the new error handling
bkchr Aug 7, 2019
35f9ebc
More work to get it back compiling
bkchr Aug 12, 2019
d542efc
Merge remote-tracking branch 'origin/master' into new_error_handling
bkchr Aug 13, 2019
a3b5693
Start to fix after master merge
bkchr Aug 13, 2019
6784605
The great transaction error handling refactoring
bkchr Aug 15, 2019
7424908
Make `decl_error` errors convertible to `&'static str`
bkchr Aug 15, 2019
cc862ef
Make srml-executive build again
bkchr Aug 16, 2019
3b809f2
Fix `sr-primitives` tests
bkchr Aug 16, 2019
ddd630a
More fixes
bkchr Aug 16, 2019
f611efc
Last round of fix ups
bkchr Aug 18, 2019
c181c6c
Merge remote-tracking branch 'origin/master' into bkchr-runtime-error…
bkchr Aug 18, 2019
89a04a5
Fix build
bkchr Aug 18, 2019
46dc7be
Merge remote-tracking branch 'origin/master' into bkchr-runtime-error…
bkchr Aug 18, 2019
86ce38b
Fix build
bkchr Aug 18, 2019
41a176a
Apply suggestions from code review
bkchr Aug 26, 2019
a644a6e
Rename some stuff
bkchr Aug 26, 2019
66f3da5
Merge remote-tracking branch 'origin/master' into bkchr-runtime-error…
bkchr Aug 26, 2019
80a07b0
Fixes after master merge
bkchr Aug 26, 2019
31cd048
Adds `CheckBlockGasLimit` signed extension
bkchr Aug 26, 2019
513702c
Remove debug stuff
bkchr Aug 27, 2019
c81d17e
Fix srml-balances test
bkchr Aug 27, 2019
9df261b
Merge remote-tracking branch 'origin/master' into bkchr-runtime-error…
bkchr Aug 27, 2019
e48d2b5
Rename `InvalidIndex` to `CannotLookup`
bkchr Aug 27, 2019
1f16b00
Remove weird generic parameters
bkchr Aug 27, 2019
ed0761c
Rename function again
bkchr Aug 27, 2019
c0496ec
Merge remote-tracking branch 'origin/master' into bkchr-runtime-error…
bkchr Aug 27, 2019
20c6706
Fix import
bkchr Aug 27, 2019
28bbc86
Document the signed extension
bkchr Aug 27, 2019
92cec3c
Change from `Into` to `From`
bkchr Aug 27, 2019
442db38
Update srml/contracts/src/lib.rs
bkchr Aug 28, 2019
e48e66f
Merge remote-tracking branch 'origin/master' into bkchr-runtime-error…
bkchr Aug 30, 2019
257684e
Fix compilation
bkchr Aug 30, 2019
1470875
Update srml/contracts/src/lib.rs
bkchr Aug 30, 2019
23d5a93
Update core/sr-primitives/src/transaction_validity.rs
bkchr Aug 30, 2019
39d9d47
Remove unused code
bkchr Aug 30, 2019
7990a97
Fix compilation
bkchr Aug 30, 2019
7ecba8d
Some cleanups
bkchr Aug 30, 2019
448f4da
Merge remote-tracking branch 'origin/master' into bkchr-runtime-error…
bkchr Sep 2, 2019
3d7abc0
Fix compile errors
bkchr Sep 2, 2019
f93f9d3
Make `TransactionValidity` a `Result`
bkchr Sep 2, 2019
91b0869
Apply suggestions from code review
bkchr Sep 2, 2019
86ef4eb
Beautify the code a little bit and fix test
bkchr Sep 2, 2019
354e05f
Make `CannotLookup` an inherent error declared by `decl_error!`
bkchr Sep 3, 2019
6743719
Adds some documentation
bkchr Sep 3, 2019
b9fc817
Make `ApplyOutcome` a result
bkchr Sep 3, 2019
d5dc034
Merge remote-tracking branch 'origin/master' into bkchr-runtime-error…
bkchr Sep 3, 2019
e1bd019
Up the spec_version
bkchr Sep 3, 2019
e0fa417
Apply suggestions from code review
bkchr Sep 4, 2019
c25ac83
Merge remote-tracking branch 'origin/master' into bkchr-runtime-error…
bkchr Sep 4, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more test fixes
  • Loading branch information
xlc committed Jun 21, 2019
commit 9d2dbbb63fe6a2f559c6de528f7e24f84d545d54
11 changes: 5 additions & 6 deletions srml/aura/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#![cfg(test)]

use primitives::{BuildStorage, traits::IdentityLookup, testing::{Header, UintAuthorityId}};
use srml_support::impl_outer_origin;
use srml_support::{impl_outer_origin, impl_outer_error};
use runtime_io;
use substrate_primitives::{H256, Blake2Hasher};
use crate::{Trait, Module, GenesisConfig};
Expand All @@ -28,15 +28,14 @@ impl_outer_origin!{
pub enum Origin for Test {}
}

impl_outer_error! {
pub enum Error for Runtime {}
}

// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct Test;

#[allow(non_camel_case_types)]
pub enum Error {
system(system::Error)
}

impl system::Trait for Test {
type Origin = Origin;
type Index = u64;
Expand Down
23 changes: 22 additions & 1 deletion srml/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
use rstd::prelude::*;
use rstd::{cmp, result, mem};
use parity_codec::{Codec, Encode, Decode};
use srml_support::{StorageValue, StorageMap, Parameter, decl_event, decl_storage, decl_module};
use srml_support::{StorageValue, StorageMap, Parameter, decl_event, decl_storage, decl_module, decl_error};
use srml_support::traits::{
UpdateBalanceOutcome, Currency, OnFreeBalanceZero, MakePayment, OnUnbalanced,
WithdrawReason, WithdrawReasons, LockIdentifier, LockableCurrency, ExistenceRequirement,
Expand All @@ -170,6 +170,8 @@ mod tests;

pub use self::imbalances::{PositiveImbalance, NegativeImbalance};

pub type DispatchResult<T, I> = srml_support::dispatch::DispatchResult<<T as Trait<I>>::Error>;

pub trait Subtrait<I: Instance = DefaultInstance>: system::Trait {
/// The balance of an account.
type Balance: Parameter + Member + SimpleArithmetic + Codec + Default + Copy +
Expand Down Expand Up @@ -211,6 +213,9 @@ pub trait Trait<I: Instance = DefaultInstance>: system::Trait {

/// The overarching event type.
type Event: From<Event<Self, I>> + Into<<Self as system::Trait>::Event>;

/// The overarching error type.
type Error: From<Error> + From<system::Error> + From<&'static str>;
}

impl<T: Trait<I>, I: Instance> Subtrait<I> for T {
Expand All @@ -233,6 +238,19 @@ decl_event!(
}
);

decl_error! {
pub enum Error {
}
}

impl From<Error> for &'static str {
fn from(err: Error) -> &'static str {
match err {
Error::Unknown(msg) => msg,
}
}
}

/// Struct to encode the vesting schedule of an individual account.
#[derive(Encode, Decode, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug))]
Expand Down Expand Up @@ -340,6 +358,8 @@ decl_storage! {

decl_module! {
pub struct Module<T: Trait<I>, I: Instance = DefaultInstance> for enum Call where origin: T::Origin {
type Error = <T as Trait<I>>::Error;

fn deposit_event<T, I>() = default;

/// Transfer some liquid free balance to another account.
Expand Down Expand Up @@ -707,6 +727,7 @@ impl<T: Subtrait<I>, I: Instance> Trait<I> for ElevatedTrait<T, I> {
type TransactionPayment = ();
type TransferPayment = ();
type DustRemoval = ();
type Error = &'static str;
}

impl<T: Trait<I>, I: Instance> Currency<T::AccountId> for Module<T, I>
Expand Down
9 changes: 8 additions & 1 deletion srml/balances/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ impl_outer_origin!{
pub enum Origin for Runtime {}
}

mod balances {
pub use crate::Error;
}

impl_outer_error! {
pub enum Error for Runtime {}
pub enum Error for Runtime {
balances,
}
}

// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
Expand All @@ -56,6 +62,7 @@ impl Trait for Runtime {
type TransactionPayment = ();
type DustRemoval = ();
type TransferPayment = ();
type Error = Error;
}

pub struct ExtBuilder {
Expand Down
13 changes: 8 additions & 5 deletions srml/balances/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ fn default_indexing_on_new_accounts_should_not_work2() {
// account 1 has 256 * 10 = 2560, account 5 is not exist, 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"
mock::Error::balances(Error::Unknown("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);
Expand Down Expand Up @@ -347,7 +347,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),
mock::Error::balances(Error::Unknown("balance too low to send value"))
);
});
}

Expand Down Expand Up @@ -475,7 +478,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"
mock::Error::balances(Error::Unknown("destination balance too high to receive value"))
);

assert_eq!(Balances::free_balance(&1), u64::max_value());
Expand Down Expand Up @@ -553,7 +556,7 @@ fn transfer_overflow_isnt_exploitable() {

assert_err!(
Balances::transfer(Some(1).into(), 5, evil_value),
"got overflow after adding a fee to value"
mock::Error::balances(Error::Unknown("got overflow after adding a fee to value"))
);
}
);
Expand Down Expand Up @@ -617,7 +620,7 @@ fn unvested_balance_should_not_transfer() {
assert_eq!(Balances::vesting_balance(&1), 90); // Account 1 has only 10 units vested at block 1
assert_noop!(
Balances::transfer(Some(1).into(), 2, 11),
"vesting balance too high to send value"
mock::Error::balances(Error::Unknown("vesting balance too high to send value"))
); // Account 1 cannot send more than vested amount
}
);
Expand Down
69 changes: 37 additions & 32 deletions srml/support/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,10 @@ macro_rules! decl_module {
};
(@normalize
$(#[$attr:meta])*
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident>
pub struct $mod_type:ident<
$trait_instance:ident:
$trait_name:ident$(<I>, $instance:ident: $instantiable:path $(= $module_default_instance:path)?)?
>
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
{ $( $deposit_event:tt )* }
{ $( $on_initialize:tt )* }
Expand All @@ -438,7 +441,9 @@ macro_rules! decl_module {
) => {
$crate::decl_module!(@normalize
$(#[$attr])*
pub struct $mod_type<$trait_instance: $trait_name>
pub struct $mod_type<
$trait_instance: $trait_name$(<I>, $instance: $instantiable $(= $module_default_instance)?)?
>
for enum $call_type where origin: $origin_type, system = $system
{ $( $deposit_event )* }
{ $( $on_initialize )* }
Expand All @@ -449,7 +454,7 @@ macro_rules! decl_module {
$($rest)*
);
};
// This puts the function statement into the [], decreasing `$rest` and moving toward finishing the parse.
// Add default Error if none supplied
(@normalize
$(#[$attr:meta])*
pub struct $mod_type:ident<
Expand All @@ -461,13 +466,8 @@ macro_rules! decl_module {
{ $( $on_initialize:tt )* }
{ $( $on_finalize:tt )* }
{ $( $offchain:tt )* }
{ $error_type:ty }
{ }
[ $($t:tt)* ]
$(#[doc = $doc_attr:tt])*
#[weight = $weight:expr]
$fn_vis:vis fn $fn_name:ident(
$origin:ident $(, $(#[$codec_attr:ident])* $param_name:ident : $param:ty)*
) $( -> $result:ty )* { $( $impl:tt )* }
$($rest:tt)*
) => {
$crate::decl_module!(@normalize
Expand All @@ -480,20 +480,12 @@ macro_rules! decl_module {
{ $( $on_initialize )* }
{ $( $on_finalize )* }
{ $( $offchain )* }
{ $error_type }
[
$($t)*
$(#[doc = $doc_attr])*
#[weight = $weight]
$fn_vis fn $fn_name(
$origin $( , $(#[$codec_attr])* $param_name : $param )*
) $( -> $result )* { $( $impl )* }
{ $($instance: $instantiable)? }
]
{ &'static str }
[ $($t)* ]
$($rest)*
);
};
// Add #[weight] if none is defined.
// This puts the function statement into the [], decreasing `$rest` and moving toward finishing the parse.
(@normalize
$(#[$attr:meta])*
pub struct $mod_type:ident<
Expand All @@ -505,11 +497,12 @@ macro_rules! decl_module {
{ $( $on_initialize:tt )* }
{ $( $on_finalize:tt )* }
{ $( $offchain:tt )* }
{ $( $error_type:tt )* }
{ $error_type:ty }
[ $($t:tt)* ]
$(#[doc = $doc_attr:tt])*
#[weight = $weight:expr]
$fn_vis:vis fn $fn_name:ident(
$from:ident $(, $(#[$codec_attr:ident])* $param_name:ident : $param:ty)*
$origin:ident $(, $(#[$codec_attr:ident])* $param_name:ident : $param:ty)*
) $( -> $result:ty )* { $( $impl:tt )* }
$($rest:tt)*
) => {
Expand All @@ -523,17 +516,20 @@ macro_rules! decl_module {
{ $( $on_initialize )* }
{ $( $on_finalize )* }
{ $( $offchain )* }
{ $( $error_type )* }
[ $($t)* ]
$(#[doc = $doc_attr])*
#[weight = $crate::dispatch::TransactionWeight::default()]
$fn_vis fn $fn_name(
$from $(, $(#[$codec_attr])* $param_name : $param )*
) $( -> $result )* { $( $impl )* }
{ $error_type }
[
$($t)*
$(#[doc = $doc_attr])*
#[weight = $weight]
$fn_vis fn $fn_name(
$origin $( , $(#[$codec_attr])* $param_name : $param )*
) $( -> $result )* { $( $impl )* }
{ $($instance: $instantiable)? }
]
$($rest)*
);
};
// Add default Error if none supplied
// Add #[weight] if none is defined.
(@normalize
$(#[$attr:meta])*
pub struct $mod_type:ident<
Expand All @@ -545,8 +541,12 @@ macro_rules! decl_module {
{ $( $on_initialize:tt )* }
{ $( $on_finalize:tt )* }
{ $( $offchain:tt )* }
{ }
{ $( $error_type:tt )* }
[ $($t:tt)* ]
$(#[doc = $doc_attr:tt])*
$fn_vis:vis fn $fn_name:ident(
$from:ident $(, $(#[$codec_attr:ident])* $param_name:ident : $param:ty)*
) $( -> $result:ty )* { $( $impl:tt )* }
$($rest:tt)*
) => {
$crate::decl_module!(@normalize
Expand All @@ -559,8 +559,13 @@ macro_rules! decl_module {
{ $( $on_initialize )* }
{ $( $on_finalize )* }
{ $( $offchain )* }
{ &'static str }
{ $( $error_type )* }
[ $($t)* ]
$(#[doc = $doc_attr])*
#[weight = $crate::dispatch::TransactionWeight::default()]
$fn_vis fn $fn_name(
$from $(, $(#[$codec_attr])* $param_name : $param )*
) $( -> $result )* { $( $impl )* }
$($rest)*
);
};
Expand Down
19 changes: 10 additions & 9 deletions srml/support/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ macro_rules! impl_outer_error {
impl Into<$crate::runtime_primitives::DispatchError> for $name {
fn into(self) -> $crate::runtime_primitives::DispatchError {
match self {
$name::system(err) => match err {
$name::system(ref err) => match err {
$system::Error::Unknown(msg) =>
$crate::runtime_primitives::DispatchError {
module: 0,
Expand All @@ -110,15 +110,15 @@ macro_rules! impl_outer_error {
},
},
$(
$name::$module(err) => match err {
$name::$module(ref err) => match err {
$module::Error::Unknown(msg) =>
$crate::runtime_primitives::DispatchError {
module: $crate::codec::Encode.using_encoded(&self, |s| s[0]),
module: $crate::codec::Encode::using_encoded(&self, |s| s[0]),
error: 0,
message: Some(msg),
},
_ => $crate::runtime_primitives::DispatchError {
module: $crate::codec::Encode.using_encoded(&self, |s| s[0]),
module: $crate::codec::Encode::using_encoded(&self, |s| s[0]),
error: Into::<u8>::into(err),
message: None,
},
Expand All @@ -130,7 +130,7 @@ macro_rules! impl_outer_error {

$(
impl From<$module::Error> for $name {
fn from(err: $system::Error) -> Self {
fn from(err: $module::Error) -> Self {
$name::$module(err)
}
}
Expand Down Expand Up @@ -174,11 +174,12 @@ macro_rules! decl_error {
impl From<Error> for () {
fn from(_: Error) -> () { () }
}
impl Into<u8> for Error {
fn into(self) -> u8 {
match self {

impl From<&Error> for u8 {
fn from(err: &Error) -> u8 {
match err {
Error::Unknown(_) => 0,
_ => $crate::codec::Encode::using_encoded(&self, |s| s[0]),
_ => $crate::codec::Encode::using_encoded(err, |s| s[0]),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion srml/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ pub type KeyValue = (Vec<u8>, Vec<u8>);

decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
type Error = Error;
type Error = T::Error;

/// Deposits an event into this block's event record.
pub fn deposit_event(event: T::Event) {
Expand Down