Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
fix test after changes in master
Browse files Browse the repository at this point in the history
  • Loading branch information
ordian committed Jan 10, 2023
1 parent 4d63258 commit 9d81c26
Showing 1 changed file with 28 additions and 35 deletions.
63 changes: 28 additions & 35 deletions runtime/parachains/src/disputes/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,14 @@ fn test_punish_post_conclusion() {
let v4 = <ValidatorId as CryptoType>::Pair::generate().0;
let v5 = <ValidatorId as CryptoType>::Pair::generate().0;
let v6 = <ValidatorId as CryptoType>::Pair::generate().0;
// Mapping between key pair and `ValidatorIndex`
// v0 -> 0
// v1 -> 3
// v2 -> 6
// v3 -> 5
// v4 -> 1
// v5 -> 4
// v6 -> 2

run_to_block(6, |b| {
// a new session at each block
Expand Down Expand Up @@ -1295,7 +1303,6 @@ fn test_punish_post_conclusion() {
let inclusion_parent = sp_core::H256::repeat_byte(0xff);
let session = 3;

// v0 votes backing, v1 votes against
let stmts = vec![DisputeStatementSet {
candidate_hash: candidate_hash.clone(),
session,
Expand All @@ -1312,7 +1319,7 @@ fn test_punish_post_conclusion() {
(
DisputeStatement::Invalid(InvalidDisputeStatementKind::Explicit),
ValidatorIndex(1),
v1.sign(
v4.sign(
&ExplicitDisputeStatement {
valid: false,
candidate_hash: candidate_hash.clone(),
Expand All @@ -1321,25 +1328,10 @@ fn test_punish_post_conclusion() {
.signing_payload(),
),
),
],
}];

let stmts = filter_dispute_set(stmts);
assert_ok!(
Pallet::<Test>::process_checked_multi_dispute_data(stmts),
vec![(3, candidate_hash)],
);

// v2, v6, v4, v5 vote against, dispute concludes AGAINST.
// v3 votes FOR
let stmts = vec![DisputeStatementSet {
candidate_hash: candidate_hash.clone(),
session,
statements: vec![
(
DisputeStatement::Invalid(InvalidDisputeStatementKind::Explicit),
ValidatorIndex(2),
v2.sign(
v6.sign(
&ExplicitDisputeStatement {
valid: false,
candidate_hash: candidate_hash.clone(),
Expand All @@ -1351,7 +1343,7 @@ fn test_punish_post_conclusion() {
(
DisputeStatement::Invalid(InvalidDisputeStatementKind::Explicit),
ValidatorIndex(6),
v6.sign(
v2.sign(
&ExplicitDisputeStatement {
valid: false,
candidate_hash: candidate_hash.clone(),
Expand All @@ -1363,7 +1355,7 @@ fn test_punish_post_conclusion() {
(
DisputeStatement::Invalid(InvalidDisputeStatementKind::Explicit),
ValidatorIndex(4),
v4.sign(
v5.sign(
&ExplicitDisputeStatement {
valid: false,
candidate_hash: candidate_hash.clone(),
Expand All @@ -1375,7 +1367,7 @@ fn test_punish_post_conclusion() {
(
DisputeStatement::Invalid(InvalidDisputeStatementKind::Explicit),
ValidatorIndex(5),
v5.sign(
v3.sign(
&ExplicitDisputeStatement {
valid: false,
candidate_hash: candidate_hash.clone(),
Expand All @@ -1387,24 +1379,27 @@ fn test_punish_post_conclusion() {
(
DisputeStatement::Valid(ValidDisputeStatementKind::ApprovalChecking),
ValidatorIndex(3),
v3.sign(&ApprovalVote(candidate_hash).signing_payload(session)),
v1.sign(&ApprovalVote(candidate_hash).signing_payload(session)),
),
],
}];

let stmts = filter_dispute_set(stmts);
assert_ok!(Pallet::<Test>::process_checked_multi_dispute_data(stmts), vec![],);
assert_ok!(
Pallet::<Test>::process_checked_multi_dispute_data(stmts),
vec![(session, candidate_hash)],
);

assert_eq!(
PUNISH_VALIDATORS_FOR.with(|r| r.borrow().clone()),
vec![(3, vec![]), (3, vec![ValidatorIndex(0), ValidatorIndex(3)]),],
vec![(session, vec![ValidatorIndex(0), ValidatorIndex(3)]),],
);
assert_eq!(
PUNISH_BACKERS_FOR.with(|r| r.borrow().clone()),
vec![(3, vec![ValidatorIndex(0)]), (3, vec![ValidatorIndex(0)]),],
vec![(session, vec![ValidatorIndex(0)]),],
);

// someone reveals v3 backing vote, v6 votes against
// someone reveals 3 backing vote, 6 votes against
let stmts = vec![DisputeStatementSet {
candidate_hash: candidate_hash.clone(),
session,
Expand All @@ -1414,14 +1409,14 @@ fn test_punish_post_conclusion() {
inclusion_parent,
)),
ValidatorIndex(3),
v3.sign(&CompactStatement::Valid(candidate_hash).signing_payload(
v1.sign(&CompactStatement::Valid(candidate_hash).signing_payload(
&SigningContext { session_index: session, parent_hash: inclusion_parent },
)),
),
(
DisputeStatement::Invalid(InvalidDisputeStatementKind::Explicit),
ValidatorIndex(6),
v6.sign(
v2.sign(
&ExplicitDisputeStatement {
valid: false,
candidate_hash: candidate_hash.clone(),
Expand All @@ -1440,24 +1435,22 @@ fn test_punish_post_conclusion() {
assert_eq!(
PUNISH_VALIDATORS_FOR.with(|r| r.borrow().clone()),
vec![
(3, vec![]),
(3, vec![ValidatorIndex(0), ValidatorIndex(3)]),
(3, vec![ValidatorIndex(3)]),
(session, vec![ValidatorIndex(0), ValidatorIndex(3)]),
(session, vec![ValidatorIndex(3)]),
],
);

assert_eq!(
PUNISH_BACKERS_FOR.with(|r| r.borrow().clone()),
vec![
(3, vec![ValidatorIndex(0)]),
(3, vec![ValidatorIndex(0)]),
(3, vec![ValidatorIndex(0), ValidatorIndex(3)])
(session, vec![ValidatorIndex(0)]),
(session, vec![ValidatorIndex(0), ValidatorIndex(3)])
],
);

assert_eq!(
PUNISH_VALIDATORS_AGAINST.with(|r| r.borrow().clone()),
vec![(3, vec![]), (3, vec![]), (3, vec![]),],
vec![(session, vec![]), (session, vec![]),],
);
})
}
Expand Down

0 comments on commit 9d81c26

Please sign in to comment.