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

Add double_vote_1 test-case in vetomint #464

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 143 additions & 2 deletions vetomint/tests/test_suite1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,150 @@ fn normal_1() {
fn lock_1() {}

/// A byzantine node broadcasts both nil and non-nil prevotes but fails to break the safety.
#[ignore]
#[test]
fn double_votes_1() {}
fn double_votes_1() {
let mut height_info = HeightInfo {
validators: vec![1, 1, 1, 1],
this_node_index: Some(0),
timestamp: 0,
consensus_params: ConsensusParams {
timeout_ms: 100,
repeat_round_for_first_leader: 1,
},
initial_block_candidate: 0,
};

let mut proposer = Vetomint::new(height_info.clone());

let mut nodes = Vec::new();
for i in 1..=2 {
height_info.this_node_index = Some(i);
nodes.push(Vetomint::new(height_info.clone()));
}

let response = proposer.progress(ConsensusEvent::Start, 0);
assert_eq!(
response,
vec![
ConsensusResponse::BroadcastProposal {
proposal: 0,
valid_round: None,
round: 0,
},
ConsensusResponse::BroadcastPrevote {
proposal: Some(0),
round: 0
}
]
);

for node in nodes.iter_mut() {
let response = node.progress(ConsensusEvent::Start, 0);
assert_eq!(response, vec![]);
}

for node in nodes.iter_mut() {
let response = node.progress(
ConsensusEvent::BlockProposalReceived {
proposal: 0,
valid: true,
valid_round: None,
proposer: 0,
round: 0,
favor: true,
},
1,
);
assert_eq!(
response,
vec![ConsensusResponse::BroadcastPrevote {
proposal: Some(0),
round: 0,
}]
);
}

let mut nodes = vec![vec![proposer], nodes].concat();

for (i, node) in nodes.iter_mut().enumerate() {
// byzantine node's will send nil-prevote to node
let response = node.progress(
ConsensusEvent::Prevote {
proposal: None,
signer: 3, // byzantine node index
round: 0,
},
2,
);
assert_eq!(response, Vec::new());

// byzantine node's will send prevote to node agiain to break the consensus
let response = node.progress(
ConsensusEvent::Prevote {
proposal: Some(0),
signer: 3, // byzantine node index
round: 0,
},
2,
);
assert_eq!(response, Vec::new());

let response = node.progress(
ConsensusEvent::Prevote {
proposal: Some(0),
signer: (i + 1) % 3,
round: 0,
},
2,
);
assert_eq!(
response,
vec![ConsensusResponse::BroadcastPrecommit {
proposal: Some(0),
round: 0,
}]
);

let response = node.progress(
ConsensusEvent::Prevote {
proposal: Some(0),
signer: (i + 2) % 3,
round: 0,
},
2,
);
assert_eq!(response, Vec::new());
}

for (i, node) in nodes.iter_mut().enumerate() {
let response = node.progress(
ConsensusEvent::Precommit {
proposal: Some(0),
signer: (i + 1) % 3,
round: 0,
},
3,
);
assert_eq!(response, Vec::new());
let response = node.progress(
ConsensusEvent::Precommit {
proposal: Some(0),
signer: (i + 2) % 3,
round: 0,
},
3,
);

assert_eq!(
response,
vec![ConsensusResponse::FinalizeBlock {
proposal: 0,
proof: (0..3).collect(),
round: 0
}]
);
}
}

/// Timeout occurs in the prevote stage, skipping the first round but eventually reaching consensus.
#[ignore]
Expand Down