Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staking support #99

Merged
merged 110 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from 93 commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
6bdf5e8
Initial Staking API
Demi-Marie Apr 30, 2020
10667e3
Merge branch 'master' of github.com:paritytech/substrate-subxt
Demi-Marie Apr 30, 2020
d4a085a
Add more staking types
Demi-Marie May 1, 2020
c08e22a
Reformat
Demi-Marie May 1, 2020
93c347c
Remove dead code
Demi-Marie May 1, 2020
fef1260
Fix missing documentation
Demi-Marie May 1, 2020
3d6e2ee
Reformat
Demi-Marie May 5, 2020
c0b1904
Merge branch 'master' into staking
Demi-Marie May 5, 2020
8721237
Merge branch 'master' into staking
Demi-Marie May 14, 2020
a28fb20
Staking: use proc macros
Demi-Marie May 15, 2020
cfabfe8
Add partial session support
Demi-Marie May 15, 2020
ff967e9
Reformat
Demi-Marie May 15, 2020
716dd13
Try to implement nomination
Demi-Marie May 17, 2020
88ac3cb
Use the #[module] macro
Demi-Marie May 17, 2020
122260f
Explain undefined method diagnostics
Demi-Marie May 17, 2020
ffbffd4
Use ‘#[module]’ and implement session for Kusama
Demi-Marie May 17, 2020
1b4dc07
Don’t impl ‘Staking’ for all ‘T: System’
Demi-Marie May 17, 2020
ebfdc17
Add staking payout support
Demi-Marie May 17, 2020
aaf190e
Fix compilation errors and remove useless lifetimes
Demi-Marie May 18, 2020
5ff1b17
Merge branch 'master' into staking
Demi-Marie May 24, 2020
58da217
Merge branch 'master' into staking
Demi-Marie May 27, 2020
ab9612b
Respond to code review
Demi-Marie May 27, 2020
193104c
Make signing fallable and asynchronous
Demi-Marie May 28, 2020
7868f2c
Merge branch 'async-signer' into staking
Demi-Marie May 28, 2020
c4942c4
Reformat
Demi-Marie May 28, 2020
c6ade8b
Refactor as suggested by Andrew Jones (@ascjones).
Demi-Marie May 28, 2020
36b124d
Reformat
Demi-Marie May 28, 2020
bc19991
Refactor as suggested by Andrew Jones (@ascjones).
Demi-Marie May 28, 2020
9fd2949
Merge branch 'async-signer' into staking
Demi-Marie May 28, 2020
e3e30cf
Trait cleanups
Demi-Marie May 29, 2020
ba4f90c
Merge branch 'master' into staking
Demi-Marie May 29, 2020
06aa7e2
Make the `Signer` impl require Send + Sync
Demi-Marie May 29, 2020
49b3b1e
Use the correct key for staking maps
Demi-Marie May 31, 2020
3314ea1
Implement set_payee call
Demi-Marie May 31, 2020
57e2390
Switch to associated types for Staking
Demi-Marie Jun 3, 2020
067c6f9
Implement `set_keys`
Demi-Marie Jun 3, 2020
83c6c61
Remove impl of Signer for Box<dyn Signer + Send + Sync>
Demi-Marie Jun 4, 2020
5bdeee4
Merge branch 'master' into staking
Demi-Marie Jun 7, 2020
7587469
Merge branch 'master' into staking
Demi-Marie Jun 8, 2020
06bc4ab
Fix Polkadot and Kusama ‘SessionKey’ structs
Demi-Marie Jun 9, 2020
6ccfc9c
Include a copy of `ValidatorId`
Demi-Marie Jun 9, 2020
d4d7b1d
Merge branch 'master' into staking
Demi-Marie Jun 16, 2020
c63b74c
Fix syntax error in Cargo.toml
Demi-Marie Jun 16, 2020
4d8ccab
Fix compile errors
Demi-Marie Jun 16, 2020
90e3b9b
Add Debug impls
Demi-Marie Jun 18, 2020
2bea59f
Fix return type of `BondedStore`
Demi-Marie Jun 18, 2020
a95fd8a
Use some upstream type definitions
Demi-Marie Jun 19, 2020
f15c5f6
Merge branch 'master' into staking
Demi-Marie Jun 25, 2020
d3df9ea
Bump deps and fix build
Demi-Marie Jun 26, 2020
ff8e37f
Remove last reference to Kusama feature
Demi-Marie Jun 30, 2020
fe20eb5
Merge remote-tracking branch 'origin/master' into staking
Demi-Marie Jul 8, 2020
e80ddd4
Merge branch 'master' into staking
Demi-Marie Jul 8, 2020
94ce5ce
Merge branch 'master' into staking
Demi-Marie Jul 18, 2020
ae676c9
Merge branch 'master' into staking
DemiMarie Aug 5, 2020
e829a46
Merge branch 'master' into staking
DemiMarie Aug 5, 2020
6bf960f
Fix compilation errors
DemiMarie Aug 8, 2020
528b218
Implement the `concat` in `twox_64_concat`
DemiMarie Aug 8, 2020
7bad6c6
Merge branch 'master' into staking
DemiMarie Aug 10, 2020
da36675
Expose properties and per-era preferences
DemiMarie Aug 12, 2020
d5b1138
Era rewards point support
DemiMarie Aug 12, 2020
28533f6
Expose clipped exposure
DemiMarie Aug 12, 2020
c330e68
Era reward points support
DemiMarie Aug 13, 2020
59decaf
Make `PayoutStakersCall` public
DemiMarie Aug 17, 2020
93fafcd
Merge remote-tracking branch 'origin/master' into staking
DemiMarie Aug 24, 2020
8bcde31
Merge branch 'master' into staking
DemiMarie Aug 28, 2020
b03b28b
Add in all default features for debugging
DemiMarie Aug 28, 2020
2744127
Chill support and update to latest Substrate
DemiMarie Aug 31, 2020
3efe16f
If property fetch fails, use dummy values
DemiMarie Sep 6, 2020
dd15f22
Merge branch 'master' into staking
DemiMarie Sep 9, 2020
773d43e
Merge branch 'master' into staking
dvdplm Sep 11, 2020
d3865a6
Fix tests
DemiMarie Sep 11, 2020
0084f87
Fix header
DemiMarie Sep 11, 2020
33f1710
Remove some code Ledgeracio does not need
DemiMarie Sep 11, 2020
9f34f76
More deletions
DemiMarie Sep 11, 2020
1df5a64
Remove more code not needed for Ledgeracio
DemiMarie Sep 12, 2020
c622641
Remove a pointless change in Cargo.toml
DemiMarie Sep 12, 2020
b253a7a
Remove more junk
DemiMarie Sep 12, 2020
1394bb9
Merge branch 'staking' of github.com:paritytech/substrate-subxt into …
dvdplm Sep 14, 2020
9a86802
Revert contracts put_code test to pure code (not using the macro)
ascjones Sep 14, 2020
0e7bc2d
Test contract instantiate
ascjones Sep 14, 2020
92bcd26
Fmt
ascjones Sep 14, 2020
95c8900
Merge remote-tracking branch 'origin/aj-contract-test' into staking
DemiMarie Sep 14, 2020
b3687af
Merge branch 'staking' of github.com:paritytech/substrate-subxt into …
dvdplm Sep 15, 2020
3020f32
Merge branch 'master' into staking
DemiMarie Sep 15, 2020
303c5f4
WIP
dvdplm Sep 15, 2020
2e74c1e
Merge branch 'master' into dp-testing-stasking-playground
DemiMarie Sep 15, 2020
f0a5f61
Add some more submission tests
DemiMarie Sep 15, 2020
e0b41af
Merge branch 'dp-testing-stasking-playground' into staking
DemiMarie Sep 15, 2020
0516987
Reformat
DemiMarie Sep 15, 2020
dffbba6
More tests
DemiMarie Sep 16, 2020
0860bad
Cleanup
dvdplm Sep 16, 2020
ec96a42
Hopefully fix CI
DemiMarie Sep 16, 2020
01869a7
Remove dead code
DemiMarie Sep 16, 2020
b54b1b9
Test chill
DemiMarie Sep 17, 2020
68ff645
Add missing docs
DemiMarie Sep 17, 2020
9c6c663
Merge remote-tracking branch 'origin/master' into staking
DemiMarie Sep 17, 2020
bc8bc36
Remove unnecessary use
DemiMarie Sep 17, 2020
dd4dce9
Revert "Remove unnecessary use"
DemiMarie Sep 17, 2020
1eb67d9
Retry on temporary failures
DemiMarie Sep 17, 2020
d63661f
Ignore the staking tests on CI
DemiMarie Sep 17, 2020
369cb88
Add separate tests for nomination, validation announcment and chilling
dvdplm Sep 18, 2020
24848b3
Obey the fmt
dvdplm Sep 18, 2020
e2862d8
Run CI with at most one test thread
DemiMarie Sep 18, 2020
8a79571
Implement tests for staking
DemiMarie Sep 19, 2020
f3da309
More tests
DemiMarie Sep 20, 2020
18e8029
Remove unhelpful println!
DemiMarie Sep 20, 2020
f7cda4a
Revert changes in contract tests
DemiMarie Sep 20, 2020
15c0206
Reformat
DemiMarie Sep 20, 2020
d659e91
Remove spurious diff
DemiMarie Sep 20, 2020
52960b7
More tests
DemiMarie Sep 21, 2020
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
12 changes: 11 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ keywords = ["parity", "substrate", "blockchain"]
include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]

