Search in sources :

Example 1 with ConsensusElectAccept

use of com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept in project popstellar by dedis.

the class ConsensusHandlerTest method handleConsensusElectAcceptTest.

// handle an electAccept 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 handleConsensusElectAcceptTest() throws DataHandlingException {
    ConsensusElectAccept electAccept = new ConsensusElectAccept(INSTANCE_ID, messageId, true);
    MessageGeneral electAcceptMsg = getMsg(NODE_3_KEY, electAccept);
    messageHandler.handleMessage(laoRepository, messageSender, CONSENSUS_CHANNEL, electAcceptMsg);
    Optional<ElectInstance> electInstanceOpt = lao.getElectInstance(electMsg.getMessageId());
    assertTrue(electInstanceOpt.isPresent());
    ElectInstance electInstance = electInstanceOpt.get();
    Map<PublicKey, MessageID> acceptorsToMessageId = electInstance.getAcceptorsToMessageId();
    assertEquals(1, acceptorsToMessageId.size());
    assertEquals(electAcceptMsg.getMessageId(), acceptorsToMessageId.get(NODE_3));
    assertEquals(3, lao.getNodes().size());
    ConsensusNode organizer = lao.getNode(ORGANIZER);
    ConsensusNode node2 = lao.getNode(NODE_2);
    ConsensusNode node3 = lao.getNode(NODE_3);
    assertNotNull(organizer);
    assertNotNull(node2);
    assertNotNull(node3);
    Set<MessageID> organizerAcceptedMsg = organizer.getAcceptedMessageIds();
    Set<MessageID> node2AcceptedMsg = node2.getAcceptedMessageIds();
    Set<MessageID> node3AcceptedMsg = node3.getAcceptedMessageIds();
    assertTrue(organizerAcceptedMsg.isEmpty());
    assertTrue(node2AcceptedMsg.isEmpty());
    assertEquals(Sets.newSet(electMsg.getMessageId()), node3AcceptedMsg);
}
Also used : ConsensusElectAccept(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept) ElectInstance(com.github.dedis.popstellar.model.objects.ElectInstance) MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) PublicKey(com.github.dedis.popstellar.model.objects.security.PublicKey) ConsensusNode(com.github.dedis.popstellar.model.objects.ConsensusNode) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID)

Example 2 with ConsensusElectAccept

use of com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept in project popstellar by dedis.

the class ElectionStartFragmentTest method acceptButtonSendElectAcceptMessageTest.

@Test
public void acceptButtonSendElectAcceptMessageTest() throws DataHandlingException {
    setupViewModel(PAST_TIME);
    // Nodes 3 try to start
    MessageGeneral elect3Msg = createMsg(node3KeyPair, elect);
    messageHandler.handleMessage(laoRepository, messageSender, consensusChannel, elect3Msg);
    // We try to accept node3
    nodesGrid().atPosition(node3Pos).perform(ViewActions.click());
    ArgumentCaptor<ConsensusElectAccept> captor = ArgumentCaptor.forClass(ConsensusElectAccept.class);
    Mockito.verify(messageSender).publish(eq(mainKeyPair), eq(consensusChannel), captor.capture());
    ConsensusElectAccept electAccept = captor.getValue();
    ConsensusElectAccept expectedElectAccept = new ConsensusElectAccept(INSTANCE_ID, elect3Msg.getMessageId(), true);
    assertEquals(expectedElectAccept, electAccept);
}
Also used : ConsensusElectAccept(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept) MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) HiltAndroidTest(dagger.hilt.android.testing.HiltAndroidTest) Test(org.junit.Test)

Example 3 with ConsensusElectAccept

use of com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept in project popstellar by dedis.

the class LaoDetailViewModel method sendConsensusElectAccept.

/**
 * Sends a ConsensusElectAccept message.
 *
 * <p>Publish a GeneralMessage containing ConsensusElectAccept data.
 *
 * @param electInstance the corresponding ElectInstance
 * @param accept true if accepted, false if rejected
 */
