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

MESH-1877/ Staking - off-chain election results fails if validator is no longer compliant #1376

60 changes: 60 additions & 0 deletions pallets/runtime/tests/src/staking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ use mock::*;
use pallet_balances::Error as BalancesError;
use pallet_identity::Error as IdentityError;
use pallet_staking::*;
use polymesh_primitives::Claim;
use sp_npos_elections::ElectionScore;
use sp_runtime::{
assert_eq_error_rate,
Expand Down Expand Up @@ -4341,6 +4342,65 @@ mod offchain_phragmen {
})
}

#[test]
fn off_chain_election_validator_non_compliance() {
ExtBuilder::default()
.offchain_election_ext()
.validator_count(4)
.has_stakers(false)
.build()
.execute_with(|| {
build_offchain_phragmen_test_ext();
run_to_block(12);

let acc_70 = 70;
// Add did to user
provide_did_to_user(70);
let entity_id = Identity::get_identity(&70).unwrap();
let cdd_account_id = 1005;
let (cdd_id, _) = create_cdd_id_and_investor_uid(entity_id);

// Add permissions
assert_add_permissioned_validator!(&acc_70);
let (compact, winners, score) = prepare_submission_with(true, true, 2, |_| {});

// Ensure submit_solution runs successfully
assert_ok!(Staking::submit_election_solution_unsigned(
Origin::none(),
winners.clone(),
compact.clone(),
score,
current_era(),
election_size(),
));

assert_eq!(winners.len(), 4);

// Remove cdd claim for 70
assert_ok!(Identity::revoke_claim(
Origin::signed(cdd_account_id),
entity_id,
Claim::CustomerDueDiligence(cdd_id),
));

let (compact_2, winners_2, score_2) =
prepare_submission_with(true, true, 2, |_| {});

// Ensure submit_solution gets error
assert_noop!(
Staking::submit_election_solution_unsigned(
Origin::none(),
winners_2.clone(),
compact_2.clone(),
score_2,
current_era(),
election_size(),
),
Error::<Test>::OffchainElectionWeakSubmission,
JMoore96 marked this conversation as resolved.
Show resolved Hide resolved
);
})
}

#[test]
fn offchain_storage_is_set() {
let mut ext = ExtBuilder::default()
Expand Down