From 303c5f47420290c1a9c87e66c7daacc7108bfb9d Mon Sep 17 00:00:00 2001 From: David Palm Date: Tue, 15 Sep 2020 23:41:28 +0200 Subject: [PATCH] WIP --- client/run.sh | 2 +- src/frame/staking.rs | 62 ++++++++++++++++++++++++++++++++++++ test-node/runtime/Cargo.toml | 1 + test-node/runtime/src/lib.rs | 26 +++++++++++++++ 4 files changed, 90 insertions(+), 1 deletion(-) diff --git a/client/run.sh b/client/run.sh index 6f67c6875c..8481ace69c 100755 --- a/client/run.sh +++ b/client/run.sh @@ -1,3 +1,3 @@ #!/bin/sh NODE_TEMPLATE=../target/release/test-node -$NODE_TEMPLATE --chain=dev-chain.json --alice +$NODE_TEMPLATE --chain=dev-chain.json --alice -lrpc=debug diff --git a/src/frame/staking.rs b/src/frame/staking.rs index 417222e338..dbc914e14c 100644 --- a/src/frame/staking.rs +++ b/src/frame/staking.rs @@ -195,3 +195,65 @@ pub struct NominateCall { /// The targets that are being nominated pub targets: Vec, } + +#[cfg(test)] +mod tests { + use super::*; + use crate::{ + // events::EventsDecoder, + extrinsic::PairSigner, + // subscription::EventSubscription, + // system::AccountStoreExt, + // tests::{test_client, TestRuntime}, + runtimes::KusamaRuntime as RT, + ClientBuilder, + // frame::staking::NominateCallExt, + // frame::staking::CurrentEraStoreExt, + // frame::staking::CurrentEraStore, + // frame::staking::HistoryDepthStore, + // runtimes::StakingRuntime as RT, + }; + // use sp_core::{sr25519::Pair, Pair as _}; + use sp_keyring::AccountKeyring; + use core::marker::PhantomData; + use crate::frame::balances::*; + use crate::frame::system::*; + use crate::extrinsic::Signer; + + #[async_std::test] + async fn test_nominate() { + env_logger::try_init().ok(); + let alice = PairSigner::::new(AccountKeyring::Alice.pair()); + let bob = PairSigner::::new(AccountKeyring::Bob.pair()); + + let client = ClientBuilder::::new() + .build() + .await + .unwrap(); + println!("HAVE CLIENT"); + + let current_era = client.current_era(None).await; + println!("Current era: {:?}", current_era); + let hd = client.history_depth(None).await; + println!("History depth: {:?}", hd); + let total_issuance = client.total_issuance(None).await; + println!("total issuance: {:?}", total_issuance); + let alice_account = client.account(&alice.account_id(), None).await; + println!("Alice's account info: {:?}", alice_account); + let o = client.nominate(&alice, vec![bob.account_id().clone()]).await; + println!("Nom nom: {:?}", o); + // let event = client. + // current_era() + // .await; + // println!("Current era: {:?}", event); + // let (client, _) = test_client().await; + // let event = client. + // nominate_and_watch(&alice, vec![AccountKeyring::Bob.to_account_id()]) + // .await + // .unwrap(); + // // .nominate() + // // .unwrap() + // // .unwrap(); + // dbg!(event); + } +} diff --git a/test-node/runtime/Cargo.toml b/test-node/runtime/Cargo.toml index 85463292cc..804f120f16 100644 --- a/test-node/runtime/Cargo.toml +++ b/test-node/runtime/Cargo.toml @@ -20,6 +20,7 @@ pallet-aura = { version = "2.0.0-rc6", default-features = false } pallet-balances = { version = "2.0.0-rc6", default-features = false } pallet-grandpa = { version = "2.0.0-rc6", default-features = false } pallet-randomness-collective-flip = { version = "2.0.0-rc6", default-features = false } +pallet-staking = { version = "2.0.0-rc6", default-features = false } pallet-sudo = { version = "2.0.0-rc6", default-features = false } pallet-timestamp = { version = "2.0.0-rc6", default-features = false } pallet-transaction-payment = { version = "2.0.0-rc6", default-features = false } diff --git a/test-node/runtime/src/lib.rs b/test-node/runtime/src/lib.rs index 85abd73d32..9fad00a604 100644 --- a/test-node/runtime/src/lib.rs +++ b/test-node/runtime/src/lib.rs @@ -82,6 +82,7 @@ pub use frame_support::{ StorageValue, }; pub use pallet_balances::Call as BalancesCall; +pub use pallet_staking::Call as StakingCall; pub use pallet_timestamp::Call as TimestampCall; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; @@ -305,6 +306,31 @@ impl pallet_sudo::Trait for Runtime { type Call = Call; } +// impl pallet_staking::Trait for Runtime { +// type Currency = Balances; +// type UnixTime = pallet_timestamp::Module; +// type CurrencyToVote = CurrencyToVoteHandler; +// type RewardRemainder = (); +// type Event = (); +// type Slash = (); +// type Reward = (); +// type SessionsPerEra = (); +// type SlashDeferDuration = (); +// type SlashCancelOrigin = frame_system::EnsureRoot; +// type BondingDuration = (); +// type SessionInterface = Self; +// type RewardCurve = RewardCurve; +// type NextNewSession = Session; +// type ElectionLookahead = (); +// type Call = Call; +// type MaxIterations = MaxIterations; +// type MinSolutionScoreBump = (); +// type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator; +// type UnsignedPriority = (); +// type WeightInfo = (); +// } + + construct_runtime!( pub enum Runtime where Block = Block,