Skip to content

Commit

Permalink
Integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinonard committed Feb 6, 2024
1 parent 459140e commit 2febe99
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 3 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.

1 change: 1 addition & 0 deletions pallets/dapp-staking-migration/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down
1 change: 1 addition & 0 deletions runtime/astar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Runtime>;
}

Expand Down
7 changes: 4 additions & 3 deletions tests/integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 }
Expand Down
47 changes: 47 additions & 0 deletions tests/integration/src/dapp_staking_v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use crate::setup::*;

use pallet_collator_selection::{CandidateInfo, Candidates};
use pallet_dapp_staking_v3::*;

#[test]
Expand Down Expand Up @@ -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::<Runtime>::mutate(|candidates| {
candidates.push(candidate_info);
});

// Now try to participate in dApp staking with Alice and expect an error
let minimum_lock_amount =
<Runtime as pallet_dapp_staking_v3::Config>::MinimumLockedAmount::get();
assert_noop!(
DappStaking::lock(RuntimeOrigin::signed(ALICE.clone()), minimum_lock_amount,),
pallet_dapp_staking_v3::Error::<Runtime>::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 =
<Runtime as pallet_dapp_staking_v3::Config>::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::<Runtime>::NotAllowedCandidate
);
});
}
2 changes: 2 additions & 0 deletions tests/integration/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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"))]
Expand Down

0 comments on commit 2febe99

Please sign in to comment.