Skip to content

Commit

Permalink
add integration tests for pool, staking and delegated staking
Browse files Browse the repository at this point in the history
  • Loading branch information
Ank4n committed Mar 31, 2024
1 parent 32282fb commit 6caa7a5
Show file tree
Hide file tree
Showing 6 changed files with 535 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions polkadot/runtime/westend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ std = [
"pallet-beefy/std",
"pallet-collective/std",
"pallet-conviction-voting/std",
"pallet-delegated-staking/std",
"pallet-democracy/std",
"pallet-election-provider-multi-phase/std",
"pallet-election-provider-support-benchmarking?/std",
Expand Down Expand Up @@ -190,7 +191,6 @@ std = [
"pallet-society/std",
"pallet-staking-runtime-api/std",
"pallet-staking/std",
"pallet-delegated-staking/std",
"pallet-state-trie-migration/std",
"pallet-sudo/std",
"pallet-timestamp/std",
Expand Down Expand Up @@ -246,6 +246,7 @@ runtime-benchmarks = [
"pallet-balances/runtime-benchmarks",
"pallet-collective/runtime-benchmarks",
"pallet-conviction-voting/runtime-benchmarks",
"pallet-delegated-staking/runtime-benchmarks",
"pallet-democracy/runtime-benchmarks",
"pallet-election-provider-multi-phase/runtime-benchmarks",
"pallet-election-provider-support-benchmarking/runtime-benchmarks",
Expand All @@ -271,7 +272,6 @@ runtime-benchmarks = [
"pallet-session-benchmarking/runtime-benchmarks",
"pallet-society/runtime-benchmarks",
"pallet-staking/runtime-benchmarks",
"pallet-delegated-staking/runtime-benchmarks",
"pallet-state-trie-migration/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
Expand Down
4 changes: 4 additions & 0 deletions substrate/frame/delegated-staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ sp-io = { path = "../../primitives/io" }
substrate-test-utils = { path = "../../test-utils" }
sp-tracing = { path = "../../primitives/tracing" }
pallet-staking = { path = "../staking" }
pallet-nomination-pools = { path = "../nomination-pools" }
pallet-balances = { path = "../balances" }
pallet-timestamp = { path = "../timestamp" }
pallet-staking-reward-curve = { path = "../staking/reward-curve" }
Expand All @@ -39,6 +40,7 @@ std = [
"frame-support/std",
"frame-system/std",
"pallet-balances/std",
"pallet-nomination-pools/std",
"pallet-staking/std",
"pallet-timestamp/std",
"scale-info/std",
Expand All @@ -53,6 +55,7 @@ runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-nomination-pools/runtime-benchmarks",
"pallet-staking/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
Expand All @@ -63,6 +66,7 @@ try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-balances/try-runtime",
"pallet-nomination-pools/try-runtime",
"pallet-staking/try-runtime",
"pallet-timestamp/try-runtime",
"sp-runtime/try-runtime",
Expand Down
33 changes: 29 additions & 4 deletions substrate/frame/delegated-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl pallet_staking::Config for Runtime {
type NominationsQuota = pallet_staking::FixedNominationsQuota<16>;
type MaxUnlockingChunks = ConstU32<32>;
type MaxControllersInDeprecationBatch = ConstU32<100>;
type EventListeners = DelegatedStaking;
type EventListeners = (Pools, DelegatedStaking);
type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig;
type WeightInfo = ();
}
Expand Down Expand Up @@ -164,6 +164,22 @@ impl Convert<U256, Balance> for U256ToBalance {

parameter_types! {
pub static MaxUnbonding: u32 = 8;
pub const PoolsPalletId: PalletId = PalletId(*b"py/nopls");
}
impl pallet_nomination_pools::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type Currency = Balances;
type RuntimeFreezeReason = RuntimeFreezeReason;
type RewardCounter = sp_runtime::FixedU128;
type BalanceToU256 = BalanceToU256;
type U256ToBalance = U256ToBalance;
type PostUnbondingPoolsWindow = ConstU32<2>;
type PalletId = PoolsPalletId;
type MaxMetadataLen = ConstU32<256>;
type MaxUnbonding = MaxUnbonding;
type MaxPointsToBalance = frame_support::traits::ConstU8<10>;
type StakeAdapter = pallet_nomination_pools::adapter::DelegateStake<Self, DelegatedStaking>;
}

frame_support::construct_runtime!(
Expand All @@ -172,6 +188,7 @@ frame_support::construct_runtime!(
Timestamp: pallet_timestamp,
Balances: pallet_balances,
Staking: pallet_staking,
Pools: pallet_nomination_pools,
DelegatedStaking: delegated_staking,
}
);
Expand Down Expand Up @@ -301,16 +318,24 @@ pub(crate) fn get_delegatee(delegatee: &AccountId) -> Delegatee<T> {
Delegatee::<T>::from(delegatee).expect("delegate should exist")
}

#[allow(unused)]
pub(crate) fn held_balance(who: &AccountId) -> Balance {
Balances::balance_on_hold(&HoldReason::Delegating.into(), who)
}

parameter_types! {
static ObservedEventsDelegatedStaking: usize = 0;
static ObservedEventsPools: usize = 0;
}
pub(crate) fn pool_events_since_last_call() -> Vec<pallet_nomination_pools::Event<Runtime>> {
let events = System::events()
.into_iter()
.map(|r| r.event)
.filter_map(|e| if let RuntimeEvent::Pools(inner) = e { Some(inner) } else { None })
.collect::<Vec<_>>();
let already_seen = ObservedEventsPools::get();
ObservedEventsPools::set(events.len());
events.into_iter().skip(already_seen).collect()
}

#[allow(unused)]
pub(crate) fn events_since_last_call() -> Vec<crate::Event<Runtime>> {
let events = System::events()
.into_iter()
Expand Down
Loading

0 comments on commit 6caa7a5

Please sign in to comment.