use of com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusLearn in project popstellar by dedis.
the class ElectionStartFragmentTest method displayWithUpdatesIsCorrect.
@Test
public void displayWithUpdatesIsCorrect() throws DataHandlingException {
setupViewModel(PAST_TIME);
// Election start time has passed, should display that it's ready and start button enabled
displayAssertions(STATUS_READY, START_START, true);
DataInteraction grid = nodesGrid();
nodeAssertions(grid, ownPos, "Waiting\n" + publicKey, false);
nodeAssertions(grid, node2Pos, "Waiting\n" + node2, false);
nodeAssertions(grid, node3Pos, "Waiting\n" + node3, false);
// Nodes 3 try to start
MessageGeneral elect3Msg = createMsg(node3KeyPair, elect);
messageHandler.handleMessage(laoRepository, messageSender, consensusChannel, elect3Msg);
nodeAssertions(grid, node3Pos, "Approve Start by\n" + node3, true);
// We try to start (it should disable the start button)
MessageGeneral elect1Msg = createMsg(mainKeyPair, elect);
messageHandler.handleMessage(laoRepository, messageSender, consensusChannel, elect1Msg);
displayAssertions(STATUS_READY, START_START, false);
nodeAssertions(grid, ownPos, "Approve Start by\n" + publicKey, true);
// We accepted node 3 (it should disable button for node3)
ConsensusElectAccept electAccept3 = new ConsensusElectAccept(INSTANCE_ID, elect3Msg.getMessageId(), true);
MessageGeneral accept3Msg = createMsg(mainKeyPair, electAccept3);
messageHandler.handleMessage(laoRepository, messageSender, consensusChannel, accept3Msg);
nodeAssertions(grid, node3Pos, "Approve Start by\n" + node3, false);
// Receive a learn message => node3 was accepted and has started the election
ConsensusLearn learn3 = new ConsensusLearn(INSTANCE_ID, elect3Msg.getMessageId(), PAST_TIME, true, Collections.emptyList());
MessageGeneral learn3Msg = createMsg(node3KeyPair, learn3);
messageHandler.handleMessage(laoRepository, messageSender, consensusChannel, learn3Msg);
displayAssertions(STATUS_STARTED, START_STARTED, false);
nodeAssertions(grid, node3Pos, "Started by\n" + node3, false);
}
use of com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusLearn in project popstellar by dedis.
the class ConsensusHandlerTest method handleConsensusLearnTest.
// handle a learn from node3 for the elect of node2
// This test need be run after the elect message was handled, else the messageId would be invalid
private void handleConsensusLearnTest() throws DataHandlingException {
ConsensusLearn learn = new ConsensusLearn(INSTANCE_ID, messageId, CREATION_TIME, true, Collections.emptyList());
MessageGeneral learnMsg = getMsg(NODE_3_KEY, learn);
messageHandler.handleMessage(laoRepository, messageSender, CONSENSUS_CHANNEL, learnMsg);
Optional<ElectInstance> electInstanceOpt = lao.getElectInstance(electMsg.getMessageId());
assertTrue(electInstanceOpt.isPresent());
ElectInstance electInstance = electInstanceOpt.get();
assertEquals(ACCEPTED, electInstance.getState());
}
use of com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusLearn in project popstellar by dedis.
the class ConsensusHandlerTest method handleConsensusWithInvalidMessageIdTest.
@Test
public void handleConsensusWithInvalidMessageIdTest() {
// When an invalid instance id is used in handler for elect_accept and learn,
// it should throw an InvalidMessageIdException
ConsensusElectAccept electAcceptInvalid = new ConsensusElectAccept(INSTANCE_ID, INVALID_MSG_ID, true);
ConsensusLearn learnInvalid = new ConsensusLearn(INSTANCE_ID, INVALID_MSG_ID, CREATION_TIME, true, Collections.emptyList());
ConsensusFailure failureInvalid = new ConsensusFailure(INSTANCE_ID, INVALID_MSG_ID, CREATION_TIME);
MessageGeneral electAcceptInvalidMsg = getMsg(ORGANIZER_KEY, electAcceptInvalid);
MessageGeneral learnInvalidMsg = getMsg(ORGANIZER_KEY, learnInvalid);
MessageGeneral failureMsg = getMsg(ORGANIZER_KEY, failureInvalid);
assertThrows(InvalidMessageIdException.class, () -> messageHandler.handleMessage(laoRepository, messageSender, CONSENSUS_CHANNEL, electAcceptInvalidMsg));
assertThrows(InvalidMessageIdException.class, () -> messageHandler.handleMessage(laoRepository, messageSender, CONSENSUS_CHANNEL, learnInvalidMsg));
assertThrows(InvalidMessageIdException.class, () -> messageHandler.handleMessage(laoRepository, messageSender, CONSENSUS_CHANNEL, failureMsg));
}
Aggregations