Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 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
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
Merge remote-tracking branch 'upstream/master' into improve-error-res…
…ponse
  • Loading branch information
xlc committed Jul 10, 2019
commit 57f79583dfba1e847e2649d4a9d13b8a16bb25d0
5 changes: 4 additions & 1 deletion core/sr-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ pub mod transaction_validity;
/// Re-export these since they're only "kind of" generic.
pub use generic::{DigestItem, Digest};

/// Re-export this since it's part of the API of this crate.
pub use substrate_primitives::crypto::{key_types, KeyTypeId};

#[cfg_attr(test, derive(PartialEq, Debug))]
/// Primitive Error type
pub enum PrimitiveError {
Expand All @@ -59,7 +62,7 @@ pub enum PrimitiveError {
Other(&'static str),
/// Indicating an invalid signature in extrinsic.
BadSignature,
/// Full block error.
/// Full block error message.
///
/// This allows modules to indicate that given transaction is potentially valid
/// in the future, but can't be executed in the current state.
Expand Down
2 changes: 2 additions & 0 deletions node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ impl system::Trait for Runtime {
type Origin = Origin;
/// The ubiquitous error type.
type Error = Error;
/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
type BlockHashCount = BlockHashCount;
}

impl aura::Trait for Runtime {
Expand Down
3 changes: 2 additions & 1 deletion node-template/runtime/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ mod tests {

use runtime_io::with_externalities;
use primitives::{H256, Blake2Hasher};
use support::{{impl_outer_origin, impl_outer_error}, assert_ok};
use support::{impl_outer_origin, impl_outer_error, assert_ok, parameter_types};
use runtime_primitives::{traits::{BlakeTwo256, IdentityLookup}, testing::Header};

impl_outer_origin! {
Expand Down Expand Up @@ -101,6 +101,7 @@ mod tests {
type Header = Header;
type Event = ();
type Error = Error;
type BlockHashCount = BlockHashCount;
}
impl Trait for Test {
type Event = ();
Expand Down
5 changes: 3 additions & 2 deletions node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// and set impl_version to equal spec_version. If only runtime
// implementation changes and behavior does not, then leave spec_version as
// is and increment impl_version.
spec_version: 105,
impl_version: 105,
spec_version: 108,
impl_version: 108,
apis: RUNTIME_API_VERSIONS,
};

Expand Down Expand Up @@ -126,6 +126,7 @@ impl system::Trait for Runtime {
type Header = generic::Header<BlockNumber, BlakeTwo256>;
type Event = Event;
type Error = Error;
type BlockHashCount = BlockHashCount;
}

impl aura::Trait for Runtime {
Expand Down
3 changes: 2 additions & 1 deletion srml/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ mod tests {
use super::*;

use runtime_io::with_externalities;
use srml_support::{impl_outer_origin, impl_outer_error, assert_ok, assert_noop};
use srml_support::{impl_outer_origin, impl_outer_error, assert_ok, assert_noop, parameter_types};
use substrate_primitives::{H256, Blake2Hasher};
// The testing primitives are very useful for avoiding having to work with signatures
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are required.
Expand Down Expand Up @@ -273,6 +273,7 @@ mod tests {
type Header = Header;
type Event = ();
type Error = Error;
type BlockHashCount = BlockHashCount;
}
impl Trait for Test {
type Event = ();
Expand Down
9 changes: 7 additions & 2 deletions srml/aura/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@

#![cfg(test)]

use primitives::{traits::IdentityLookup, testing::{Header, UintAuthorityId}};
use srml_support::{impl_outer_origin, impl_outer_error};
use primitives::{
KeyTypeId,
traits::IdentityLookup,
testing::{UINT_DUMMY_KEY, Header, UintAuthorityId},
};
use srml_support::{impl_outer_origin, impl_outer_error, parameter_types};
use runtime_io;
use substrate_primitives::{H256, Blake2Hasher};
use crate::{Trait, Module, GenesisConfig};
Expand Down Expand Up @@ -51,6 +55,7 @@ impl system::Trait for Test {
type Header = Header;
type Event = ();
type Error = Error;
type BlockHashCount = BlockHashCount;
}

impl timestamp::Trait for Test {
Expand Down
1 change: 1 addition & 0 deletions srml/authorship/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ mod tests {
type Header = Header;
type Event = ();
type Error = Error;
type BlockHashCount = BlockHashCount;
}

impl Trait for Test {
Expand Down
1 change: 1 addition & 0 deletions srml/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ impl<T: Subtrait<I>, I: Instance> system::Trait for ElevatedTrait<T, I> {
type Header = T::Header;
type Event = ();
type Error = &'static str;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not T::Error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting this error with T::Error and I can't resolve it. Does the current approach have any issues?

Checking srml-balances v2.0.0 (/Users/bryanchen/projects/cennznet/substrate/srml/balances)
error[E0277]: the trait bound `<T as srml_system::Trait>::Error: std::convert::From<Error>` is not satisfied
   --> srml/balances/src/lib.rs:722:35
    |
722 | impl<T: Subtrait<I>, I: Instance> Trait<I> for ElevatedTrait<T, I> {
    |                                   ^^^^^^^^ the trait `std::convert::From<Error>` is not implemented for `<T as srml_system::Trait>::Error`
    |
    = help: consider adding a `where <T as srml_system::Trait>::Error: std::convert::From<Error>` bound

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect it'd need to be converted simultaneously with the instance below...

type BlockHashCount = T::BlockHashCount;
}
impl<T: Subtrait<I>, I: Instance> Trait<I> for ElevatedTrait<T, I> {
type Balance = T::Balance;
Expand Down
3 changes: 2 additions & 1 deletion srml/balances/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use primitives::{traits::{IdentityLookup}, testing::Header};
use substrate_primitives::{H256, Blake2Hasher};
use runtime_io;
use srml_support::{impl_outer_origin, impl_outer_error, traits::Get};
use srml_support::{impl_outer_origin, impl_outer_error, parameter_types, traits::Get};
use std::cell::RefCell;
use crate::{GenesisConfig, Module, Trait};

Expand Down Expand Up @@ -89,6 +89,7 @@ impl system::Trait for Runtime {
type Header = Header;
type Event = ();
type Error = Error;
type BlockHashCount = BlockHashCount;
}
impl Trait for Runtime {
type Balance = u64;
Expand Down
1 change: 1 addition & 0 deletions srml/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ impl system::Trait for Test {
type Header = Header;
type Event = MetaEvent;
type Error = Error;
type BlockHashCount = BlockHashCount;
}
parameter_types! {
pub const BalancesTransactionBaseFee: u64 = 0;
Expand Down
1 change: 1 addition & 0 deletions srml/council/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ mod tests {
type Header = Header;
type Event = Event;
type Error = Error;
type BlockHashCount = BlockHashCount;
}
parameter_types! {
pub const ExistentialDeposit: u64 = 0;
Expand Down
1 change: 1 addition & 0 deletions srml/democracy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,7 @@ mod tests {
type Header = Header;
type Event = ();
type Error = Error;
type BlockHashCount = BlockHashCount;
}
parameter_types! {
pub const ExistentialDeposit: u64 = 0;
Expand Down
1 change: 1 addition & 0 deletions srml/example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ mod tests {
type Header = Header;
type Event = ();
type Error = Error;
type BlockHashCount = BlockHashCount;
}
parameter_types! {
pub const ExistentialDeposit: u64 = 0;
Expand Down
1 change: 1 addition & 0 deletions srml/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ mod tests {
type Header = Header;
type Event = MetaEvent;
type Error = Error;
type BlockHashCount = BlockHashCount;
}
parameter_types! {
pub const ExistentialDeposit: u64 = 0;
Expand Down
1 change: 1 addition & 0 deletions srml/finality-tracker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ mod tests {
type Header = Header;
type Event = ();
type Error = Error;
type BlockHashCount = BlockHashCount;
}
parameter_types! {
pub const WindowSize: u64 = 11;
Expand Down
13 changes: 7 additions & 6 deletions srml/grandpa/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use primitives::{DigestItem, traits::IdentityLookup, testing::{Header, UintAuthorityId}};
use runtime_io;
use srml_support::{impl_outer_origin, impl_outer_error, impl_outer_event};
use srml_support::{impl_outer_origin, impl_outer_event, impl_outer_error, parameter_types};
use substrate_primitives::{H256, Blake2Hasher};
use parity_codec::{Encode, Decode};
use crate::{AuthorityId, GenesisConfig, Trait, Module, ConsensusLog};
Expand All @@ -34,10 +34,8 @@ impl_outer_error! {
pub enum Error for Test {}
}

impl From<Signal<u64>> for DigestItem<H256> {
fn from(log: Signal<u64>) -> DigestItem<H256> {
DigestItem::Consensus(GRANDPA_ENGINE_ID, log.encode())
}
pub fn grandpa_log(log: ConsensusLog<u64>) -> DigestItem<H256> {
DigestItem::Consensus(GRANDPA_ENGINE_ID, log.encode())
}

// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
Expand All @@ -47,7 +45,9 @@ pub struct Test;
impl Trait for Test {
type Event = TestEvent;
}

parameter_types! {
pub const BlockHashCount: u64 = 250;
}
impl system::Trait for Test {
type Origin = Origin;
type Index = u64;
Expand All @@ -59,6 +59,7 @@ impl system::Trait for Test {
type Header = Header;
type Event = TestEvent;
type Error = Error;
type BlockHashCount = BlockHashCount;
}

mod grandpa {
Expand Down
3 changes: 2 additions & 1 deletion srml/indices/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::collections::HashSet;
use ref_thread_local::{ref_thread_local, RefThreadLocal};
use primitives::testing::Header;
use substrate_primitives::{H256, Blake2Hasher};
use srml_support::{impl_outer_origin, impl_outer_error};
use srml_support::{impl_outer_origin, impl_outer_error, parameter_types};
use {runtime_io, system};
use crate::{GenesisConfig, Module, Trait, IsDeadAccount, OnNewAccount, ResolveHint};

Expand Down Expand Up @@ -82,6 +82,7 @@ impl system::Trait for Runtime {
type Header = Header;
type Event = ();
type Error = Error;
type BlockHashCount = BlockHashCount;
}
impl Trait for Runtime {
type AccountIndex = u64;
Expand Down
97 changes: 1 addition & 96 deletions srml/session/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,7 @@ impl<T: Trait, Inner: FindAuthor<u32>> FindAuthor<T::ValidatorId>
#[cfg(test)]
mod tests {
use super::*;
use std::cell::RefCell;
use srml_support::{impl_outer_origin, impl_outer_error, assert_ok};
use srml_support::assert_ok;
use runtime_io::with_externalities;
use substrate_primitives::Blake2Hasher;
use primitives::{
Expand All @@ -563,100 +562,6 @@ mod tests {
set_next_validators, set_session_length, session_changed, Test, Origin, System, Session,
};

impl_outer_origin!{
pub enum Origin for Test {}
}

impl_outer_error! {
pub enum Error for Test {}
}

thread_local!{
static NEXT_VALIDATORS: RefCell<Vec<u64>> = RefCell::new(vec![1, 2, 3]);
static AUTHORITIES: RefCell<Vec<UintAuthorityId>> =
RefCell::new(vec![UintAuthorityId(1), UintAuthorityId(2), UintAuthorityId(3)]);
static FORCE_SESSION_END: RefCell<bool> = RefCell::new(false);
static SESSION_LENGTH: RefCell<u64> = RefCell::new(2);
static SESSION_CHANGED: RefCell<bool> = RefCell::new(false);
static TEST_SESSION_CHANGED: RefCell<bool> = RefCell::new(false);
}

pub struct TestShouldEndSession;
impl ShouldEndSession<u64> for TestShouldEndSession {
fn should_end_session(now: u64) -> bool {
let l = SESSION_LENGTH.with(|l| *l.borrow());
now % l == 0 || FORCE_SESSION_END.with(|l| { let r = *l.borrow(); *l.borrow_mut() = false; r })
}
}

pub struct TestSessionHandler;
impl SessionHandler<u64> for TestSessionHandler {
fn on_new_session<T: OpaqueKeys>(changed: bool, validators: &[(u64, T)]) {
SESSION_CHANGED.with(|l| *l.borrow_mut() = changed);
AUTHORITIES.with(|l|
*l.borrow_mut() = validators.iter().map(|(_, id)| id.get::<UintAuthorityId>(0).unwrap_or_default()).collect()
);
}
fn on_disabled(_validator_index: usize) {}
}

pub struct TestOnSessionEnding;
impl OnSessionEnding<u64> for TestOnSessionEnding {
fn on_session_ending(_: SessionIndex) -> Option<Vec<u64>> {
if !TEST_SESSION_CHANGED.with(|l| *l.borrow()) {
Some(NEXT_VALIDATORS.with(|l| l.borrow().clone()))
} else {
None
}
}
}

fn authorities() -> Vec<UintAuthorityId> {
AUTHORITIES.with(|l| l.borrow().to_vec())
}

fn force_new_session() {
FORCE_SESSION_END.with(|l| *l.borrow_mut() = true )
}

fn set_session_length(x: u64) {
SESSION_LENGTH.with(|l| *l.borrow_mut() = x )
}

fn session_changed() -> bool {
SESSION_CHANGED.with(|l| *l.borrow())
}

#[derive(Clone, Eq, PartialEq)]
pub struct Test;
impl system::Trait for Test {
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = ();
type Error = Error;
}
impl timestamp::Trait for Test {
type Moment = u64;
type OnTimestampSet = ();
}
impl Trait for Test {
type ShouldEndSession = TestShouldEndSession;
type OnSessionEnding = TestOnSessionEnding;
type SessionHandler = TestSessionHandler;
type Keys = UintAuthorityId;
type Event = ();
type SelectInitialValidators = ();
}

type System = system::Module<Test>;
type Session = Module<Test>;

fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
let mut t = system::GenesisConfig::default().build_storage::<Test>().unwrap();
timestamp::GenesisConfig::<Test> {
Expand Down
7 changes: 6 additions & 1 deletion srml/session/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use super::*;
use std::cell::RefCell;
use srml_support::{impl_outer_origin, parameter_types};
use srml_support::{impl_outer_origin, impl_outer_error, parameter_types};
use substrate_primitives::H256;
use primitives::{
traits::{BlakeTwo256, IdentityLookup, ConvertInto},
Expand All @@ -30,6 +30,10 @@ impl_outer_origin! {
pub enum Origin for Test {}
}

impl_outer_error! {
pub enum Error for Test {}
}

thread_local! {
pub static NEXT_VALIDATORS: RefCell<Vec<u64>> = RefCell::new(vec![1, 2, 3]);
pub static AUTHORITIES: RefCell<Vec<UintAuthorityId>> =
Expand Down Expand Up @@ -120,6 +124,7 @@ impl system::Trait for Test {
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = ();
type Error = Error;
type BlockHashCount = BlockHashCount;
}
impl timestamp::Trait for Test {
Expand Down
1 change: 1 addition & 0 deletions srml/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl system::Trait for Test {
type Header = Header;
type Event = ();
type Error = Error;
type BlockHashCount = BlockHashCount;
}
parameter_types! {
pub const TransferFee: u64 = 0;
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.