Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(consensus): test for ConsensusReactor
- Loading branch information
Lee
committed
Oct 24, 2021
1 parent
2cd3b98
commit afb80c1
Showing
4 changed files
with
63 additions
and
14 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,42 @@ | ||
using Libplanet.Net.Consensus; | ||
using Libplanet.Net.Messages; | ||
using Xunit; | ||
|
||
namespace Libplanet.Tests.Net.Consensus | ||
{ | ||
public class ConsensusReactorTest | ||
{ | ||
[Fact] | ||
public void ProcessPropose() | ||
{ | ||
ConsensusReactor reactor = new ConsensusReactor(0, new MockedConsensusBroadCaster()); | ||
var data = new byte[] { 0x01 }; | ||
ConsensusPropose propose = new ConsensusPropose(0, 0, new byte[] { 0x01 }); | ||
reactor.ProcessMessage(propose); | ||
|
||
ConsensusState state = reactor.GetState(); | ||
Assert.Equal(data, state.Data); | ||
Assert.Equal(ConsensusState.RoundStep.RoundStepPrevoteWait, state.Step); | ||
} | ||
|
||
[Fact] | ||
public void ProcessProposeWrongRound() | ||
{ | ||
ConsensusReactor reactor = new ConsensusReactor(0, new MockedConsensusBroadCaster()); | ||
var data = new byte[] { 0x01 }; | ||
ConsensusPropose propose = new ConsensusPropose(0, 1, new byte[] { 0x01 }); | ||
reactor.ProcessMessage(propose); | ||
|
||
ConsensusState state = reactor.GetState(); | ||
Assert.Equal(new byte[] { }, state.Data); | ||
Assert.Equal(ConsensusState.RoundStep.RoundStepNewRound, state.Step); | ||
} | ||
|
||
public class MockedConsensusBroadCaster : IConsensusBroadcaster | ||
{ | ||
public void BroadcastMessage(ConsensusMessage message) | ||
{ | ||
} | ||
} | ||
} | ||
} |
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
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
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