Skip to content

Commit

Permalink
test(superblock): update two_thirds_consensus
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommytrg committed Feb 26, 2024
1 parent b70d537 commit 0494905
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions data_structures/src/superblock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2595,16 +2595,17 @@ mod tests {

#[test]
fn test_two_thirds_consensus() {
assert!(!two_thirds_consensus(2, 3));
assert!(!two_thirds_consensus(1, 3));
assert!(two_thirds_consensus(2, 3));
assert!(two_thirds_consensus(3, 3));
assert!(!two_thirds_consensus(2, 4));
assert!(!two_thirds_consensus(1, 4));
assert!(two_thirds_consensus(3, 4));
assert!(!two_thirds_consensus(21, 32));
assert!(two_thirds_consensus(22, 32));
assert!(!two_thirds_consensus(22, 33));
assert!(two_thirds_consensus(23, 33));
assert!(!two_thirds_consensus(22, 34));
assert!(two_thirds_consensus(23, 34));
assert!(!two_thirds_consensus(20, 32));
assert!(two_thirds_consensus(21, 32));
assert!(!two_thirds_consensus(21, 33));
assert!(two_thirds_consensus(22, 33));
assert!(!two_thirds_consensus(21, 34));
assert!(two_thirds_consensus(22, 34));
}

#[test]
Expand Down Expand Up @@ -2686,21 +2687,24 @@ mod tests {

// 4 valid votes -> SameAsLocal
let mut v3 = SuperBlockVote::new_unsigned(sb2.hash(), 2);
v3.secp256k1_signature.public_key = p3;
v3.secp256k1_signature.public_key = p3.clone();
assert_eq!(sbs.add_vote(&v3, 2), AddSuperBlockVote::ValidWithSameHash);
let mut v4 = SuperBlockVote::new_unsigned(sb2.hash(), 2);
v4.secp256k1_signature.public_key = p4;
assert_eq!(sbs.add_vote(&v4, 2), AddSuperBlockVote::ValidWithSameHash);

assert_eq!(sbs.has_consensus(), SuperBlockConsensus::SameAsLocal);

// 2 valid votes, 2 double votes and 1 missing vote -> NoConsensus
// 1 valid votes, 3 double votes and 1 missing vote -> NoConsensus
let mut v1_b = SuperBlockVote::new_unsigned(Hash::SHA256([2; 32]), 2);
v1_b.secp256k1_signature.public_key = p1;
assert_eq!(sbs.add_vote(&v1_b, 2), AddSuperBlockVote::DoubleVote);
let mut v2_b = SuperBlockVote::new_unsigned(Hash::SHA256([2; 32]), 2);
v2_b.secp256k1_signature.public_key = p2;
assert_eq!(sbs.add_vote(&v2_b, 2), AddSuperBlockVote::DoubleVote);
let mut v3_b = SuperBlockVote::new_unsigned(Hash::SHA256([2; 32]), 2);
v3_b.secp256k1_signature.public_key = p3;
assert_eq!(sbs.add_vote(&v3_b, 2), AddSuperBlockVote::DoubleVote);

assert_eq!(sbs.has_consensus(), SuperBlockConsensus::NoConsensus);
}
Expand Down

0 comments on commit 0494905

Please sign in to comment.