public void sendConsensusElectAccept(ElectInstance electInstance, boolean accept) {
    MessageID messageId = electInstance.getMessageId();
    Log.d(TAG, "sending a new elect_accept for consensus with messageId : " + messageId + " with value " + accept);
    Lao lao = getCurrentLaoValue();
    if (lao == null) {
        Log.d(TAG, LAO_FAILURE_MESSAGE);
        return;
    }
    ConsensusElectAccept consensusElectAccept = new ConsensusElectAccept(electInstance.getInstanceId(), messageId, accept);
    Log.d(TAG, PUBLISH_MESSAGE);
    Disposable disposable = networkManager.getMessageSender().publish(keyManager.getMainKeyPair(), electInstance.getChannel(), consensusElectAccept).subscribe(() -> Log.d(TAG, "sent an elect_accept successfully"), error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_consensus_accept));
    disposables.add(disposable);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) ConsensusElectAccept(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept) StateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao) Lao(com.github.dedis.popstellar.model.objects.Lao) UpdateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID)

Example 4 with ConsensusElectAccept

use of com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept 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);
}
Also used : ConsensusElectAccept(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept) MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) ConsensusLearn(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusLearn) DataInteraction(androidx.test.espresso.DataInteraction) HiltAndroidTest(dagger.hilt.android.testing.HiltAndroidTest) Test(org.junit.Test)

Example 5 with ConsensusElectAccept

use of com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept in project popstellar by dedis.

the class ElectInstanceTest method acceptorsResponsesTest.

@Test
public void acceptorsResponsesTest() {
    MessageID messageId1 = generateMessageID();
    MessageID messageId2 = generateMessageID();
    String instanceId = electInstance.getInstanceId();
    ConsensusElectAccept electAccept = new ConsensusElectAccept(instanceId, electMessageId, true);
    ConsensusElectAccept electReject = new ConsensusElectAccept(instanceId, electMessageId, false);
    electInstance.addElectAccept(node2, messageId1, electAccept);
    electInstance.addElectAccept(node2, messageId2, electReject);
    Map<PublicKey, MessageID> messageIds = electInstance.getAcceptorsToMessageId();
    assertEquals(1, messageIds.size());
    assertEquals(messageId1, messageIds.get(node2));
}
Also used : ConsensusElectAccept(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept) Base64DataUtils.generatePublicKey(com.github.dedis.popstellar.testutils.Base64DataUtils.generatePublicKey) PublicKey(com.github.dedis.popstellar.model.objects.security.PublicKey) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID) Base64DataUtils.generateMessageID(com.github.dedis.popstellar.testutils.Base64DataUtils.generateMessageID) Test(org.junit.Test)

Aggregations

ConsensusElectAccept (com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept)6 MessageGeneral (com.github.dedis.popstellar.model.network.method.message.MessageGeneral)4 Test (org.junit.Test)4 MessageID (com.github.dedis.popstellar.model.objects.security.MessageID)3 ConsensusLearn (com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusLearn)2 PublicKey (com.github.dedis.popstellar.model.objects.security.PublicKey)2 HiltAndroidTest (dagger.hilt.android.testing.HiltAndroidTest)2 DataInteraction (androidx.test.espresso.DataInteraction)1 ConsensusFailure (com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusFailure)1 StateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao)1 UpdateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao)1 ConsensusNode (com.github.dedis.popstellar.model.objects.ConsensusNode)1 ElectInstance (com.github.dedis.popstellar.model.objects.ElectInstance)1 Lao (com.github.dedis.popstellar.model.objects.Lao)1 Base64DataUtils.generateMessageID (com.github.dedis.popstellar.testutils.Base64DataUtils.generateMessageID)1 Base64DataUtils.generatePublicKey (com.github.dedis.popstellar.testutils.Base64DataUtils.generatePublicKey)1 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)1 Disposable (io.reactivex.disposables.Disposable)1