From 2febe99048728288ae984f31fe83132ddea65360 Mon Sep 17 00:00:00 2001 From: Dino Pacandi Date: Tue, 6 Feb 2024 11:05:12 +0100 Subject: [PATCH] Integration tests --- Cargo.lock | 1 + pallets/dapp-staking-migration/src/mock.rs | 1 + runtime/astar/src/lib.rs | 1 + tests/integration/Cargo.toml | 7 ++-- tests/integration/src/dapp_staking_v3.rs | 47 ++++++++++++++++++++++ tests/integration/src/setup.rs | 2 + 6 files changed, 56 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 83b53b9d8d..295a1cd6de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4989,6 +4989,7 @@ dependencies = [ "libsecp256k1", "pallet-assets", "pallet-balances", + "pallet-collator-selection", "pallet-contracts", "pallet-contracts-primitives", "pallet-dapp-staking-v3", diff --git a/pallets/dapp-staking-migration/src/mock.rs b/pallets/dapp-staking-migration/src/mock.rs index a3de9ef81f..262c0ce340 100644 --- a/pallets/dapp-staking-migration/src/mock.rs +++ b/pallets/dapp-staking-migration/src/mock.rs @@ -182,6 +182,7 @@ impl pallet_dapp_staking_v3::Config for Test { type StakingRewardHandler = DummyStakingRewardHandler; type CycleConfiguration = DummyCycleConfiguration; type Observers = (); + type AccountCheck = (); type EraRewardSpanLength = ConstU32<8>; type RewardRetentionInPeriods = ConstU32<2>; type MaxNumberOfContracts = ConstU32<10>; diff --git a/runtime/astar/src/lib.rs b/runtime/astar/src/lib.rs index c4491f9ee3..a4adfc43de 100644 --- a/runtime/astar/src/lib.rs +++ b/runtime/astar/src/lib.rs @@ -449,6 +449,7 @@ impl pallet_collator_selection::Config for Runtime { type ValidatorIdOf = pallet_collator_selection::IdentityCollator; type ValidatorRegistration = Session; type SlashRatio = SlashRatio; + type AccountCheck = CollatorSelectionAccountCheck; type WeightInfo = pallet_collator_selection::weights::SubstrateWeight; } diff --git a/tests/integration/Cargo.toml b/tests/integration/Cargo.toml index 1d1696f550..595ee1afb2 100644 --- a/tests/integration/Cargo.toml +++ b/tests/integration/Cargo.toml @@ -25,9 +25,6 @@ pallet-assets = { workspace = true } pallet-balances = { workspace = true } pallet-contracts = { workspace = true } pallet-contracts-primitives = { workspace = true } -pallet-dapp-staking-v3 = { workspace = true } -pallet-dapps-staking = { workspace = true } -pallet-inflation = { workspace = true } pallet-proxy = { workspace = true } pallet-utility = { workspace = true } sp-core = { workspace = true } @@ -36,9 +33,13 @@ sp-runtime = { workspace = true } # astar dependencies assets-chain-extension-types = { workspace = true } +pallet-collator-selection = { workspace = true } +pallet-dapp-staking-v3 = { workspace = true } +pallet-dapps-staking = { workspace = true } pallet-ethereum-checked = { workspace = true } pallet-evm-precompile-assets-erc20 = { workspace = true } pallet-evm-precompile-dispatch = { workspace = true } +pallet-inflation = { workspace = true } pallet-unified-accounts = { workspace = true } precompile-utils = { workspace = true } unified-accounts-chain-extension-types = { workspace = true } diff --git a/tests/integration/src/dapp_staking_v3.rs b/tests/integration/src/dapp_staking_v3.rs index 1a79c9ccbc..5fa769ea1f 100644 --- a/tests/integration/src/dapp_staking_v3.rs +++ b/tests/integration/src/dapp_staking_v3.rs @@ -20,6 +20,7 @@ use crate::setup::*; +use pallet_collator_selection::{CandidateInfo, Candidates}; use pallet_dapp_staking_v3::*; #[test] @@ -78,3 +79,49 @@ fn dapp_staking_triggers_inflation_recalculation() { ); }); } + +#[test] +fn lock_not_possible_for_collator_candidate_account() { + new_test_ext().execute_with(|| { + // Hacky approach but it works + let candidate_info = CandidateInfo { + who: ALICE.clone(), + deposit: CollatorSelection::candidacy_bond(), + }; + Candidates::::mutate(|candidates| { + candidates.push(candidate_info); + }); + + // Now try to participate in dApp staking with Alice and expect an error + let minimum_lock_amount = + ::MinimumLockedAmount::get(); + assert_noop!( + DappStaking::lock(RuntimeOrigin::signed(ALICE.clone()), minimum_lock_amount,), + pallet_dapp_staking_v3::Error::::AccountNotAvailableForDappStaking + ); + }); +} + +// Not the ideal place for such test, can be moved later. +#[test] +fn collator_selection_candidacy_not_possible_for_dapp_staking_participant() { + new_test_ext().execute_with(|| { + // Lock some amount with Alice + let minimum_lock_amount = + ::MinimumLockedAmount::get(); + assert_ok!(DappStaking::lock( + RuntimeOrigin::signed(ALICE.clone()), + minimum_lock_amount, + )); + + // Ensure it's not possible to become a candidate for collator selection while having locked funds in dApp staking + assert_ok!(CollatorSelection::set_desired_candidates( + RuntimeOrigin::root(), + 1_000_000, + )); + assert_noop!( + CollatorSelection::register_as_candidate(RuntimeOrigin::signed(ALICE.clone())), + pallet_collator_selection::Error::::NotAllowedCandidate + ); + }); +} diff --git a/tests/integration/src/setup.rs b/tests/integration/src/setup.rs index 083a560ceb..2bca834b28 100644 --- a/tests/integration/src/setup.rs +++ b/tests/integration/src/setup.rs @@ -231,6 +231,7 @@ pub fn run_to_block(n: BlockNumber) { AuraExt::on_finalize(block_number); PolkadotXcm::on_finalize(block_number); Ethereum::on_finalize(block_number); + CollatorSelection::on_finalize(block_number); DynamicEvmBaseFee::on_finalize(block_number); #[cfg(any(feature = "shibuya", feature = "shiden"))] Inflation::on_finalize(block_number); @@ -249,6 +250,7 @@ pub fn run_to_block(n: BlockNumber) { Authorship::on_initialize(block_number); Aura::on_initialize(block_number); AuraExt::on_initialize(block_number); + CollatorSelection::on_initialize(block_number); Ethereum::on_initialize(block_number); DynamicEvmBaseFee::on_initialize(block_number); #[cfg(any(feature = "shibuya", feature = "shiden"))]