-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4790be5
commit db933f0
Showing
2 changed files
with
98 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package pbft | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// When Representative Number : 6, prevoteMsg Num : 4 -> then true | ||
func TestState_CheckPrevoteCondition_Satisfy(t *testing.T) { | ||
// 6 rep | ||
satisfyPrevoteConditionState := setUpState() | ||
prevoteMsgs := make([]PrevoteMsg, 0) | ||
for i := 0; i < 4; i++ { | ||
prevoteMsgs = append(prevoteMsgs, PrevoteMsg{ | ||
StateID: StateID{"state1"}, | ||
SenderID: "user1", | ||
}) | ||
} | ||
satisfyPrevoteConditionState.PrevoteMsgPool = PrevoteMsgPool{messages: prevoteMsgs} | ||
|
||
assert.Equal(t, true, satisfyPrevoteConditionState.CheckPrevoteCondition()) | ||
} | ||
|
||
// When Representative Number : 6, prevoteMsg Number : 3 -> then false | ||
func TestState_CheckPrevoteCondition_UnSatisfy(t *testing.T) { | ||
unSatisfyPrevoteConditionState := setUpState() | ||
prevoteMsgs := make([]PrevoteMsg, 0) | ||
for i := 0; i < 3; i++ { | ||
prevoteMsgs = append(prevoteMsgs, PrevoteMsg{ | ||
StateID: StateID{"state1"}, | ||
SenderID: "user1", | ||
}) | ||
} | ||
unSatisfyPrevoteConditionState.PrevoteMsgPool = PrevoteMsgPool{messages: prevoteMsgs} | ||
|
||
//then false | ||
assert.Equal(t, false, unSatisfyPrevoteConditionState.CheckPrevoteCondition()) | ||
} | ||
|
||
// When Representative Number : 6, prevoteCommitMsg Number : 4 -> then true | ||
func TestState_CheckPreCommitCondition_Satisfy(t *testing.T) { | ||
satisfyPrecommitConditionState := setUpState() | ||
precommitMsgs := make([]PreCommitMsg, 0) | ||
for i := 0; i < 4; i++ { | ||
precommitMsgs = append(precommitMsgs, PreCommitMsg{ | ||
StateID: StateID{"state1"}, | ||
SenderID: "user1", | ||
}) | ||
} | ||
satisfyPrecommitConditionState.PreCommitMsgPool = PreCommitMsgPool{messages: precommitMsgs} | ||
|
||
assert.Equal(t, true, satisfyPrecommitConditionState.CheckPreCommitCondition()) | ||
} | ||
|
||
// When Representative Number : 6, prevoteCommitMsg Number : 3 -> then false | ||
func TestState_CheckPreCommitCondition_UnSatisfy(t *testing.T) { | ||
|
||
unSatisfyPrecommitConditionState := setUpState() | ||
precommitMsgs := make([]PreCommitMsg, 0) | ||
for i := 0; i < 3; i++ { | ||
precommitMsgs = append(precommitMsgs, PreCommitMsg{ | ||
StateID: StateID{"state1"}, | ||
SenderID: "user1", | ||
}) | ||
} | ||
unSatisfyPrecommitConditionState.PreCommitMsgPool = PreCommitMsgPool{messages: precommitMsgs} | ||
|
||
assert.Equal(t, false, unSatisfyPrecommitConditionState.CheckPreCommitCondition()) | ||
} | ||
|
||
func setUpState() State { | ||
//when representatives consist 6 member | ||
reps := make([]*Representative, 0) | ||
for i := 0; i < 6; i++ { | ||
reps = append(reps, &Representative{ | ||
ID: "user", | ||
}) | ||
} | ||
|
||
var normalBlock = ProposedBlock{ | ||
Seal: []byte{1, 2, 3, 4}, | ||
Body: []byte{1, 2, 3, 5}, | ||
} | ||
|
||
state1 := State{ | ||
StateID: StateID{"state1"}, | ||
Representatives: reps, | ||
Block: normalBlock, | ||
CurrentStage: IDLE_STAGE, | ||
} | ||
return state1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters