Skip to content

Commit

Permalink
implement state tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JSHan94 authored and junha1 committed Nov 6, 2023
1 parent 9f020e4 commit 129aa3c
Showing 1 changed file with 115 additions and 5 deletions.
120 changes: 115 additions & 5 deletions vetomint/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,24 @@ mod tests {

#[test]
fn get_total_prevotes() {
// TODO
let mut consensus_state = create_default_consensus_state();
consensus_state.prevotes.insert(Vote {
proposal: None,
signer: 0,
round: 0,
});

let total_prevotes_round = consensus_state.get_total_prevotes(0);
assert_eq!(total_prevotes_round, 1, "total precommits should be 1");

consensus_state.prevotes.insert(Vote {
proposal: None,
signer: 1,
round: 0,
});

let total_prevotes_round = consensus_state.get_total_prevotes(0);
assert_eq!(total_prevotes_round, 2, "total precommits should be 2");
}

#[test]
Expand Down Expand Up @@ -184,21 +201,114 @@ mod tests {

#[test]
fn get_total_prevotes_on_proposal() {
// TODO: modify the default consensus state (e.g., add prevotes) to test this.
let mut consensus_state = create_default_consensus_state();
consensus_state.prevotes.insert(Vote {
proposal: Some(0),
signer: 0,
round: 0,
});

let total_prevotes_on_proposal = consensus_state.get_total_prevotes_on_proposal(0, 0);
assert_eq!(
total_prevotes_on_proposal, 1,
"total prevotes on proposal should be 1"
);

consensus_state.prevotes.insert(Vote {
proposal: Some(0),
signer: 1,
round: 0,
});

let total_prevotes_on_proposal = consensus_state.get_total_prevotes_on_proposal(0, 0);
assert_eq!(
total_prevotes_on_proposal, 2,
"total prevotes on proposal should be 2"
);
}

#[test]
fn get_total_precommits_on_proposal() {
// TODO: modify the default consensus state (e.g., add precommits) to test this.
let mut consensus_state = create_default_consensus_state();
consensus_state.precommits.insert(Vote {
proposal: Some(0),
signer: 0,
round: 0,
});

let total_precommits_on_proposal = consensus_state.get_total_precommits_on_proposal(0, 0);
assert_eq!(
total_precommits_on_proposal, 1,
"total precommits on proposal should be 1"
);

consensus_state.precommits.insert(Vote {
proposal: Some(0),
signer: 1,
round: 0,
});

let total_precommits_on_proposal = consensus_state.get_total_precommits_on_proposal(0, 0);
assert_eq!(
total_precommits_on_proposal, 2,
"total precommits on proposal should be 2"
);
}

#[test]
fn get_total_prevotes_on_nil() {
// TODO: modify the default consensus state (e.g., add prevotes) to test this.
let mut consensus_state = create_default_consensus_state();
consensus_state.prevotes.insert(Vote {
proposal: None,
signer: 0,
round: 0,
});

let total_prevotes_on_nil = consensus_state.get_total_prevotes_on_nil(0);
assert_eq!(
total_prevotes_on_nil, 1,
"total prevotes on nil should be 1"
);

consensus_state.prevotes.insert(Vote {
proposal: None,
signer: 1,
round: 0,
});

let total_prevotes_on_nil = consensus_state.get_total_prevotes_on_nil(0);
assert_eq!(
total_prevotes_on_nil, 2,
"total prevotes on nil should be 2"
);
}

#[test]
fn get_total_precommits_on_nil() {
// TODO: modify the default consensus state (e.g., add precommits) to test this.
let mut consensus_state = create_default_consensus_state();

consensus_state.precommits.insert(Vote {
proposal: None,
signer: 0,
round: 0,
});

let total_precommits_on_nil = consensus_state.get_total_precommits_on_nil(0);
assert_eq!(
total_precommits_on_nil, 1,
"total precommits on nil should be 1"
);

consensus_state.precommits.insert(Vote {
proposal: None,
signer: 1,
round: 0,
});

let total_precommits_on_nil = consensus_state.get_total_precommits_on_nil(0);
assert_eq!(
total_precommits_on_nil, 2,
"total precommits on nil should be 2"
);
}
}

0 comments on commit 129aa3c

Please sign in to comment.