[features]
kusama = []
default = ["kusama"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is kusama the default feature?

client = ["substrate-subxt-client"]

# enable this feature to run tests which require a local dev chain node
Expand All @@ -31,14 +33,22 @@ num-traits = { version = "0.2.12", default-features = false }
serde = { version = "1.0.115", features = ["derive"] }
serde_json = "1.0.57"
url = "2.1.1"
codec = { package = "parity-scale-codec", version = "1.3.4", default-features = false, features = ["derive", "full"] }
codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive", "full"] }

frame-metadata = { version = "11.0.0-rc6", package = "frame-metadata" }
frame-support = { version = "2.0.0-rc6", package = "frame-support" }
sp-runtime = { version = "2.0.0-rc6", package = "sp-runtime" }
sp-version = { version = "2.0.0-rc6", package = "sp-version" }
pallet-indices = { version = "2.0.0-rc6", package = "pallet-indices" }
hex = "0.4.2"
sp-std = "2.0.0-rc6"
application-crypto = { version = "2.0.0-rc6", package = "sp-application-crypto" }
sp-finality-grandpa = "2.0.0-rc6"
sp-consensus-babe = "0.8.0-rc6"
pallet-im-online = "2.0.0-rc6"
sp-authority-discovery = "2.0.0-rc6"
pallet-staking = "2.0.0-rc6"

sp-rpc = { version = "2.0.0-rc6", package = "sp-rpc" }
sp-core = { version = "2.0.0-rc6", package = "sp-core" }
sc-rpc-api = { version = "0.8.0-rc6", package = "sc-rpc-api" }
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ A library to **sub**mit e**xt**rinsics to a [substrate](https://github.com/parit

See [examples](./examples).

If you use `#[derive(Call)]` without `#[module]` in the same module, you will get errors
complaining about an undefined method with a name starting with `with_`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please open an issue for this, or provide some context here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It took me a long time to figure this out, so I added this for the benefit of others.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think this info – which I agree is useful – should move or be copied to the docs for module/Call macros?

Copy link
Contributor

Choose a reason for hiding this comment

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

I've raised an issue for it to improve the error message: #170. But probably we should remove from the readme since it doesn't make sense without any context.


**Alternatives**

[substrate-api-client](https://github.com/scs/substrate-api-client) provides similar functionality.
Expand Down
1 change: 1 addition & 0 deletions src/extrinsic/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub trait Signer<T: Runtime> {
}

/// Extrinsic signer using a private key.
#[derive(Debug)]
pub struct PairSigner<T: Runtime, P: Pair> {
account_id: T::AccountId,
nonce: Option<T::Index>,
Expand Down
2 changes: 2 additions & 0 deletions src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ use sp_core::storage::StorageKey;

pub mod balances;
pub mod contracts;
pub mod session;
pub mod staking;
pub mod sudo;
pub mod system;

Expand Down
75 changes: 75 additions & 0 deletions src/frame/session.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of substrate-subxt.
//
// subxt is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// subxt is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.

//! Session support
use crate::frame::system::{
System,
SystemEventsDecoder as _,
};
use codec::Encode;
use frame_support::Parameter;
use sp_runtime::traits::{
Member,
OpaqueKeys,
};
use std::{
fmt::Debug,
marker::PhantomData,
};
use substrate_subxt_proc_macro::Store;

/// Impls `Default::default` for some types that have a `_runtime` field of type
/// `PhantomData` as their only field.
macro_rules! default_impl {
($name:ident) => {
impl<T: Session> Default for $name<T> {
fn default() -> Self {
Self {
_runtime: PhantomData,
}
}
}
};
}

/// The trait needed for this module.
#[module]
pub trait Session: System {
/// The validator account identifier type for the runtime.
type ValidatorId: Parameter + Debug + Ord + Default + Send + Sync + 'static;

/// The keys.
type Keys: OpaqueKeys + Member + Parameter + Default;
}

/// The current set of validators.
#[derive(Encode, Store, Debug)]
pub struct ValidatorsStore<T: Session> {
#[store(returns = Vec<<T as Session>::ValidatorId>)]
/// Marker for the runtime
pub _runtime: PhantomData<T>,
}

default_impl!(ValidatorsStore);

/// Set the session keys for a validator.
#[derive(Encode, Call, Debug)]
pub struct SetKeysCall<T: Session> {
/// The keys
pub keys: T::Keys,
/// The proof. This is not currently used and can be set to an empty vector.
pub proof: Vec<u8>,
}
252 changes: 252 additions & 0 deletions src/frame/staking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of substrate-subxt.
//
// subxt is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// subxt is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.

//! Implements support for the pallet_staking module.

use super::balances::{
Balances,
BalancesEventsDecoder as _,
};
use codec::{
Decode,
Encode,
};

use std::{
collections::BTreeMap,
fmt::Debug,
marker::PhantomData,
};

pub use pallet_staking::{
ActiveEraInfo,
EraIndex,
Exposure,
Nominations,
RewardDestination,
RewardPoint,
StakingLedger,
ValidatorPrefs,
};

/// Rewards for the last `HISTORY_DEPTH` eras.
/// If reward hasn't been set or has been removed then 0 reward is returned.
#[derive(Clone, Encode, Decode, Debug, Store)]
pub struct ErasRewardPointsStore<T: Staking> {
#[store(returns = EraRewardPoints<T::AccountId>)]
/// Era index
pub index: EraIndex,
/// Marker for the runtime
pub _phantom: PhantomData<T>,
}

/// Preference of what happens regarding validation.
#[derive(Clone, Encode, Decode, Debug, Call)]
pub struct SetPayeeCall<T: Staking> {
/// The payee
pub payee: RewardDestination,
/// Marker for the runtime
pub _runtime: PhantomData<T>,
}

/// The subset of the `frame::Trait` that a client must implement.
#[module]
pub trait Staking: Balances {}

/// Number of eras to keep in history.
///
/// Information is kept for eras in `[current_era - history_depth; current_era]`.
///
/// Must be more than the number of eras delayed by session otherwise.
/// I.e. active era must always be in history.
/// I.e. `active_era > current_era - history_depth` must be guaranteed.
#[derive(Encode, Decode, Copy, Clone, Debug, Default, Store)]
pub struct HistoryDepthStore<T: Staking> {
#[store(returns = u32)]
/// Marker for the runtime
pub _runtime: PhantomData<T>,
}

/// Map from all locked "stash" accounts to the controller account.
#[derive(Encode, Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd, Store)]
pub struct BondedStore<T: Staking> {
#[store(returns = Option<T::AccountId>)]
/// Tٗhe stash account
pub stash: T::AccountId,
}

/// Map from all (unlocked) "controller" accounts to the info regarding the staking.
#[derive(Encode, Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd, Store)]
pub struct LedgerStore<T: Staking> {
#[store(returns = Option<StakingLedger<T::AccountId, T::Balance>>)]
/// The controller account
pub controller: T::AccountId,
}

/// Where the reward payment should be made. Keyed by stash.
#[derive(Encode, Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd, Store)]
pub struct PayeeStore<T: Staking> {
#[store(returns = RewardDestination)]
/// Tٗhe stash account
pub stash: T::AccountId,
}

/// The map from (wannabe) validator stash key to the preferences of that validator.
#[derive(Encode, Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd, Store)]
pub struct ValidatorsStore<T: Staking> {
#[store(returns = ValidatorPrefs)]
/// Tٗhe stash account
pub stash: T::AccountId,
}

/// The map from nominator stash key to the set of stash keys of all validators to nominate.
#[derive(Encode, Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Store)]
pub struct NominatorsStore<T: Staking> {
#[store(returns = Option<Nominations<T::AccountId>>)]
/// Tٗhe stash account
pub stash: T::AccountId,
}

/// The current era index.
///
/// This is the latest planned era, depending on how the Session pallet queues the validator
/// set, it might be active or not.
#[derive(Encode, Copy, Clone, Debug, Store)]
pub struct CurrentEraStore<T: Staking> {
#[store(returns = Option<EraIndex>)]
/// Marker for the runtime
pub _runtime: PhantomData<T>,
}

/// Reward points of an era. Used to split era total payout between validators.
///
/// This points will be used to reward validators and their respective nominators.
#[derive(PartialEq, Encode, Decode, Default, Debug)]
pub struct EraRewardPoints<AccountId: Ord> {
/// Total number of points. Equals the sum of reward points for each validator.
pub total: RewardPoint,
/// The reward points earned by a given validator.
pub individual: BTreeMap<AccountId, RewardPoint>,
}

/// Declare no desire to either validate or nominate.
///
/// Effective at the beginning of the next era.
///
/// The dispatch origin for this call must be _Signed_ by the controller, not the stash.
/// Can only be called when [`EraElectionStatus`] is `Closed`.
#[derive(Debug, Call, Encode)]
pub struct ChillCall<T: Staking> {
/// Runtime marker
pub _runtime: PhantomData<T>,
}

impl<T: Staking> Default for ChillCall<T> {
fn default() -> Self {
Self {
_runtime: PhantomData,
}
}
}
impl<T: Staking> Clone for ChillCall<T> {
fn clone(&self) -> Self {
Self {
_runtime: self._runtime,
}
}
}
impl<T: Staking> Copy for ChillCall<T> {}

/// Declare the desire to validate for the origin controller.
///
/// Effective at the beginning of the next era.
///
/// The dispatch origin for this call must be _Signed_ by the controller, not the stash.
/// Can only be called when [`EraElectionStatus`] is `Closed`.
#[derive(Clone, Debug, PartialEq, Call, Encode)]
pub struct ValidateCall<T: Staking> {
/// Runtime marker
pub _runtime: PhantomData<T>,
/// Validation preferences
pub prefs: ValidatorPrefs,
}

/// Declare the desire to nominate `targets` for the origin controller.
///
/// Effective at the beginning of the next era.
///
/// The dispatch origin for this call must be _Signed_ by the controller, not the stash.
/// Can only be called when [`EraElectionStatus`] is `Closed`.
#[derive(Call, Encode, Debug)]
pub struct NominateCall<T: Staking> {
/// The targets that are being nominated
pub targets: Vec<T::Address>,
}

#[cfg(all(test, feature = "integration-tests"))]
mod tests {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please clean up the tests before asking for a review. This is PoC-level stuff here. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

The integration-tests feature is necessary because the tests don’t work without a running Polkadot and/or Kusama node. I could have written

#[cfg(test)]
#[cfg(feature = "integration-tests")]

or added #[cfg(feature = "integration-tests")] on each test, but this is equivalent and shorter.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think he is referring to looking how it is handled already by other tests. Even better would be to add the staking module to the test runtime we use for tests

Copy link
Contributor

Choose a reason for hiding this comment

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

I tried adding the staking module, but it would up pulling in a huge portion of Kusama. I think we would be better off using an actual Kusama node instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason to use a feature gate instead of #[ignore]?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I also fixed the test suite to retry on temporary errors.

Copy link
Contributor

@dvdplm dvdplm Sep 18, 2020

Choose a reason for hiding this comment

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

No I was referring to the test code itself: it contains a bunch of my lame attempts at figuring out how to test this. It's not something we want to actually review. :/

I think @ascjones added the integration-tests feature as a way to (eventually) run these tests in CI. There's a problem though: the contracts tests he added in #163 assumes the "remote" node has the contracts pallet, which is true for a substrate node, but isn't for polkadot/kusama. This means cargo test --feature integration-tests will pass or fail tests depending on which flavour of node you're running. :/

@demi the retry thing doesn't actually work for me. If you use _and_watch() and check on what the outcome actually is you'll see that it's not ok.

EDIT: I think the problem is that if you run a single node the chain isn't progressing so when we submit several extrinsics they end up failing in random order with "Extrinsic Usurped" or "Priority is too low: (1155024648500 vs 1155024648500)".

Edit-2: the contracts tests are run with the test-node but they keep failing for me so I must be doing something wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

EDIT: I think the problem is that if you run a single node the chain isn't progressing so when we submit several extrinsics they end up failing in random order with "Extrinsic Usurped" or "Priority is too low: (1155024648500 vs 1155024648500)"

Yeah usually that is probably because the nonce needs incrementing. I came up with a rudimentary solution here which appears to work consistently: https://github.com/paritytech/substrate-subxt/blob/aj-contract-call/src/frame/contracts.rs#L175

I tried adding the staking module, but it would up pulling in a huge portion of Kusama. I think we would be better off using an actual Kusama node instead.

I agree. I assume these tests would work against node-runtime too? If so then #169 might be a solution.

That said for this PR I am happy for the tests to be run manually against a local node of whatever flavour.

use super::*;
use crate::{
extrinsic::PairSigner,
runtimes::KusamaRuntime as RT,
ClientBuilder,
};
// use sp_core::{sr25519::Pair, Pair as _};
use crate::{
extrinsic::Signer,
frame::{
balances::*,
system::*,
},
};
use sp_keyring::AccountKeyring;

#[async_std::test]
async fn test_nominate() {
env_logger::try_init().ok();
let alice = PairSigner::<RT, _>::new(AccountKeyring::Alice.pair());
let bob = PairSigner::<RT, _>::new(AccountKeyring::Bob.pair());

let client = ClientBuilder::<RT>::new().build().await.unwrap();
let current_era = client.current_era(None).await.unwrap();
println!("Current era: {:?}", current_era);
let hd = client.history_depth(None).await.unwrap();
println!("History depth: {:?}", hd);
let total_issuance = client.total_issuance(None).await.unwrap();
println!("total issuance: {:?}", total_issuance);
let alice_account = client.account(&alice.account_id(), None).await.unwrap();
println!("Alice's account info: {:?}", alice_account);
let o = client
.nominate(&alice, vec![bob.account_id().clone()])
.await
.unwrap();
println!("Nom nom: {:?}", o);
let o = client
.validate(&bob, ValidatorPrefs::default())
.await
.unwrap();
println!("Validator result: {:?}", o);
for &i in &[RewardDestination::Controller] {
for &j in &[&bob, &alice] {
println!(
"Transaction result: {:?}",
client.set_payee(j, i).await.unwrap()
);
client.chill(j).await.unwrap();
}
}
}
}
2 changes: 2 additions & 0 deletions src/frame/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ pub trait System {
+ MaybeSerialize
+ Debug
+ MaybeDisplay
+ Encode
+ Decode
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these are redundant, they come with Paramater

Copy link
Contributor

Choose a reason for hiding this comment

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

q: Parameter also comes with fmt::Debug, so should I drop that too?

+ Ord
+ Default;

Expand Down
Loading